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)?
Let's summarize the comments.
To my actual question: There is no specific shortcut to use get_property
.
Useful comments:
CACHE INTERNAL
implies FORCE
it is okay to use cached variables to make variables globally accessible.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With