If I do:
set(SourceDir ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
message("SourceDir: " ${SourceDir})
The message says that SourceDir is empty. Presumably it is being set in the parent scope only. Is there a way to set the variable in the current scope AND the parent scope? So that I don't have to do:
set(SourceDir ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
set(SourceDir ${CMAKE_CURRENT_SOURCE_DIR})
message("SourceDir: " ${SourceDir})
Options and variables are defined on the CMake command line like this: $ cmake -DVARIABLE=value path/to/source You can set a variable after the initial `CMake` invocation to change its value. You can also undefine a variable: $ cmake -UVARIABLE path/to/source Variables are stored in the `CMake` cache.
You can use the command line to set entries in the Cache with the syntax cmake -D var:type=value , just cmake -D var=value or with cmake -C CMakeInitialCache. cmake . You can unset entries in the Cache with unset(... CACHE) .
Set a normal, cache, or environment variable to a given value. See the cmake-language(7) variables documentation for the scopes and interaction of normal variables and cache entries. Signatures of this command that specify a <value>... placeholder expect zero or more arguments.
Variables defined in the script are only available to the script scope and not the global or parent scope.
When you set it for PARENT_SCOPE, it doesn't do it for current scope somehow. But a two step process works. The first line sets it locally, the second line exports it to the parent scope.
set (LIB_VER 6)
set (LIB_VER ${LIB_VER} PARENT_SCOPE)
I think you can not. The documentation says:
Each new directory or function creates a new scope.
If I understand it correctly when your SET
gets executed, its scope is already created by copying the parent scope. So no matter what you do to the original (PARENT_SCOPE
) your local scope won't change.
You'd better ask the question on CMake's user list to verify that they don't do fallback to parent when a variable is not defined in the local scope. If they do however, this is a bug.
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