CMake overrides cached variable using command line

As I understand it, when you provide a variable through the cmake command line (for example, -DMy_Var = ON), this variable is stored inside the cache. When this variable is available for subsequent runs of the CMake script, it will always receive the value stored in the cache, ignoring any subsequent parameters -DMy_Var = OFF on the command line.

I understand that you can force the cache variable to be overwritten inside the CMakeLists.txt file with "FORCE" or by deleting the cache file, however I would like to know if there is a good way for -DMy_Var = XXX to be effective every time it is specified?

I have a suspicion that the answer is not to change these variables within the same assembly, but that they have separate assembly subsystems for different configurations. Can anyone clarify?

+5
source share
2 answers

I found two methods for changing CMake variables.

The first is suggested in the previous answer:

cmake -U My_Var -D Mu_Var=new_value

( ) - CMake. CMake, cmake, -D My_Var=.... , . :

if (NOT DEFINED BUILD_NUMBER)
  set(BUILD_NUMBER "unknown")
endif()

BUILD_NUMBER ( CI):

cmake -D BUILD_NUMBER=4242 <source_dir>

, BUILD_NUMBER ( ), .

+1

CMake -UMy_Var -DMy_Var=new_value

. https://cmake.org/cmake/help/v3.9/manual/cmake.1.html

, .

0

All Articles