CMake Cache Variables Versus Global Properties: Simple Syntax for Using a Variable Value

To make values ​​available for the entire CMake environment from within a subdirectory, you can set the cache variable using the set(VARIABLE_NAME Value CACHE INTERNAL "") syntax set(VARIABLE_NAME Value CACHE INTERNAL "") or set the global property using the set_property(GLOBAL PROPERTY VARIABLE_NAME Value) syntax set_property(GLOBAL PROPERTY VARIABLE_NAME Value) (see also this very good answer about variables in CMake).

Using the latter has the advantage that you do not "pollute" the CMake cache for something that it is not intended for, and that you are not dependent on the cache being deleted if you do not use the FORCE parameter.

But the syntax for using a variable's value is not so user-friendly that you need to get the value with get_property instead of just using the ${...} notation.

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

+5
source share
1 answer

Summarize the comments.

To my actual question: there is no special shorthand for using get_property .

Useful comments:

  • Because CACHE INTERNAL implies FORCE , you can use cached variables to make variables globally available.
  • It’s good practice to run the CMake file by explicitly clearing / setting the internal cache variables to avoid unpredictable behavior on repeated launches.
+2
source

Source: https://habr.com/ru/post/1238261/


All Articles