[MUC++] Daniel Pfeifer - "Effective CMake"
Why Stack Overflow recommends it
Stack Overflow users link it as the authoritative guide to modern, target-based CMake practices when answering or asking how to configure builds, flags and static analysis tools.
Recommended by 2 people across 2 different months, 2018 to 2019.
What it is
A conference talk from Meeting C++ Munich (MUC++) by Daniel Pfeifer on modern CMake best practices. It gives a quick tour of CMake, CTest and CPack, then covers dependency management, exporting libraries, cross-compiling, running tests in an emulator, and code coverage plus static and dynamic analysis.
What people said
Recommends Daan Timmer · 2019-01 · Stack Overflow · on “set c-compiler and c++-compiler flags for single target without abusing CMAKE_CXX_FLAGS and CMAKE_C_FLAGS”
I've got an (embedded mixed C/C++) project. I need to set, the most important one, -fno-rtti . I can't use target_compile_options( my_target PRIVATE -fno-rtti ) Because this sets -fno-rtti for CXX and C objects. However, watching Daniel Pfeifer - "Effective CMake" [this video] he 'recommends' to not use SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CUSTOM_C_FLAGS}") and SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CUSTOM_CXX_FLAGS}") But how can I achieve different compiler flags for c++ and c? I can't just use -fno-rtti for C, because it emits warnings, warnings that I can't ignore because of -Werror policy. I've tried moving the C files to a library or the C++ files to a library but that generates a diffe
Recommends user2449761 · 2019-06 · Stack Overflow · on “How to use cpplint code style checking with CMake?”
Recommended way to use static analysis tools with CMake was presented in Daniel Pffeifer's "Effective Cmake" ( [this video] ). You can either define it when calling cmake , eg.: cmake "-DCMAKE_CXX_CPPLINT=cpplint" .. or put it into CMakeLists.txt : set(CMAKE_CXX_CPPLINT "cpplint") Recommended option is the first one (we shouldn't define in a project what isn't a project requirement). CMake will call cpplint for each file it compiles. You can pass extra arguments after semicolon (e.g. -DCMAKE_CXX_CPPLINT=cpplint;--linelength=100 ). Downsides of this method: Errors count will not get accumulated (because cpplint is invoked for each file separately). It will not check header files (as opposed to wha
Cites Krupip · 2018-10 · Stack Overflow · on “How am I supposed to pass along the same arguments to multiple targets in CMAKE with out variables?”
I'm refactoring a cmake file to use modern CMAKE practices for an personal project. However since I don't believe the operating system comes as a generalized variable, in order to test the operating system in CMAKE I have to do the following ( based on this answer [LINK] ): if(UNIX AND NOT APPLE) set(LINUX TRUE) endif() #... if(LINUX) set(MY_PROJECT_LINK_ARGUMENTS ...) elseif(WIN32) set(MY_PROJECT_LINK_ARGUMENTS ...) else() message( FATAL_ERROR "Unsupported operating system") endif() add_library(xxx STATIC) #... target_link_libraries(xxx INTERFACE ${MY_PROJECT_LINK_LIBRARIES} ...) add_library(yyy STATIC) #... target_link_libraries(yyy INTERFACE ${MY_PROJECT_LINK_LIBRARIES} ...) add_library(z