How can I skip CMake compiler identification? - c++

I'm running some tests on my software environment. This does hundreds of calls to CMake to configure many projects, always using the same compiler.
For every call to CMake, it checks the compiler:
-- Selecting Windows SDK version to target Windows 10.0.16299.
-- The C compiler identification is MSVC 19.0.24215.1
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
This takes a while and is useless to be done many time as it will always end with the same result on the machine running those tests.
Is there no way to "cache" compiler check result and have it be done once only?

fdan recommended (in a comment) to add a top level CMake projects adding all sub-projects using add_subdirectory. I did not try that but it looks like something that would wok.
In the mean time, I found an alternative is to:
Create an empty CMakeLists.txt file
Run CMake on it, it checks the compiler. This produces some files including a CMakeCache.txt and a CMakeFiles folder.
For every next project you will run CMake on
Copy the output of the first run you did with the empty project (including CMakeCache.txt and a CMakeFiles folder)
Modify CMakeCache.txt content to reference the new project folder instead of the old one (else Cmake will report CMake Error: The current CMakeCache.txt directory ... is different than the directory ... where CMakeCache.txt was created).
Then compiler check will not be processed when you'll configure the next project

Related

CMake: Avoiding inclusion of Windows SDK from CMakeLists.txt. Using MinGW instead msvc

I have a project that compiles right when I configure it from the command line:
cmake .. -DCMAKE_GENERATOR="MinGW Makefiles"
generator is set to MinGW Makefiles
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Qt/Tools/mingw810_64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Qt/Tools/mingw810_64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/jose/Documents/ApD_PRG/test_v2/Build
But surprisingly it doesn't when I asjust it at the beginning of the CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
set (CMAKE_GENERATOR "MinGW Makefiles" CACHE INTERNAL "" FORCE)
message("generator is set to ${CMAKE_GENERATOR}")
set(CMAKE_PROJECT_NAME "testProject")
...
$ cmake ..
-- Building for: Visual Studio 14 2015
generator is set to MinGW Makefiles
-- Selecting Windows SDK version to target Windows 10.0.18363. <--------- HERE!!!
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Qt/Tools/mingw810_64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Qt/Tools/mingw810_64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/jose/Documents/ApD_PRG/test_v2/Build
It automatic gets the Windows SDK, and the project doesn't compile any more.
Please, somebody so kind to help me in the avoid of the Windows SDK inclusion from CMakeLists.txt?
Thanks in advance
pd: I need this way, because I want that eclipse automatic select the right compiler on import
It doesn't work because you simply cannot set the generator from within the CMakeLists.txt file.
From the documentation (emphasis mine)
The value of this variable should never be modified by project code. A generator may be selected via the cmake(1) -G option, interactively in cmake-gui(1), or via the CMAKE_GENERATOR environment variable.
Since I'm not familiar with Eclipse I cannot guarantee that it works, but you can try to set the CMAKE_GENERATOR env-variable to MinGW Makefiles when using CMake 3.15 or later.
However, there is a good chance that
the CMake plugin you're using needs to be aware of the generator being used in order to be able to parse the build output, and as such manually adds -G <generator> for the generator configured in the plugin to the CMake invocation, thus overriding the value set in the env-variable, or
the Eclipse plugin only knows how to handle the output of the default generator, but also doesn't enforce it with -G <generator>, in which case you setting a different generator might cause it to fail to parse the build output for errors / warnings.

Unexpected behavior by VS 2017 when compiling a CMake project that works on Linux

I have a CMake project that works fine on Linux with g++.
On Windows (10, Creators Update) CMake runs fine and generates relevant files.
So I opened TestProject.sln solution file and for a test run, I ran 'Local Windows Debugger' and got this error.
Error LNK1104 cannot open file 'jsoncpp.lib'
This is how I've setup this project.
.
|-root
| |- src
| |- lib
| |- bin
| |- app
| |- include
| |- extras
| |- jsoncpp
|-build
I'm not really sure what could be wrong here.
I have jsoncpp added as a submodule.
I did
git submodule update --init --recursive
and there is a jsoncpp.lib file in
root\lib\Debug
This is my CMakeLists.txt
cmake_minimum_required (VERSION 3.13)
project (TestProject)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/root/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/root/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/root/bin)
set(SOURCE_DIR ${PROJECT_SOURCE_DIR}/root/src)
set(INCLUDE_DIR ${PROJECT_SOURCE_DIR}/root/include)
set(EXTRAS_DIR ${PROJECT_SOURCE_DIR}/root/extras)
set(PROJECT_MAIN_DIR ${PROJECT_SOURCE_DIR}/root/app)
set(SOURCES
${INCLUDE_DIR}/Combinations.hpp
${INCLUDE_DIR}/Lib.hpp
${SOURCE_DIR}/Lib.cpp
)
add_executable(TestProject ${PROJECT_MAIN_DIR}/Main.cpp ${SOURCES})
add_subdirectory(${EXTRAS_DIR}/jsoncpp jsoncpp)
target_link_libraries(TestProject jsoncpp)
set_target_properties(TestProject PROPERTIES
CXX_STANDARD_REQUIRED ON
CXX_STANDARD 17
CXX_EXTENSIONS OFF
)
This is CMake's output
Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.17134.
The C compiler identification is MSVC 19.16.27026.1
The CXX compiler identification is MSVC 19.16.27026.1
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
JsonCpp Version: 1.8.4
Looking for C++ include clocale
Looking for C++ include clocale - found
Looking for localeconv
Looking for localeconv - found
Looking for C++ include sys/types.h
Looking for C++ include sys/types.h - found
Looking for C++ include stdint.h
Looking for C++ include stdint.h - found
Looking for C++ include stddef.h
Looking for C++ include stddef.h - found
Check size of lconv
Check size of lconv - done
Performing Test HAVE_DECIMAL_POINT
Performing Test HAVE_DECIMAL_POINT - Success
Found PythonInterp: C:/Users/USERNAME/emacs-26.1-x86_64/bin/python2.exe (found suitable version "2.7.14", minimum required is "2.6")
Configuring done
Generating done
I'm not very familiar with Visual Studio but looking at the error, it says 'cannot open' and not 'couldn't find' so my first thought was maybe it's a permission issue.
So I booted up VS with Admin Privileges but the error continued.
I thought maybe there's some compiler issue so I used nmake.exe as a compiler (after generating nmake makefiles) but no luck there either.
I'm not sure if it's a linker issue since CMake was able to find and link jsoncpp library so I doubt CMake made a mistake building the Makefile.
I'm not sure how I should go about debugging the issue.

Setting Up Google Mock 1.6

I'm trying to follow along with Modern C++ Programming with Test-Driven Development and to do so the book instructs readers to install
Google Mock 1.6. Trying to do I downloaded the source from here. Then according to the book I do:
mkdir build
cd build
cmake ..
make
myComputer:build me$ cmake ..
-- The CXX compiler identification is AppleClang 8.0.0.8000042
-- The C compiler identification is AppleClang 8.0.0.8000042
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at CMakeLists.txt:56 (add_subdirectory):
add_subdirectory given source "../gtest" which is not an existing
directory.
CMake Error at CMakeLists.txt:61 (config_compiler_and_linker):
Unknown CMake command "config_compiler_and_linker".
-- Configuring incomplete, errors occurred!
See also "/Users/me/Downloads/googlemock-release-1.6.0 3/build/CMakeFiles/CMakeOutput.log".
The ../gtest directory is indeed missing. As these are the directories:
CHANGES COPYING build include scripts
CMakeLists.txt Makefile.am build-aux make src
CONTRIBUTORS README configure.ac msvc test
Adding to the confusion are these instructions:
You will also need to build Google Test, which is nested within Google Mock.
cd $GMOCK_HOME/gtest
mkdir mybuild
cd mybuild
cmake ..
make
I looked at the README and I don't seem anything that helps resolve this issue. Any help/guidance would be super!
As you can see here, Google Mock has been absorbed into the GoogleTest project.
There are various ways to install GoogleTest, described in The GoogleTest Readme. Since you seem to be using CMake, I suggest you follow the steps under
Incorporating Into An Existing CMake Project
You can also put everything that should go into CMakeLists.txt into CMakeLists.GTest and then only put include(CmakeLists.GTest) in CMakeLists.txt.
If you want to determine a fixed version of GoogleTest that should be incorporated, you can use the GIT_TAG eg release-1.8.0ยด instead ofmaster` in your CMakeLists.txt.in.
After incorporating GoogleTest in your project, you can add gtests for class Foo by creating eg FooTest.cpp that includes gtest/gtest.h and Foo.h. Therefore, you also have to put add_executable(FooTarget FooTest.cpp) and target_link_libraries(FooTarget gtest) in the corresponding CMakeLists.txt.
You can also find a short description of this, and how to integrate GoogleTests into ctest on these slides).
You need to have gtest inside gmock dir.
I initialy had same error as you, than took gtest version 1.6 from https://github.com/google/googletest and placed it in gmock root dir and succesfully built it.

Point Cloud Library (PCL) can't find PCLConfig.cmake or pcl-config.cmake [Ubuntu 16.04]

I've been trying to get the Point Cloud Library properly installed on my system. I would like to be able to get the basic tutorial working so that I know everything is correct and I can move on.
This has so far been a case of dealing with problem after problem of which this is the latest.
When I run cmake it errors and outputs:
-- The C compiler identification is GNU 4.9.3
-- The CXX compiler identification is GNU 4.9.3
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:3 (find_package):
By not providing "FindPCL.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "PCL", but
CMake did not find one.
Could not find a package configuration file provided by "PCL" (requested
version 1.3) with any of the following names:
PCLConfig.cmake
pcl-config.cmake
Add the installation prefix of "PCL" to CMAKE_PREFIX_PATH or set "PCL_DIR"
to a directory containing one of the above files. If "PCL" provides a
separate development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
See also "/home/matt/hdd_home/pcl/tutorials/build/CMakeFiles/CMakeOutput.log".
I've installed PCL v1.8 from the Ubuntu repository but I've also installed python-vtk because it provides the package libvtkRenderingPythonTkWidgets which removes an error I was facing previously (see here). Installation of python-vtk I believe removes some of the packages bundled in libpcl-dev (PCL v1.8); I don't know whether this is relevant to the issue.
I'm not 100% sure that PCLConfig.cmake or pcl-config.cmake are even on my system. Maybe there has been an issue with the installation?
Any help is much appreciated!

Building cpp-netlib with CMake

I've downloaded the cpp-netlib source, extracted it to a folder and for some reason I'm completely lost. I read the documentation carefully, it states I have to download CMake as well, which I did. Then I set the source directory and build directories, and upon clicking the "Generate" button I got this output:
The CXX compiler identification is MSVC 19.0.23506.0
Check for working C compiler using: Visual Studio 14 2015
Check for working C compiler using: Visual Studio 14 2015 -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working CXX compiler using: Visual Studio 14 2015
Check for working CXX compiler using: Visual Studio 14 2015 -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.5/Modules/FindBoost.cmake:1657 (message):
Unable to find the requested Boost libraries.
Unable to find the Boost header files. Please set BOOST_ROOT to the root
directory containing Boost or BOOST_INCLUDEDIR to the directory containing
Boost's headers.
Call Stack (most recent call first):
CMakeLists.txt:49 (find_package)
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES OPENSSL_INCLUDE_DIR)
Looking for pthread.h
Looking for pthread.h - not found
Found Threads: TRUE
CMake Error at CMakeLists.txt:131 (export):
export given target "cppnetlib-client-connections" which is not built by
this project.
Configuring incomplete, errors occurred!
See also "C:/Users/Nick/Documents/cpp-netlib/cpp-netlib-build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/Nick/Documents/cpp-netlib/cpp-netlib-build/CMakeFiles/CMakeError.log"
It couldn't find the Boost libraries, and that's where I'm stuck. I installed boost, but I have no idea where to set "BOOST_ROOT". I did some research on that, tried to use the command line with the -DBOOST_ROOT option like so:
c:\Program Files>cmake -DBOOST_ROOT=/boost/boost_1_55_0
But it gives me the following error:
CMake Error: The source directory "C:/Program Files" does not appear to contain
CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
I'm really unsure as to what to do now and I feel this isn't the end of my problems... Is there anything obvious I'm missing?
You need to either run cmake from the source tree (which would contain CMakeLists.txt), or, more typically, run it from a build folder and tell it where the source tree is.
A common case would be creating a build folder next to the source tree and running cmake ../sourcedir.
You seem to have initially been using a gui; surely that provides a means to set the BOOST_ROOT variable?
Alternatively, if you just put boost in the VC++ include/lib paths (either in the vc dirs, or by setting %INCLUDE%/%LIB%), you probably would not need BOOST_ROOT. Same for OpenSSL.