Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake cache variables vs. global properties: Simple syntax to use the variable value

To make values available to the whole CMake environment from within a subdirectory one may set a cache variable using the set(VARIABLE_NAME Value CACHE INTERNAL "") syntax or set a global property using the set_property(GLOBAL PROPERTY VARIABLE_NAME Value) syntax (see also this very good answer about variables in CMake).

Using the latter has the advantages that you are not "polluting" the CMake cache for something it is not designed for and that you are not dependent on the cache being deleted when not using the FORCE parameter.

But the syntax to use the variable value is not that user-friendly as you have to retrieve the value using get_property instead of simply using the ${...} notation.

Is there a simpler syntax to use instead of get_property (some kind of syntactic sugar)?

like image 380
Roland Sarrazin Avatar asked Dec 15 '15 13:12

Roland Sarrazin


1 Answers

Let's summarize the comments.

To my actual question: There is no specific shortcut to use get_property.

Useful comments:

  • As CACHE INTERNAL implies FORCE it is okay to use cached variables to make variables globally accessible.
  • It is good practice to start the CMake file by explicitly cleaning / setting the internal cache variables to avoid unpredictable behavior at repeated runs.
like image 165
Roland Sarrazin Avatar answered Sep 22 '22 06:09

Roland Sarrazin