Title Page Copyright and Credits CMake Cookbook Packt Upsell Why subscribe? PacktPub.com Contributors About the authors About the reviewers Packt is searching for authors like you Preface Who this book is for What this book covers To get the most out of this book Download the example code files Download the color images Conventions used Additional reading resources Get in touch Reviews Setting up Your System Obtaining the code Docker image Installing prerequisite software Getting CMake Compilers Build-automation tools Python Additional software BLAS and LAPACK Message passing interface (MPI) The Eigen linear algebra template library The Boost libraries Cross-compilers ZeroMQ, pkg-config, UUID, and Doxygen Conda build and deployment tools Testing the recipes Reporting problems and suggesting improvements From a Simple Executable to Libraries Introduction Compiling a single source file into an executable Getting ready How to do it How it works There is more Switching generators Getting ready How to do it How it works See also Building and linking static and shared libraries Getting ready How to do it How it works There is more Controlling compilation with conditionals How to do it How it works Presenting options to the user How to do it How it works There is more Specifying the compiler How to do it How it works There is more Switching the build type How to do it How it works There is more Controlling compiler flags Getting ready How to do it How it works There is more Setting the standard for the language Getting ready How to do it How it works There is more Using control flow constructs Getting ready How to do it How it works There is more Detecting the Environment Introduction Discovering the operating system How to do it How it works Dealing with platform-dependent source code Getting ready How to do it How it works Dealing with compiler-dependent source code Getting ready How to do it How it works Discovering the host processor architecture Getting ready How to do it How it works There is more Discovering the host processor instruction set Getting ready How to do it How it works There is more Enabling vectorization for the Eigen library Getting ready How to do it How it works There is more Detecting External Libraries and Programs Introduction Detecting the Python interpreter How to do it How it works There is more Detecting the Python library Getting ready How to do it How it works There is more See also Detecting Python modules and packages Getting ready How to do it How it works Detecting the BLAS and LAPACK math libraries Getting ready How to do it How it works There is more Detecting the OpenMP parallel environment Getting ready How to do it How it works Detecting the MPI parallel environment Getting ready How to do it How it works Detecting the Eigen library Getting ready How to do it How it works There is more Detecting the Boost libraries Getting ready How to do it How it works Detecting external libraries: I. Using pkg-config Getting ready How to do it How it works Detecting external libraries: II. Writing a find-module How to do it How it works There is more Creating and Running Tests Introduction Creating a simple unit test Getting ready How to do it How it works There is more Defining a unit test using the Catch2 library Getting ready How to do it How it works There is more See also Defining a unit test and linking against Google Test Getting ready How to do it How it works There is more See also Defining a unit test and linking against Boost test Getting ready How to do it How it works There is more Using dynamic analysis to detect memory defects Getting ready How to do it How it works There is more See also Testing expected failures Getting ready How to do it How it works There is more Using timeouts for long tests Getting ready How to do it How it works Running tests in parallel Getting ready How to do it How it works There is more Running a subset of tests Getting ready How to do it How it works There is more Using test fixtures Getting ready How to do it How it works There is more Configure-time and Build-time Operations Introduction Using platform-independent file operations Getting ready How to do it How it works There is more Running a custom command at configure time How to do it How it works There is more Running a custom command at build time: I. Using add_custom_command Getting ready How to do it How it works Running a custom command at build time: II. Using add_custom_target Getting ready How to do it How it works Running custom commands for specific targets at build time Getting ready How to do it How it works Probing compilation and linking Getting ready How to do it How it works There is more Probing compiler flags Getting ready How to do it How it works See also Probing execution Getting ready How to do it How it works Fine-tuning configuration and compilation with generator expressions Getting ready How to do it How it works There is more See also Generating Source Code Introduction Generating sources at configure time Getting ready How to do it How it works There is more Generating source code at configure time using Python Getting ready How to do it How it works There is more Generating source code at build time using Python Getting ready How to do it How it works There is more Recording the project version information for reproducibility Getting ready How to do it How it works There is more Recording the project version from a file Getting ready How to do it How it works Recording the Git hash at configure time Getting ready How to do it How it works Recording the Git hash at build time Getting ready How to do it How it works There is more Structuring Projects Introduction Code reuse with functions and macros Getting ready How to do it How it works There is more Splitting CMake sources into modules Getting ready How to do it How it works There is more Writing a function to test and set compiler flags Getting ready How to do it How it works There is more Defining a function or macro with named arguments Getting ready How to do it How it works There is more Redefining functions and macros Getting ready How to do it How it works Deprecating functions, macros, and variables Getting ready How to do it How it works Limiting scope with add_subdirectory Getting ready How to do it How it works There is more See also Avoiding global variables using target_sources Getting ready How to do it How it works There is more Organizing Fortran projects Getting ready How to do it How it works There is more The Superbuild Pattern Introduction Using the superbuild pattern Getting ready How to do it How it works There is more Managing dependencies with a superbuild: I. The Boost libraries How to do it How it works Managing dependencies with a superbuild: II. The FFTW library Getting ready How to do it How it works Managing dependencies with a superbuild: III. The Google Test framework Getting ready How to do it How it works See also Managing your project as a superbuild Getting ready How to do it How it works Mixed-language Projects Introduction Building Fortran projects that use C/C++ libraries Getting ready How to do it How it works There is more Building C/C++ projects that use Fortran libraries Getting ready How to do it How it works Building C++ and Python projects using Cython Getting ready How to do it How it works There is more Building C++ and Python projects using Boost.Python Getting ready How to do it How it works There is more Building C++ and Python projects using pybind11 Getting ready How to do it How it works There is more See also Mixing C, C++, Fortran, and Python using Python CFFI Getting ready How to do it How it works There is more See also Writing an Installer Introduction Installing your project Getting ready How to do it How it works Installing to standard locations Target properties and RPATH handling Installation directives There is more Generating export headers Getting ready How to do it How it works There is more Exporting your targets Getting ready How to do it How it works There is more Installing a superbuild Getting ready How to do it How it works Packaging Projects Introduction Generating source and binary packages Getting ready How to do it How it works Source archives Binary archives Platform-native binary installers There is more Distributing a C++/Python project built with CMake/pybind11 via PyPI Getting ready How to do it How it works There is more Distributing a C/Fortran/Python project build with CMake/CFFI via PyPI Getting ready How to do it How it works There is more Distributing a simple project as Conda package Getting ready How to do it How it works There is more Distributing a project with dependencies as Conda package Getting ready How to do it How it works There is more Building Documentation Introduction Building documentation using Doxygen Getting ready How to do it How it works Building documentation using Sphinx Getting ready How to do it How it works Combining Doxygen and Sphinx Getting ready How to do it How it works Alternative Generators and Cross-compilation Introduction Building a CMake project using Visual Studio 2017 Getting ready How to do it How it works See also Cross-compiling a hello world example Getting ready How to do it How it works See also Cross-compiling a Windows binary with OpenMP parallelization Getting ready How to do it How it works There is more Testing Dashboards Introduction Setting up a CDash dashboard Deploying tests to the CDash dashboard Getting ready How to do it How it works There is more See also Reporting test coverage to the CDash dashboard Getting ready How to do it How it works See also Using the AddressSanitizer and reporting memory defects to CDash Getting ready How to do it How it works There is more See also Using the ThreadSanitizer and reporting data races to CDash Getting ready How to do it How it works There is more See also Porting a Project to CMake Where to start Reproducing the porting example Creating a top-level CMakeLists.txt How to allow both conventional configuration and configuration with CMake at the same time Capturing a record of what the traditional build does Debugging the migration Implementing options Start with the executable and very few targets, later localize scope Generating files and writing platform checks How to structure files Configuring preprocessor definitions based on the system environment Configuring files with paths and compiler flags Executing shell scripts at configure time Detecting required dependencies and linking Reproducing compiler flags Defining compiler flags Scope of compiler flags Porting tests Getting started Implementing a multi-step test Recommendation for tests Porting install targets Further steps Summary and common pitfalls when converting projects to CMake Summary of code changes Common pitfalls Other Books You May Enjoy Leave a review - let other readers know what you think