CMake 学过又忘记的写法

这篇用来记录学过但是不容易记住的写法。

CMake language

add_subdirectory(source_dir [binary_dir] [EXCLUDE_FROM_ALL] [SYSTEM])
                             ^^^^^^^^^
e.g.
add_subdirectory(src bin)

这个操作是可以给单个文件设置不同的编译选项,而不是对 target 设置。控制的粒度就更细了。

if(MSVC AND NOT CLANG_CL)
 set_source_files_properties(CompileCommands.cpp PROPERTIES COMPILE_FLAGS -wd4130) # disables C4130: logical operation on address of string constant
endif()

CMake command line

cmake -S . -B build -G "Ninja Multi-Config"