CMake variable extension using "@" versus "$ {}"

Consider the following:

SET(TEST_DIR, "test") INSTALL(PROGRAMS scripts/foo.py DESTINATION ${TEST_DIR}) INSTALL(PROGRAMS scripts/foo.py DESTINATION @ TEST_DIR@ ) 

The first INSTALL command does not work. The second one does. Why is this? What is the difference between the two? I did not find a link to the @@ extension, except in the context of creating configuration files. Everything else uses only the extension ${} .

UPDATE: OK, obvious error in the above. My SET() command has an extraneous comma. Remove it so it looks like this:

  SET(TEST_DIR "test") 

leads to @@ and ${} . Still wondering (a) what the value of @@ , and not ${} , and why only the first one worked with my incorrect SET() expression.

+4
source share
2 answers

According to the documentation for the configure_file() command, when configuring a file, the form form ${VAR} and @ VAR@ will be replaced with the VAR value. Based on your experience above and on some tests, I made both forms replaced when CMake evaluates your CMakeLists.txt . Since this is not documented, I would recommend not using @ VAR@ from your CMakeLists.txt

Note that when using configure_file() you can restrict the replacement only to the @ VAR@ form with the @ONLY argument.

+4
source

As far as I know, the @VAR @ syntax is only used when replacing variables with the configure_file command.

Note that the configure_file command allows an additional @ONLY option. Using it, you can indicate that only @VAR @ is replaced, but $ {VAR} is saved.

As an example, this can be useful when creating, for example, a cmake file that will later be used with CMake. For instance. when creating a project, @VAR @ will be replaced when using configure_file. After you have distributed your project, and someone else is using the generated UseProject.cmake file, the $ {VAR} $ entries will be replaced.

+1
source

All Articles