Find package Eigen3 for CMake

Since Eigen3 is completely header only, all you ever need is the path to the include directory. And this one, you are already defining manually anyway. So there is no real need for a FindEigen3.cmake or FIND_PACKAGE call. Simply use INCLUDE_DIRECTORIES ( “$ENV{EIGEN3_INCLUDE_DIR}” ) or SET( EIGEN3_INCLUDE_DIR “$ENV{EIGEN3_INCLUDE_DIR}” ) IF( NOT EIGEN3_INCLUDE_DIR ) MESSAGE( FATAL_ERROR … Read more

How to test if CMake found a library with find_library

You can simply test the variable as such, e.g.: find_library(LUA_LIB lua) if(NOT LUA_LIB) message(FATAL_ERROR “lua library not found”) endif() Example output: CMake Error at CMakeLists.txt:99 (message): lua library not found — Configuring incomplete, errors occurred! Note that we use if(NOT LUA_LIB) and not if(NOT ${LUA_LIB}) because of the different semantics. With ${}, the variable LUA_LIB … Read more

CMake: In which order are files parsed (cache, toolchain, etc.)?

There’s no official documentation about this particular inner workings of CMake, so please find below a summary of what I’ve learned about CMake so far … What files are parsed depends on the The host and target operating system The target compiler Your host computer’s environment (variables, registry, installed software) Your project’s CMake script files, … Read more

How do I use CMake ExternalProject_Add or alternatives in a cross-platform way?

Problems -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} This is enough for single-configuration projects. But for Xcode and Visual Studio, you need to set CMAKE_CONFIGURATION_TYPES plus call build . –config at the build stage. See my answer. COMMAND cd <BINARY_DIR> && make install This will work only for Makefile generators of course. To be cross-platform you can use: –build . –target … Read more

What is cmake_install.cmake

You generally don’t use cmake_install.cmake directly. From the v3.12 page it states: The install() command generates a file, cmake_install.cmake, inside the build directory, which is used internally by the generated install target and by CPack. With your current CMakeLists.txt, the generated file doesn’t do much. To create a useful install you would need to add … Read more

CMake: Is there a difference between set_property(TARGET …) and set_target_properties?

Consider set_target_properties() as a specialized form of set_property(). Advantages of … set_target_properties(…) is a convenience function because it allows to set multiple properties of multiple targets. For example: add_executable(a …) add_executable(b …) set_target_properties( a b PROPERTIES LINKER_LANGUAGE CXX FOLDER “Executable” ) set_property(TARGET …) can APPEND to a list- or APPEND_STRING to a string-based property of … Read more

What does –target option mean in CMake?

If I have add_executable(hello hello.cpp) add_executable(goodbye goodbye.cpp) then CMake creates ‘build targets’ for each executable. It also creates other build targets, such as the ‘all’ build target, which builds everything. By default, if the target is not specified, the ‘all’ target is executed, meaning both hello and goodbye are built. You can specify the target … Read more