From 2f0a3d43e15c2429d6d2b75d0892985b1e8302c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Wed, 30 Mar 2022 00:54:43 +0000 Subject: [PATCH 01/35] Help: Fix string(JSON ... LENGTH ...) signature The list of indices and/or member names is optional, i.e., can be empty. For example, string(JSON foo LENGTH "[0,0,0]") sets foo to 3. --- Help/command/string.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Help/command/string.rst b/Help/command/string.rst index 9b707eb83da..b1ca2cb80dc 100644 --- a/Help/command/string.rst +++ b/Help/command/string.rst @@ -612,7 +612,7 @@ Requires an element of object type. .. code-block:: cmake string(JSON [ERROR_VARIABLE ] - LENGTH [ ...]) + LENGTH [ ...]) Get the length of an element in ```` at the location given by the list of ```` arguments. From cf4100d7da85e714df727cebd591124486a026ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Tue, 29 Mar 2022 23:49:29 +0000 Subject: [PATCH 02/35] Help: Add that CMAKE_CACHEFILE_DIR might not be defined CMake only sets `CMAKE_CACHEFILE_DIR` when writing `CMakeCache.txt`, so the variable will usually be undefined when `CMakeLists.txt` runs. Revise its documentation to clarify that `CMAKE_BINARY_DIR` should be used instead. --- Help/variable/CMAKE_CACHEFILE_DIR.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Help/variable/CMAKE_CACHEFILE_DIR.rst b/Help/variable/CMAKE_CACHEFILE_DIR.rst index 8604d0e8c84..3fee09f37b3 100644 --- a/Help/variable/CMAKE_CACHEFILE_DIR.rst +++ b/Help/variable/CMAKE_CACHEFILE_DIR.rst @@ -1,7 +1,6 @@ CMAKE_CACHEFILE_DIR ------------------- -The directory with the ``CMakeCache.txt`` file. - -This is the full path to the directory that has the ``CMakeCache.txt`` -file in it. This is the same as :variable:`CMAKE_BINARY_DIR`. +This variable is used internally by CMake, and may not be set during +the first configuration of a build tree. When it is set, it has the +same value as :variable:`CMAKE_BINARY_DIR`. Use that variable instead. From 624ec3692f91788d84f9dc2b08573286bdef2cc9 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 30 Mar 2022 11:45:04 -0400 Subject: [PATCH 03/35] GNUInstallDirs: Revert "Apply Debian multiarch LIBDIR to more prefixes" Revert commit dd9584b352 (GNUInstallDirs: Apply Debian multiarch LIBDIR to more prefixes, 2021-11-19, v3.23.0-rc1~323^2). There are separate problems with activating multiarch `LIBDIR` for each prefix it added: * Prefix `/` is often used to stage an installation with `DESTDIR` for inclusion in a tarball package or similar. * Prefix `/usr/local` is the default `CMAKE_INSTALL_PREFIX`, causing the multiarch `LIBDIR` to be cached after the first configuration, even if the prefix changes later. Revert the change for now, except for the documentation update. Further discussion will be needed to select a way to enable multiarch `LIBDIR` for `/` and `/usr/local`. Fixes: #23365 Issue: #19698 --- Modules/GNUInstallDirs.cmake | 6 ++---- Tests/RunCMake/GNUInstallDirs/Root-Debian-stderr.txt | 4 ++-- Tests/RunCMake/GNUInstallDirs/UsrLocal-Debian-stderr.txt | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Modules/GNUInstallDirs.cmake b/Modules/GNUInstallDirs.cmake index 4e7f87b9211..bd72901941e 100644 --- a/Modules/GNUInstallDirs.cmake +++ b/Modules/GNUInstallDirs.cmake @@ -55,7 +55,7 @@ where ```` is one of: object code libraries (``lib`` or ``lib64``) On Debian, this may be ``lib/`` when - :variable:`CMAKE_INSTALL_PREFIX` is ``/``, ``/usr``, or ``/usr/local``. + :variable:`CMAKE_INSTALL_PREFIX` is ``/usr``. ``INCLUDEDIR`` C header files (``include``) ``OLDINCLUDEDIR`` @@ -273,9 +273,7 @@ if(NOT DEFINED CMAKE_INSTALL_LIBDIR OR (_libdir_set if(__system_type_for_install STREQUAL "debian") if(CMAKE_LIBRARY_ARCHITECTURE) - if("${CMAKE_INSTALL_PREFIX}" STREQUAL "/" - OR "${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$" - OR "${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/local/?$") + if("${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$") set(_LIBDIR_DEFAULT "lib/${CMAKE_LIBRARY_ARCHITECTURE}") endif() if(DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX diff --git a/Tests/RunCMake/GNUInstallDirs/Root-Debian-stderr.txt b/Tests/RunCMake/GNUInstallDirs/Root-Debian-stderr.txt index 2019459d71f..25f80d3f612 100644 --- a/Tests/RunCMake/GNUInstallDirs/Root-Debian-stderr.txt +++ b/Tests/RunCMake/GNUInstallDirs/Root-Debian-stderr.txt @@ -4,7 +4,7 @@ CMAKE_INSTALL_DATAROOTDIR='usr/share' CMAKE_INSTALL_DOCDIR='usr/share/doc/Root' CMAKE_INSTALL_INCLUDEDIR='usr/include' CMAKE_INSTALL_INFODIR='usr/share/info' -CMAKE_INSTALL_LIBDIR='usr/lib/arch' +CMAKE_INSTALL_LIBDIR='usr/lib' CMAKE_INSTALL_LIBEXECDIR='usr/libexec' CMAKE_INSTALL_LOCALEDIR='usr/share/locale' CMAKE_INSTALL_LOCALSTATEDIR='var' @@ -19,7 +19,7 @@ CMAKE_INSTALL_FULL_DATAROOTDIR='/usr/share' CMAKE_INSTALL_FULL_DOCDIR='/usr/share/doc/Root' CMAKE_INSTALL_FULL_INCLUDEDIR='/usr/include' CMAKE_INSTALL_FULL_INFODIR='/usr/share/info' -CMAKE_INSTALL_FULL_LIBDIR='/usr/lib/arch' +CMAKE_INSTALL_FULL_LIBDIR='/usr/lib' CMAKE_INSTALL_FULL_LIBEXECDIR='/usr/libexec' CMAKE_INSTALL_FULL_LOCALEDIR='/usr/share/locale' CMAKE_INSTALL_FULL_LOCALSTATEDIR='/var' diff --git a/Tests/RunCMake/GNUInstallDirs/UsrLocal-Debian-stderr.txt b/Tests/RunCMake/GNUInstallDirs/UsrLocal-Debian-stderr.txt index 08301380e05..30795c8a955 100644 --- a/Tests/RunCMake/GNUInstallDirs/UsrLocal-Debian-stderr.txt +++ b/Tests/RunCMake/GNUInstallDirs/UsrLocal-Debian-stderr.txt @@ -4,7 +4,7 @@ CMAKE_INSTALL_DATAROOTDIR='share' CMAKE_INSTALL_DOCDIR='share/doc/UsrLocal' CMAKE_INSTALL_INCLUDEDIR='include' CMAKE_INSTALL_INFODIR='share/info' -CMAKE_INSTALL_LIBDIR='lib/arch' +CMAKE_INSTALL_LIBDIR='lib' CMAKE_INSTALL_LIBEXECDIR='libexec' CMAKE_INSTALL_LOCALEDIR='share/locale' CMAKE_INSTALL_LOCALSTATEDIR='var' @@ -19,7 +19,7 @@ CMAKE_INSTALL_FULL_DATAROOTDIR='/usr/local/share' CMAKE_INSTALL_FULL_DOCDIR='/usr/local/share/doc/UsrLocal' CMAKE_INSTALL_FULL_INCLUDEDIR='/usr/local/include' CMAKE_INSTALL_FULL_INFODIR='/usr/local/share/info' -CMAKE_INSTALL_FULL_LIBDIR='/usr/local/lib/arch' +CMAKE_INSTALL_FULL_LIBDIR='/usr/local/lib' CMAKE_INSTALL_FULL_LIBEXECDIR='/usr/local/libexec' CMAKE_INSTALL_FULL_LOCALEDIR='/usr/local/share/locale' CMAKE_INSTALL_FULL_LOCALSTATEDIR='/usr/local/var' From f7c6b9833c55257d2b83e2cb5678139ba52df3dc Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 30 Mar 2022 15:12:25 -0400 Subject: [PATCH 04/35] CUDA: Ninja generator generates valid compile database The ninja generator has been updated to poperly write the compile database when the CUDA language has been enabled. Fixes #23368 --- Source/cmNinjaTargetGenerator.cxx | 34 ++++++++++++++------------ Tests/CudaOnly/WithDefs/CMakeLists.txt | 2 ++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index dd7d2446340..e61b4b6e608 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -1678,28 +1678,32 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand( compileObjectVars.Includes = includes.c_str(); // Rule for compiling object file. - std::vector compileCmds; + std::string cudaCompileMode; if (language == "CUDA") { - std::string cmdVar; if (this->GeneratorTarget->GetPropertyAsBool( "CUDA_SEPARABLE_COMPILATION")) { - cmdVar = "CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION"; - } else if (this->GeneratorTarget->GetPropertyAsBool( - "CUDA_PTX_COMPILATION")) { - cmdVar = "CMAKE_CUDA_COMPILE_PTX_COMPILATION"; + const std::string& rdcFlag = + this->Makefile->GetRequiredDefinition("_CMAKE_CUDA_RDC_FLAG"); + cudaCompileMode = cmStrCat(cudaCompileMode, rdcFlag, " "); + } + if (this->GeneratorTarget->GetPropertyAsBool("CUDA_PTX_COMPILATION")) { + const std::string& ptxFlag = + this->Makefile->GetRequiredDefinition("_CMAKE_CUDA_PTX_FLAG"); + cudaCompileMode = cmStrCat(cudaCompileMode, ptxFlag); } else { - cmdVar = "CMAKE_CUDA_COMPILE_WHOLE_COMPILATION"; + const std::string& wholeFlag = + this->Makefile->GetRequiredDefinition("_CMAKE_CUDA_WHOLE_FLAG"); + cudaCompileMode = cmStrCat(cudaCompileMode, wholeFlag); } - const std::string& compileCmd = - this->GetMakefile()->GetRequiredDefinition(cmdVar); - cmExpandList(compileCmd, compileCmds); - } else { - const std::string cmdVar = cmStrCat("CMAKE_", language, "_COMPILE_OBJECT"); - const std::string& compileCmd = - this->GetMakefile()->GetRequiredDefinition(cmdVar); - cmExpandList(compileCmd, compileCmds); + compileObjectVars.CudaCompileMode = cudaCompileMode.c_str(); } + std::vector compileCmds; + const std::string cmdVar = cmStrCat("CMAKE_", language, "_COMPILE_OBJECT"); + const std::string& compileCmd = + this->Makefile->GetRequiredDefinition(cmdVar); + cmExpandList(compileCmd, compileCmds); + std::unique_ptr rulePlaceholderExpander( this->GetLocalGenerator()->CreateRulePlaceholderExpander()); diff --git a/Tests/CudaOnly/WithDefs/CMakeLists.txt b/Tests/CudaOnly/WithDefs/CMakeLists.txt index 02f043f362b..39bcd918f27 100644 --- a/Tests/CudaOnly/WithDefs/CMakeLists.txt +++ b/Tests/CudaOnly/WithDefs/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.18) project(WithDefs CUDA) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + set(release_compile_defs DEFREL) #Goal for this example: From 7a614977f9443146e8b423b6dc5a11a7c79862ce Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 29 Mar 2022 16:26:26 -0400 Subject: [PATCH 05/35] CMakeDependentOption: improve documentation This makes it far clearer that `` is a list up front instead of burying the lede because a list is generally "trivially true" in CMake[1]. Also clarify that `` is only available as a local variable and if queried outside of the "scope" of the `cmake_dependent_option` call, will get the stored user cache value. [1] The exception being when the last entry ends in `-NOTFOUND`. Suggested-by: Rui Oliveira --- Modules/CMakeDependentOption.cmake | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Modules/CMakeDependentOption.cmake b/Modules/CMakeDependentOption.cmake index b7c478f6440..ac0e2624a33 100644 --- a/Modules/CMakeDependentOption.cmake +++ b/Modules/CMakeDependentOption.cmake @@ -16,13 +16,18 @@ conditions are true. cmake_dependent_option(