I have a directory with CMakeLists.txt
. And it invokes a CMake module module1.cmake
file located elsewhere.
module1.cmake
will reference a variable named XXX
, which may come from:
- the environment variable
%XXX%
. - the command line through
cmake -D XXX=
XXX
defined in the invoking directory'sCMakeLists.txt
throughset()
.- and the CACHE entry in the previously configured build folder
Then module1.cmake
will store the variable XXX
into the CACHE.
In the module1.cmake
file, I need to tell where XXX
is from because I need to treat them differently.
For 1, I can check the value of $ENV{XXX}
.
For 4, I was thinking about using get_property(cached_XXX CACHE XXX PROPERTY VALUE)
and check the value of cached_XXX
. But it turns out the -D XXX=
option always update the CACHE entry. So I cannot tell if the cached_XXX
value is from an old CACHE or from the current -D
option.
So after all, how can I tell between 2, 3 and 4?