How to make CMake reconfiguration depend on custom file?
It doesn’t require any kind of workarounds. The standard way is to use CMAKE_CONFIGURE_DEPENDS property: set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS <filename>)
It doesn’t require any kind of workarounds. The standard way is to use CMAKE_CONFIGURE_DEPENDS property: set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS <filename>)
When you setup your build environment, you should put some thought into the following three topics (beside others, but for this discussion/answer I reduced it to the three I feel are relevant here): Dependecies / Coupling Deployment Teams “Strong Coupling” I came to think of the add_subdirectory() command as supporting “strong coupling” and your current … Read more
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
You may consider using configure_file with the COPYONLY option: configure_file(<input> <output> COPYONLY) Unlike file(COPY …) it creates a file-level dependency between input and output, that is: If the input file is modified the build system will re-run CMake to re-configure the file and generate the build system again.
You can modify the CMAKE_CXX_FLAGS_<Build Type> and/or CMAKE_C_FLAGS_<Build Type> variables: set(CMAKE_CXX_FLAGS_RELEASE “${CMAKE_CXX_FLAGS_RELEASE} /MT”) set(CMAKE_CXX_FLAGS_DEBUG “${CMAKE_CXX_FLAGS_DEBUG} /MTd”) If your CMake flags already contain /MD, you can ensure that the above commands are executed after the point at which /MD is inserted (the later addition of /MT overrides the conflicting existing option), or you can set the … Read more
This can be changed via the Run -> Edit Configurations… dialog, just like Idea. The mix of needing to make changes to CMakeLists.txt for so much of the configuration just threw me, and I’ve been hunting for a way to change it there, but this bit at least is consistent with the other IDEs, which … Read more
CMake has a standard module for testing if the compiler supports OpenMP: find_package(OpenMP) if (OPENMP_FOUND) set (CMAKE_C_FLAGS “${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}”) set (CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}”) set (CMAKE_EXE_LINKER_FLAGS “${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}”) endif() Note: This answer is not recommended to be used anymore for including OpenMP in the project for current CMake versions. Refer to the other answers.
In modern CMake, the following works well: if(MSVC) target_compile_options(${TARGET_NAME} PRIVATE /W4 /WX) else() target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror) endif() My colleague suggested an alternative version: target_compile_options(${TARGET_NAME} PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/W4 /WX> $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic -Werror> ) Replace ${TARGET_NAME} with the actual target name. -Werror is optional, it turns all warnings into errors. Or use add_compile_options(…) if … Read more
A portable way of setting environment variables for a custom target is to use CMake’s command-line tool mode command env: env [–unset=NAME]… [NAME=VALUE]… COMMAND [ARG]… Run command in a modified environment. E.g.: add_custom_target(newtarget ${CMAKE_COMMAND} -E env NAME=VALUE somecommand) Also see Command Line Tool Mode.
CMake 3.X CMake 3.X offers a ‘clean’ target. cmake –build C:/foo/build/ –target clean From the CMake docs for 3.0.2: –clean-first = Build target ‘clean’ first, then build. (To clean only, use –target ‘clean’.) CMake 2.X There is no cmake clean in CMake version 2.X I usually build the project in a single folder like “build”. … Read more