cmake_dependent_option: Does not work with set()
If you have these two lines in a subdirectory
set(BUILD_TESTING OFF)
cmake_dependent_option(BUILD_TESTING "help text" ON "" OFF)
then the variable will be set to OFF in the parent scope.
This leads to bugs with fetch Content, where both of these lines are set in a subproject and therefore BUILD_TESTING
is always off in my project.
I uploaded a minimal reproducing example here: https://gitlab.kitware.com/Leon0402/cmake-dependent-option-bug
The output is:
-- Before parent scope: ON
-- Before: ON
-- After: OFF
-- After parent scope: OFF
I expected the last line to be ON
as a set should not influence the parent scope. This only happens if you use set
and cmake_dependent_option
together.
Edited by Brad King