CMake/Help/command
Craig Scott 86ad7cc886 project: Only define non-cache vars if already defined
In c1ece78d11 (project: non cache <project> prefix variables are
also created, 2024-08-27), we started explicitly setting the non-cache
variable for <projectName>_SOURCE_DIR, <projectName>_BINARY_DIR,
and <projectName>_IS_TOP_LEVEL in addition to setting them as
cache variables. This changed the behavior when a project name
was used more than once, and the second project call happens in
the same scope or a child scope of the first. Previously, the first
project call would set cache variables, and the second project call
would not overwrite those cache variables. With the change in
c1ece78d11, after the second project call the non-cache variables
would mask the cache variables and the project code would see
a different value to what it did before.

Setting the non-cache variable was added to handle the case where
a call to FetchContent_MakeAvailable() would set some non-cache
variables, and it just so happened those matched the same cache
variables that the project() command would set in the project being
fetched. The fetched project would then see a different set of
project-specific variables compared to when it was built standalone.

This commit here narrows the change from c1ece78d11 such that
the non-cache variable is only set by project() if there was already
a non-cache variable set. This still fixes the motivating problem
c1ece78d11 was intended to solve, but it avoids changing the variable
values seen by a project that re-uses the same project name in related scopes.

Issue: #26243, #25714
Fixes: #26281
2024-09-20 10:33:25 -04:00
..
add_compile_definitions.rst COMPILE_DEFINITIONS property: ensure leading -D is removed in all cases 2022-12-13 16:54:56 +01:00
add_compile_options.rst Help: Clarify that {add,target}_compile_options are not used for linking 2023-03-31 11:30:51 -04:00
add_custom_command.rst add_custom_command: Allow OUTPUT filenames containing a hash '#' character 2024-05-15 13:27:46 -04:00
add_custom_target.rst Help: Clarify cross-references to target-dependent generator expressions 2024-04-25 10:49:16 -04:00
add_definitions.rst Help: Add _See Also_ sections to related CMake commands 2022-11-09 23:52:30 +04:00
add_dependencies.rst Help: Document MANUALLY_ADDED_DEPENDENCIES in add_dependencies 2024-03-29 18:43:30 +01:00
add_executable.rst Help: Use signature directive for the 'add_library' command 2023-12-06 13:05:23 -05:00
add_library.rst add_library: Reject shared libraries on platforms that do not support them 2024-03-29 11:06:32 -04:00
add_link_options.rst Help: Clarify that {add,target}_compile_options are not used for linking 2023-03-31 11:30:51 -04:00
add_subdirectory.rst Help: improve docs for the EXCLUDE_FROM_ALL directory property 2024-06-04 16:58:54 +02:00
add_test.rst Help: Fix typo in add_test documentation 2024-07-26 10:37:35 -04:00
aux_source_directory.rst Help: Improve documentation links and formatting 2019-03-27 16:01:20 +01:00
block.rst Help: Explain block() policy-scope rules more clearly 2023-09-01 21:28:56 +10:00
break.rst
build_command.rst Help: Add more CLI :option: references to various pages 2022-10-20 11:21:40 -04:00
build_name.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
cmake_file_api.rst cmake_file_api: New project command 2023-06-05 06:20:50 -04:00
cmake_host_system_information.rst Help: Replace link with its http redirect 2023-10-19 09:24:41 -04:00
cmake_language.rst try_compile: Propagating top level includes into whole-project calls 2024-05-30 19:01:03 +10:00
cmake_minimum_required.rst Help: Document cmake_minimum_required deprecation of old versions 2023-08-19 09:03:53 -04:00
cmake_parse_arguments.rst Help: Add _See Also_ sections to related CMake commands 2022-11-09 23:52:30 +04:00
cmake_path.rst Help: Fix cmake_path example 2024-04-26 08:49:07 -07:00
cmake_policy.rst Help: Explain block() policy-scope rules more clearly 2023-09-01 21:28:56 +10:00
configure_file.rst Help: Organize configure_file documentation into sections 2024-01-26 10:29:57 -05:00
continue.rst Help: clean up and clarify block() and return() 2022-11-08 00:05:55 +11:00
create_test_sourcelist.rst Help: Document create_test_sourcelist source path convention 2024-02-22 09:37:23 -05:00
ctest_build.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
ctest_configure.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
ctest_coverage.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
ctest_empty_binary_directory.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
ctest_memcheck.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
ctest_read_custom_files.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
ctest_run_script.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
ctest_sleep.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
ctest_start.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
ctest_submit.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
ctest_test.rst ctest: Allow passing -j without value to choose a contextual default 2024-03-10 11:41:39 -04:00
ctest_update.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
ctest_upload.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
define_property.rst Help: Document property redefinition semantics 2024-01-29 05:23:37 -05:00
DEPRECATED_POLICY_VERSIONS.txt Help: Document cmake_minimum_required deprecation of old versions 2023-08-19 09:03:53 -04:00
DEVICE_LINK_OPTIONS.txt Help: Use direct refs to genexes instead of `$<GENEX-NAME>` 2022-11-09 23:52:30 +04:00
else.rst
elseif.rst
enable_language.rst enable_language(): Fail if called before project() 2024-04-02 23:00:38 +11:00
enable_testing.rst
endblock.rst Add new flow-control commands for variables and policies scopes management 2022-08-22 16:25:53 +02:00
endforeach.rst
endfunction.rst
endif.rst
endmacro.rst
endwhile.rst
exec_program.rst exec_program(): Remove by policy CMP0153 2023-07-25 11:09:56 -04:00
execute_process.rst Help: Clarify interaction of execute_process *_FILE and *_VARIABLE options 2023-02-06 09:47:52 -05:00
export_library_dependencies.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
export.rst EXPORT_PACKAGE_DEPENDENCIES: Add experimental feature gate 2024-03-12 14:24:53 -04:00
file.rst Help: file(CONFIGURE) only updates output file timestamp if it changes 2024-09-06 15:48:38 +10:00
find_file.rst find_(library|file|path): Drop PATH-derived search prefixes 2023-09-14 15:13:50 -04:00
find_library.rst find_(library|file|path): Drop PATH-derived search prefixes 2023-09-14 15:13:50 -04:00
find_package.rst Help: Start find_package() docs with a new "Typical Usage" section 2024-05-31 16:05:23 +10:00
find_path.rst find_(library|file|path): Drop PATH-derived search prefixes 2023-09-14 15:13:50 -04:00
find_program.rst find_(library|file|path): Drop PATH-derived search prefixes 2023-09-14 15:13:50 -04:00
FIND_XXX_ORDER.txt
FIND_XXX_REGISTRY_VIEW.txt Help: Fix typos, grammar and formatting in CMP0134 policy docs 2022-08-30 15:11:09 -04:00
FIND_XXX_ROOT.txt
FIND_XXX.txt find_(library|file|path): Drop PATH-derived search prefixes 2023-09-14 15:13:50 -04:00
fltk_wrap_ui.rst
foreach.rst Help: Unindent _See Also_ related commands list 2022-11-07 22:55:06 +04:00
function.rst Help: Add _See Also_ sections to related CMake commands 2022-11-09 23:52:30 +04:00
GENEX_NOTE.txt Help: Move a note about arguments and genexes into include file 2022-11-09 23:52:30 +04:00
get_cmake_property.rst Help: Use <variable> consistently in property getter commands 2024-01-05 15:37:39 +11:00
get_directory_property.rst Help: Add _See Also_ sections to related CMake commands 2022-11-09 23:52:30 +04:00
get_filename_component.rst Help: Convert signatures of file command 2023-03-15 10:53:25 -04:00
get_property.rst get_property(TEST): Add DIRECTORY option 2023-08-11 10:50:52 -04:00
get_source_file_property.rst Help: Fix wrong return values for unset inherited properties 2024-01-05 17:40:16 +11:00
get_target_property.rst Help: Fix wrong return values for unset inherited properties 2024-01-05 17:40:16 +11:00
get_test_property.rst Help: Fix wrong return values for unset inherited properties 2024-01-05 17:40:16 +11:00
if.rst Help: Fix typos in 3.29 docs 2024-03-19 21:47:28 +11:00
include_directories.rst codespell: Fix typos 2023-05-22 16:51:15 -04:00
include_external_msproject.rst Help: Add .. versionadded directives to commands documentation 2020-11-09 20:51:57 +05:00
include_guard.rst Help: remove links from pages to themselves 2022-11-18 14:09:32 -05:00
include_regular_expression.rst
include.rst
install_files.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
install_programs.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
install_targets.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
install.rst Help: Fix location of install() note about superseded commands 2024-03-28 16:59:00 -04:00
link_directories.rst Help: Add _See Also_ sections to related CMake commands 2022-11-09 23:52:30 +04:00
link_libraries.rst
LINK_OPTIONS_LINKER.txt Help: Add SHELL, LINKER and host/device discussions to property docs 2021-05-15 16:31:16 +10:00
list.rst Help: Link to cmake-language(7) list docs from list() command docs 2023-06-28 07:51:37 -04:00
load_cache.rst Help: Clarify load_cache documentation of first parameter 2019-11-01 10:00:28 -04:00
load_command.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
macro.rst Help: Fix inaccurate use of "function" in macro docs 2024-05-21 09:13:57 -04:00
make_directory.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
mark_as_advanced.rst Help: Replace some versionadded directives with versionchanged 2020-11-12 09:44:01 +05:00
math.rst Help: math: note that floating point inputs are invalid 2023-02-14 13:33:31 -05:00
message.rst message: Add CONFIGURE_LOG mode to record a message in the configure log 2023-01-18 11:37:11 -05:00
option.rst Help: Clarify that option() is a boolean 2022-07-05 11:05:54 -04:00
OPTIONS_SHELL.txt Help: Add SHELL, LINKER and host/device discussions to property docs 2021-05-15 16:31:16 +10:00
output_required_files.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
project.rst project: Only define non-cache vars if already defined 2024-09-20 10:33:25 -04:00
qt_wrap_cpp.rst Autogen: Update Documentation 2024-02-08 09:16:37 -05:00
qt_wrap_ui.rst
remove_definitions.rst
remove.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
return.rst Help: Fix example for return command 2024-02-15 10:42:25 -05:00
separate_arguments.rst Help: Replace links with their permanent redirects 2023-02-17 08:45:01 -05:00
set_directory_properties.rst Help: Use <xxx> for non-keyword arguments in property command signatures 2024-01-05 15:31:39 +11:00
set_property.rst set_property(TEST): Add DIRECTORY option 2023-08-10 17:36:14 -04:00
set_source_files_properties.rst Help: Add _See Also_ sections to related CMake commands 2022-11-09 23:52:30 +04:00
set_target_properties.rst Help: Use <xxx> for non-keyword arguments in property command signatures 2024-01-05 15:31:39 +11:00
set_tests_properties.rst Help: Add missing DIRECTORY keyword to set_tests_properties() signature 2024-01-05 16:45:27 +11:00
set.rst Help: Remove "this command" ambiguity in set() docs 2023-09-01 21:28:56 +10:00
site_name.rst Help: Document site_name command use of HOSTNAME variable 2020-10-22 10:20:43 -04:00
source_group.rst Help: Clarify condition of tree command from source_group. 2021-06-23 17:24:09 +02:00
string.rst Help: Clarify documentation on regex character classes 2024-04-11 08:46:37 -04:00
subdir_depends.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
subdirs.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
SUPPORTED_LANGUAGES.txt Help: Update supported languages in project and enable_language 2023-01-20 13:55:38 -05:00
target_compile_definitions.rst Help: Update cmake-buildsystem(7) build and usage requirements 2024-04-24 09:06:32 -04:00
target_compile_features.rst Help: Move a note about arguments and genexes into include file 2022-11-09 23:52:30 +04:00
target_compile_options.rst Help: Update cmake-buildsystem(7) build and usage requirements 2024-04-24 09:06:32 -04:00
target_include_directories.rst Help: Update cmake-buildsystem(7) build and usage requirements 2024-04-24 09:06:32 -04:00
target_link_directories.rst Help: Update cmake-buildsystem(7) build and usage requirements 2024-04-24 09:06:32 -04:00
target_link_libraries.rst Help: Update cmake-buildsystem(7) build and usage requirements 2024-04-24 09:06:32 -04:00
target_link_options.rst Help: Update cmake-buildsystem(7) build and usage requirements 2024-04-24 09:06:32 -04:00
target_precompile_headers.rst Help: Update cmake-buildsystem(7) build and usage requirements 2024-04-24 09:06:32 -04:00
target_sources.rst Help: Update cmake-buildsystem(7) build and usage requirements 2024-04-24 09:06:32 -04:00
try_compile.rst try_compile: Propagating top level includes into whole-project calls 2024-05-30 19:01:03 +10:00
try_run.rst try_{compile,run}: add LINKER_LANGUAGE option 2023-10-16 11:30:17 -04:00
UNSET_NOTE.txt Help: Clarify that set(VAR) unsets VAR 2023-03-24 14:44:45 -04:00
unset.rst Help: Clarify that set(VAR) unsets VAR 2023-03-24 14:44:45 -04:00
use_mangled_mesa.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
utility_source.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
variable_requires.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00
variable_watch.rst Help: Expand documentation of variable_watch() 2020-07-09 17:22:59 +02:00
while.rst Help: Unindent _See Also_ related commands list 2022-11-07 22:55:06 +04:00
write_file.rst Help: Use CMake highlighting for command synopsis 2022-11-09 23:52:30 +04:00