CMake Cookbook
上QQ阅读APP看书,第一时间看更新

There is more

Sometimes, packages are not installed in standard locations and CMake might fail to locate them correctly. It is possible to tell CMake to look into certain specific locations to find certain software using the CLI switch -D to pass the appropriate option. In the case of the Python interpreter, you may configure with the following:

$ cmake -D PYTHON_EXECUTABLE=/custom/location/python ..

This will correctly identify the Python executable in the non-standard /custom/location/python installation directory.

Every package is different and the Find<package>.cmake modules try to take that into account and offer a unified interface for detection. When a package that is installed on the system cannot be found by CMake, we recommend you read the documentation for the corresponding detection module to understand how to instruct CMake correctly. You can browse the documentation directly in the terminal, in this case using  cmake --help-module FindPythonInterp.

Independently of detecting packages, we would like to mention a handy helper module for printing variables. In this recipe, we have used the following:

message(STATUS "RESULT_VARIABLE is: ${_status}")
message(STATUS "OUTPUT_VARIABLE is: ${_hello_world}")

A handy alternative for debugging is to use the following:

include(CMakePrintHelpers)
cmake_print_variables(_status _hello_world)

This produces the following output:

-- _status="0" ; _hello_world="Hello, world!"

For more documentation on convenience macros for printing properties and variables, see https://cmake.org/cmake/help/v3.5/module/CMakePrintHelpers.html.