Mastering Cmake Pdf -

# Different compile definitions per config target_compile_definitions(my_app PRIVATE $<$<CONFIG:Debug>:DEBUG_BUILD> $<$<CONFIG:Release>:NDEBUG> ) target_link_libraries(my_app PRIVATE $<$<PLATFORM_ID:Windows>:ws2_32> $<$<PLATFORM_ID:Linux>:dl> ) 2. Custom Commands and Targets Generate code or run tools:

include_directories(include) link_directories(/custom/lib) add_executable(my_app main.cpp) mastering cmake pdf

add_custom_command( OUTPUT $CMAKE_CURRENT_BINARY_DIR/version.h COMMAND $CMAKE_COMMAND -DVERSION=$PROJECT_VERSION -P write_version.cmake DEPENDS write_version.cmake COMMENT "Generating version.h" ) add_custom_target(generate_version DEPENDS $CMAKE_CURRENT_BINARY_DIR/version.h) add_dependencies(my_app generate_version) toolchain_arm.cmake : ) target_link_libraries(my_app PRIVATE $&lt

"version": 3, "configurePresets": [ "name": "debug", "displayName": "Debug", "generator": "Ninja", "binaryDir": "$sourceDir/build/debug", "cacheVariables": "CMAKE_BUILD_TYPE": "Debug", "BUILD_TESTS": "ON" , "name": "release", "inherits": "debug", "displayName": "Release", "binaryDir": "$sourceDir/build/release", "cacheVariables": "CMAKE_BUILD_TYPE": "Release" ], "buildPresets": [ "name": "debug", "configurePreset": "debug" , "name": "release", "configurePreset": "release" ] "configurePresets": [ "name": "debug"

project/ ├── CMakeLists.txt (top-level) ├── cmake/ │ └── FindMyCustomLib.cmake ├── src/ │ ├── CMakeLists.txt │ └── app.cpp ├── libs/ │ ├── core/ │ │ ├── CMakeLists.txt │ │ └── core.cpp │ └── utils/ │ ├── CMakeLists.txt │ └── utils.h (header-only) └── tests/ ├── CMakeLists.txt └── test_core.cpp cmake_minimum_required(VERSION 3.20) project(MyProject VERSION 1.0.0 LANGUAGES CXX) Options option(BUILD_TESTS "Build unit tests" ON) option(BUILD_SHARED_LIBS "Build shared libs instead of static" OFF) Global settings set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) Add subdirectories add_subdirectory(libs/core) add_subdirectory(libs/utils) add_subdirectory(src)