Issue
I do have a project with an option, which is used to generate related executables, which are generated in lower-level subdirectories, and the higher-level CMakeLists.txt sets the option ON or OFF. For the distribution I need the executables (having option-dependent names) for both the ON and the OFF state. Presently, I set the option, run CMake, set the option, run CMake. Is it safe (primarily thinking about cacheing and threading) if I use something like shown below?
opt ON
include(generate)
opt OFF
include(generate)
Solution
Normally, it should work without caching:
set(<option> ON)
include(generate)
set(<option> OFF)
include(generate)
Threading will not be a problem in any case, as interpretation of CMake scripts(configuration stage) is single-threaded as opposite to build stage.
Using option()
command instead of set()
will not work, as option()
does not modify variable if it is already set in the cache.
You may use set(<option> <value> CACHE ...)
instead of set(<option> <value>)
, but such increasing of complexity usually is not needed, unless generate
script explicitely checks cached option's value.
Note, that generate
script should not only "have option-dependent names", but also shouldn't create cached entries which depends on <option>
value. Otherwise calling script twice with different options is broken.
Answered By - Tsyvarev Answer Checked By - Robin (WPSolving Admin)