Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variables with angle brackets in CMake scripts

Tags:

cmake

I noticed that CMake can use variables not only in ${VAR_NAME} syntax, but also in <VAR_NAME> syntax. For example, following code:

IF(NOT CMAKE_CXX_LINK_EXECUTABLE)
  SET(CMAKE_CXX_LINK_EXECUTABLE
    "<CMAKE_CXX_COMPILER>  <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS>  -o <TARGET> <LINK_LIBRARIES>")
ENDIF(NOT CMAKE_CXX_LINK_EXECUTABLE)

was found in CMake modules folder in script named CMakeCXXInformation.cmake.

I didn't find any explanation about syntax using angle brackets in the documentation. Has someone used such syntax who can explain its meaning?

like image 843
Oleksandr Avatar asked Nov 16 '12 10:11

Oleksandr


1 Answers

Regular CMake variables can be dereferenced with usual ${FOO} syntax. These dereferences occur during CMake run.

At some point CMake introduced generator expressions, which have form of $<FOO>. From the CMake perspective such expressions are plain strings. However, they get dereferenced when the generator code is being run (for instance, when you run make or ninja).

Finally, there are <FOO> expressions. These are also plain strings and are mostly used in the internal CMake code as substitutes that later get replaced with string(REPLACE ...) command. For instance, such expressions are used extensively when adding support for new language in CMake, see share/cmake/Modules/CMakeAddNewLanguage.txt for more info on this.

The documentation for ExternalProject commands mention some <FOO> styled variables. <SOURCE_DIR> and <BINARY_DIR> are obviosly get replaced with real source and build directories for a given external project (not ${CMAKE_SOURCE_DIR} and ${CMAKE_BINARY_DIR} of the project that called ExternalProject_*()), but I wasn't able to find a full list of available substitutions for this set of commands.

like image 113
arrowd Avatar answered Oct 04 '22 02:10

arrowd