Release Date: 18th July 2019
This is part of the change history for the book Professional CMake: A Practical Guide. The 4th Edition has been updated for the CMake 3.15.0 release and also contains some other minor improvements. The following lists the main changes in this edition.
General Presentation:
- Text readability has been improved by using fully black text. Previous editions used a dark grey, which was not as clear.
Setting Up A Project chapter:
- New for CMake 3.15, the
CMAKE_GENERATORenvironment variable can be used to specify a default generator. - New for CMake 3.15, multiple targets can be given for the
cmake --targetcommand line option.
Variables chapter:
- CMake 3.15 expanded the set of supported message types for the
message()command, addingNOTICE,VERBOSE,DEBUGandTRACElogging levels. The minimum log level can also be specified with the--loglevelcommand line option. - Added comments highlighting that
string(LENGTH)counts bytes rather than characters. - Added mention of the
list(PREPEND),list(POP_FRONT)andlist(POP_BACK)subcommands new for CMake 3.15.
Flow Control chapter:
- Clarified wording for how numbers are treated by the
if()command.
Using Subdirectories chapter:
- Added new Project-relative Variables section describing the set of variables defined by the
project()command. - Added paragraph to the Recommended Practices section advising to avoid using
CMAKE_SOURCE_DIRandCMAKE_BINARY_DIRand prefer the project-relative variables instead.
Functions And Macros chapter:
- Fixed incorrect variable name for numbered arguments
ARG#–>ARGV#, adjusted example to highlight that numbering starts from 0 and point out that accessingARGVxwithx>=ARGCis undefined behavior. - Added explanation and example for handling unprocessed arguments with
<prefix>_UNPARSED_ARGUMENTSwhen usingcmake_parse_arguments(). - New for CMake 3.15, when using
cmake_parse_arguments(), the<prefix>_KEYWORDS_MISSING_VALUESvariable can be used to detect single or multi-value keywords that were not given any values. - Highlighted that functions receive a copy of all variables from the calling scope.
- Added advice to the Recommended Practices section to prefer to pass information into functions and macros via arguments rather than relying on variables from the calling scope.
Properties chapter:
- Clarified the difference between
DEFINEDandSETfor theget_property()command.
Generator Expressions chapter:
- Added a brief note that new generator expressions were added in CMake 3.15 for extracting the base name, prefix and suffix of target-related file names.
- Made the wording a bit clearer regarding CMake 3.12 allowing object libraries to be linked directly instead of using
$<TARGET_OBJECTS:...>.
Compiler And Linker Essentials chapter:
- Added a small example showing how to more robustly add language-specific compiler flags to targets.
Custom Tasks chapter:
- CMake 3.15 added a new
JOB_POOLoption to theadd_custom_command()andadd_custom_target()commands. - Added more explicit comments that a target cannot be made to depend on an output of
add_custom_command()from a different directory scope. - New for CMake 3.15, the
execute_process()command now accepts a newCOMMAND_ECHOoption and has an associatedCMAKE_EXECUTE_PROCESS_COMMAND_ECHOvariable. - Fixed typo in example:
add_program()–>add_executable(). - Added extra comments for archiver.cmake example to highlight why having it as a separate file can be useful.
- Added note to the Recommended Practices section for when using
execute_process()may be appropriate.
Working With Files chapter:
- CMake 3.15 added a new
FOLLOW_SYMLINK_CHAINoption to thefile(COPY)andfile(INSTALL)subcommands. - Updated the
file(COPY)example to use more appropriate permissions (world execute rather than world write for thewhoami.shfile).
Toolchains And Cross Compiling chapter:
- Added discussion of
CMAKE_GENERATOR_PLATFORMandCMAKE_GENERATOR_TOOLSETand their associated-Aand-Tcommand line options, with examples for Visual Studio. - Added brief explanation of
CMAKE_GENERATOR_INSTANCEand when it may be useful.
Apple Features chapter:
- New for CMake 3.15, the
CMAKE_FRAMEWORKvariable is now used to initialize theFRAMEWORKtarget property.
Finding Things chapter:
- New for CMake 3.15, the
CMAKE_FIND_PACKAGE_PREFER_CONFIGvariable can be used to change the search preference offind_package()to look for config package files before a find module. - CMake 3.15 introduced policy
CMP0090to make the default behavior ofexport(PACKAGE)not update the package registry. The newCMAKE_EXPORT_PACKAGE_REGISTRYvariable can be used to re-enable it if required. - Added note that
pkg_get_variable()would incorrectly ignoreCMAKE_PREFIX_PATHwith CMake 3.14 and earlier due to a bug (fixed in CMake 3.15.0).
Testing chapter:
- CMake 3.15 allows
CROSSCOMPILING_EMULATORto hold a list rather than just a single value. It can now include arguments too, not just a single script or executable.
Installing chapter:
- CMake 3.15 removed the problematic caching optimization in
find_dependency()that sometimes caused package components to be handled incorrectly. - CMake 3.15 added a new
cmake --installcommand line option to allow an install to be performed without invoking the build tool. It also has more flexibility and is easier to use than running thecmake_install.cmakescript from the build directory.
Project Organization chapter:
- Split up the Miscellaneous Project Features section into three new sections with more specific focus: Cleaning Files, Re-running CMake On File Changes and Injecting Files Into Projects.
- CMake 3.15 added
ADDITIONAL_CLEAN_FILESdirectory and target properties as more general replacements for the existingADDITIONAL_MAKE_CLEAN_FILESdirectory property. - CMake 3.15 added new
CMAKE_PROJECT_INCLUDEandCMAKE_PROJECT_INCLUDE_BEFOREvariables for injecting content after or before anyproject()command. - Added a paragraph to the Recommended Practices section mentioning how
CMAKE_PROJECT_<PROJNAME>_INCLUDEcan be used with continuous integration builds to mitigate problems with unwanted values in the CMake cache for incremental builds.