Custom module path
- The current project has custom CMake modules under cmake_modules/
Append the path in the top-level CMakeLists?.txt:
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake_modules")
Out-of-Tree Sub-Projects
- myLib is out-of-tree library source with its own CMakeLists?.txt
- we want to build and link against the out-of-tree library
Instruct CMake to build the external library beneath the current binary dir explicitly:
add_subdirectory (${OUT_OF_TREE_DIR}/myLib ${CMAKE_CURRENT_BINARY_DIR}/myLib)
MSVC static runtime definitions
- MSVC projects require linking against specific versions of runtime libraries
Override CMAKE_C_FLAGS_*:
set(CMAKE_C_FLAGS_DEBUG "/MTd")
set(CMAKE_C_FLAGS_RELEASE "/MT")
Arch-specific Files
- Architecture-specific C implementation files in src/$ARCH/*.c
Define TARGET_BUILD_PLATFORM=[linux|win32|...]. Include glob:
file(GLOB PLATFORM_CSRCS ${TARGET_BUILD_PLATFORM}/*.c)
Group files in MSVC projects
source_group(Groupname FILES ${PLATFORM_CSRCS})
Custom Cross-compiler Toolchain
- Seems to require overriding tool invocation commands within the Toolchain file
- For compilers that don't include their system include files automatically, a platform .cmake file is useful
- Seems this has to live in the CMake install tree (is there a better way?)