cmake_minimum_required(VERSION 3.14) project(DependencyExample LANGUAGES CXX) include(FetchContent) # Define the external library to download FetchContent_Declare( fmt_lib GIT_REPOSITORY https://github.com GIT_TAG 10.0.0 # Use a specific release version ) # Make the population of content available FetchContent_MakeAvailable(fmt_lib) add_executable(main_app main.cpp) # Link against the downloaded library target target_link_libraries(main_app PRIVATE fmt::fmt) Use code with caution. 4. Professional Out-of-Source Build Workflow
If you have ever struggled with writing cross-platform CMakeLists.txt files, battled cryptic error messages, or wished for a structured set of solutions to real-world build problems, you have likely come across the . The trifecta of CMake Cookbook PDF , GitHub resources, and work -oriented examples has become the gold standard for intermediate and advanced CMake users.
If you’ve downloaded a PDF but the examples aren't compiling, follow this modern workflow to get them running: Step 1: Clone the Repo
While the CMake Cookbook is excellent, it is worth noting that the open-source community has produced high-quality, free alternatives that are often found on GitHub. cmake cookbook pdf github work
3.5 External dependencies
Parts of the book are CC-BY-NC-ND licensed? – the full book is proprietary. However, the example code on GitHub is open-source (usually MIT or BSD). You can study the code without the PDF, but you’ll miss the explanatory text.
Example: FetchContent for GoogleTest
cmake_minimum_required(VERSION 3.15) project(MultiModuleProject LANGUAGES CXX) # Walk down the directory tree add_subdirectory(libs/logger) add_subdirectory(src) Use code with caution.
The CMake Cookbook is designed to be a practical guide to mastering CMake. Here are some tips on using the cookbook:
This strategy is crucial for open-source software on GitHub, ensuring code successfully builds regardless of whether a developer clones it on Linux, macOS, or Windows. 3. Step-by-Step: Making CMake Work in GitHub Actions cmake_minimum_required(VERSION 3
Elias slammed the enter key to run the make command. The progress bar filled up green.
These are your executables or libraries (created via add_executable() or add_library() ).
# 1. Create a dedicated build directory mkdir build cd build # 2. Configure the project and generate build systems cmake .. # 3. Compile the software using all CPU cores cmake --build . --parallel $(nproc) Use code with caution. The trifecta of CMake Cookbook PDF , GitHub