Reputation: 7146
I have a CMakeLists.txt with the following in it, that I can not modify:
set(BUILD_SHARED_LIBS ON)
I want to override this variable use the commandline. I tried this:
cmake -UBUILD_SHARED_LIBS -DBUILD_SHARED_LIBS=OFF ..
but it has no effect. Is there any way to tell cmake to use a value from the commandline instead of this value?
Note: I am aware that using the cache like shown below would solve the problem, but as I cannot edit the file, that sadly is not an option:
set(BUILD_SHARED_LIBS ON CACHE BOOL "library build mode")
Upvotes: 9
Views: 6637
Reputation: 65870
Using command line you cannot override setting of the normal (non-cached) variable.
If you pass a variable via command line, then it is always a cache variable. At the time when normal flavor of the variable is set in the CMakeLists.txt
, both flavors exist. But when a variable is dereferenced, CMake prefers normal flavor to the cached one. See more in the variables' documentation.
Upvotes: 9