From 2a82bd85b66f5de2acaac60159c9b624da37ce37 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Mon, 4 Oct 2021 21:46:46 +1100 Subject: Help: Add documentation for CMAKE_TLS_CAINFO --- Help/command/file.rst | 5 +++-- Help/manual/cmake-variables.7.rst | 1 + Help/variable/CMAKE_TLS_CAINFO.rst | 9 +++++++++ Modules/ExternalProject.cmake | 8 ++++---- 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 Help/variable/CMAKE_TLS_CAINFO.rst diff --git a/Help/command/file.rst b/Help/command/file.rst index 96a55ee..798f507 100644 --- a/Help/command/file.rst +++ b/Help/command/file.rst @@ -1113,8 +1113,9 @@ If neither ``NETRC`` option is given CMake will check variables For ``https://`` URLs CMake must be built with OpenSSL support. ``TLS/SSL`` certificates are not checked by default. Set ``TLS_VERIFY`` to ``ON`` to -check certificates. If neither ``TLS`` option is given CMake will check -variables :variable:`CMAKE_TLS_VERIFY` and ``CMAKE_TLS_CAINFO``, respectively. +check certificates. If neither ``TLS`` option is given, CMake will use the +settings from the :variable:`CMAKE_TLS_VERIFY` and :variable:`CMAKE_TLS_CAINFO` +variables instead. Additional options to ``DOWNLOAD`` are: diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 7cfa0c8..63ea5ac 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -247,6 +247,7 @@ Variables that Change Behavior /variable/CMAKE_SYSTEM_LIBRARY_PATH /variable/CMAKE_SYSTEM_PREFIX_PATH /variable/CMAKE_SYSTEM_PROGRAM_PATH + /variable/CMAKE_TLS_CAINFO /variable/CMAKE_TLS_VERIFY /variable/CMAKE_USER_MAKE_RULES_OVERRIDE /variable/CMAKE_WARN_DEPRECATED diff --git a/Help/variable/CMAKE_TLS_CAINFO.rst b/Help/variable/CMAKE_TLS_CAINFO.rst new file mode 100644 index 0000000..fe34335 --- /dev/null +++ b/Help/variable/CMAKE_TLS_CAINFO.rst @@ -0,0 +1,9 @@ +CMAKE_TLS_CAINFO +---------------- + +Specify the default value for the :command:`file(DOWNLOAD)` and +:command:`file(UPLOAD)` commands' ``TLS_CAINFO`` options. +It is unset by default. + +This variable is also used by the :module:`ExternalProject` module +for internal calls to :command:`file(DOWNLOAD)`. diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index 9e25bee..e49faae 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -224,14 +224,14 @@ External Project Definition ``TLS_CAINFO `` Specify a custom certificate authority file to use if ``TLS_VERIFY`` is enabled. If this option is not specified, the value of the - ``CMAKE_TLS_CAINFO`` variable will be used instead (see + :variable:`CMAKE_TLS_CAINFO` variable will be used instead (see :command:`file(DOWNLOAD)`) ``NETRC `` .. versionadded:: 3.11 Specify whether the ``.netrc`` file is to be used for operation. - If this option is not specified, the value of the ``CMAKE_NETRC`` + If this option is not specified, the value of the :variable:`CMAKE_NETRC` variable will be used instead (see :command:`file(DOWNLOAD)`) Valid levels are: @@ -251,8 +251,8 @@ External Project Definition Specify an alternative ``.netrc`` file to the one in your home directory if the ``NETRC`` level is ``OPTIONAL`` or ``REQUIRED``. If this option - is not specified, the value of the ``CMAKE_NETRC_FILE`` variable will - be used instead (see :command:`file(DOWNLOAD)`) + is not specified, the value of the :variable:`CMAKE_NETRC_FILE` variable + will be used instead (see :command:`file(DOWNLOAD)`) .. versionadded:: 3.1 Added support for `tbz2`, `.tar.xz`, `.txz`, and `.7z` extensions. -- cgit v0.12 From 96937438b74469eea5b0ae46b4e13489ac3faec7 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Mon, 4 Oct 2021 22:01:48 +1100 Subject: Help: Clean up how TLS and NETRC variables are discussed Mention of the fallback of the command options to the CMAKE_... variables was repeated in places. The wording was also a bit unclear about whether the fallback only occurred when neither TLS or neither NETRC option was given to the command. Move the fallback details directly to each relevant option instead. Also use cross-referencing to the variables where it was not linked previously. --- Help/command/file.rst | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Help/command/file.rst b/Help/command/file.rst index 798f507..5a3fd88 100644 --- a/Help/command/file.rst +++ b/Help/command/file.rst @@ -1073,7 +1073,7 @@ Options to both ``DOWNLOAD`` and ``UPLOAD`` are: .. versionadded:: 3.11 Specify whether the .netrc file is to be used for operation. If this - option is not specified, the value of the ``CMAKE_NETRC`` variable + option is not specified, the value of the :variable:`CMAKE_NETRC` variable will be used instead. Valid levels are: @@ -1092,30 +1092,28 @@ Options to both ``DOWNLOAD`` and ``UPLOAD`` are: Specify an alternative .netrc file to the one in your home directory, if the ``NETRC`` level is ``OPTIONAL`` or ``REQUIRED``. If this option - is not specified, the value of the ``CMAKE_NETRC_FILE`` variable will + is not specified, the value of the :variable:`CMAKE_NETRC_FILE` variable will be used instead. -If neither ``NETRC`` option is given CMake will check variables -``CMAKE_NETRC`` and ``CMAKE_NETRC_FILE``, respectively. - ``TLS_VERIFY `` Specify whether to verify the server certificate for ``https://`` URLs. - The default is to *not* verify. + The default is to *not* verify. If this option is not specified, the value + of the :variable:`CMAKE_TLS_VERIFY` variable will be used instead. .. versionadded:: 3.18 Added support to ``file(UPLOAD)``. ``TLS_CAINFO `` - Specify a custom Certificate Authority file for ``https://`` URLs. + Specify a custom Certificate Authority file for ``https://`` URLs. If this + option is not specified, the value of the :variable:`CMAKE_TLS_CAINFO` + variable will be used instead. .. versionadded:: 3.18 Added support to ``file(UPLOAD)``. For ``https://`` URLs CMake must be built with OpenSSL support. ``TLS/SSL`` certificates are not checked by default. Set ``TLS_VERIFY`` to ``ON`` to -check certificates. If neither ``TLS`` option is given, CMake will use the -settings from the :variable:`CMAKE_TLS_VERIFY` and :variable:`CMAKE_TLS_CAINFO` -variables instead. +check certificates. Additional options to ``DOWNLOAD`` are: -- cgit v0.12 From 1851aa49be01076e0869ce14b22b9a860454bba4 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Mon, 4 Oct 2021 21:47:12 +1100 Subject: FetchContent: Pass through networking-related CMAKE_... variables CMAKE_TLS_VERIFY, CMAKE_TLS_CAINFO, CMAKE_NETRC and CMAKE_NETRC_FILE are now passed through to the underlying ExternalProject sub-build. Previously, they were silently ignored. Fixes: #22144 --- .../dev/fetchcontent-CMAKE-vars-passthrough.rst | 8 +++++ Help/variable/CMAKE_NETRC.rst | 10 +++--- Help/variable/CMAKE_NETRC_FILE.rst | 10 +++--- Help/variable/CMAKE_TLS_CAINFO.rst | 4 +-- Help/variable/CMAKE_TLS_VERIFY.rst | 4 +-- Modules/FetchContent.cmake | 32 ++++++++++++++---- Tests/RunCMake/FetchContent/RunCMakeTest.cmake | 1 + Tests/RunCMake/FetchContent/VarPassthroughs.cmake | 38 ++++++++++++++++++++++ 8 files changed, 88 insertions(+), 19 deletions(-) create mode 100644 Help/release/dev/fetchcontent-CMAKE-vars-passthrough.rst create mode 100644 Tests/RunCMake/FetchContent/VarPassthroughs.cmake diff --git a/Help/release/dev/fetchcontent-CMAKE-vars-passthrough.rst b/Help/release/dev/fetchcontent-CMAKE-vars-passthrough.rst new file mode 100644 index 0000000..842c016 --- /dev/null +++ b/Help/release/dev/fetchcontent-CMAKE-vars-passthrough.rst @@ -0,0 +1,8 @@ +fetchcontent-CMAKE-vars-passthrough.rst +--------------------------------------- + +* The :module:`FetchContent` module now passes through the + :variable:`CMAKE_TLS_VERIFY`, :variable:`CMAKE_TLS_CAINFO`, + :variable:`CMAKE_NETRC` and :variable:`CMAKE_NETRC_FILE` variables (when + defined) to the underlying :module:`ExternalProject` sub-build. + Previously, those variables were silently ignored by :module:`FetchContent`. diff --git a/Help/variable/CMAKE_NETRC.rst b/Help/variable/CMAKE_NETRC.rst index 2c64a81..bddfca5 100644 --- a/Help/variable/CMAKE_NETRC.rst +++ b/Help/variable/CMAKE_NETRC.rst @@ -3,9 +3,11 @@ CMAKE_NETRC .. versionadded:: 3.11 -This variable is used to initialize the ``NETRC`` option for -:command:`file(DOWNLOAD)` and :command:`file(UPLOAD)` commands and the -module :module:`ExternalProject`. See those commands for additional -information. +This variable is used to initialize the ``NETRC`` option for the +:command:`file(DOWNLOAD)` and :command:`file(UPLOAD)` commands. +See those commands for additional information. + +This variable is also used by the :module:`ExternalProject` and +:module:`FetchContent` modules for internal calls to :command:`file(DOWNLOAD)`. The local option takes precedence over this variable. diff --git a/Help/variable/CMAKE_NETRC_FILE.rst b/Help/variable/CMAKE_NETRC_FILE.rst index 97a645e..af98170 100644 --- a/Help/variable/CMAKE_NETRC_FILE.rst +++ b/Help/variable/CMAKE_NETRC_FILE.rst @@ -3,9 +3,11 @@ CMAKE_NETRC_FILE .. versionadded:: 3.11 -This variable is used to initialize the ``NETRC_FILE`` option for -:command:`file(DOWNLOAD)` and :command:`file(UPLOAD)` commands and the -module :module:`ExternalProject`. See those commands for additional -information. +This variable is used to initialize the ``NETRC_FILE`` option for the +:command:`file(DOWNLOAD)` and :command:`file(UPLOAD)` commands. +See those commands for additional information. + +This variable is also used by the :module:`ExternalProject` and +:module:`FetchContent` modules for internal calls to :command:`file(DOWNLOAD)`. The local option takes precedence over this variable. diff --git a/Help/variable/CMAKE_TLS_CAINFO.rst b/Help/variable/CMAKE_TLS_CAINFO.rst index fe34335..07f6366 100644 --- a/Help/variable/CMAKE_TLS_CAINFO.rst +++ b/Help/variable/CMAKE_TLS_CAINFO.rst @@ -5,5 +5,5 @@ Specify the default value for the :command:`file(DOWNLOAD)` and :command:`file(UPLOAD)` commands' ``TLS_CAINFO`` options. It is unset by default. -This variable is also used by the :module:`ExternalProject` module -for internal calls to :command:`file(DOWNLOAD)`. +This variable is also used by the :module:`ExternalProject` and +:module:`FetchContent` modules for internal calls to :command:`file(DOWNLOAD)`. diff --git a/Help/variable/CMAKE_TLS_VERIFY.rst b/Help/variable/CMAKE_TLS_VERIFY.rst index 24f8a25..b22f1ce 100644 --- a/Help/variable/CMAKE_TLS_VERIFY.rst +++ b/Help/variable/CMAKE_TLS_VERIFY.rst @@ -5,8 +5,8 @@ Specify the default value for the :command:`file(DOWNLOAD)` and :command:`file(UPLOAD)` commands' ``TLS_VERIFY`` options. If not set, the default is *off*. -This setting is also used by the :module:`ExternalProject` module -for internal calls to :command:`file(DOWNLOAD)`. +This variable is also used by the :module:`ExternalProject` and +:module:`FetchContent` modules for internal calls to :command:`file(DOWNLOAD)`. TLS verification can help provide confidence that one is connecting to the desired server. When downloading known content, one should diff --git a/Modules/FetchContent.cmake b/Modules/FetchContent.cmake index 5ea8b2a..be75689 100644 --- a/Modules/FetchContent.cmake +++ b/Modules/FetchContent.cmake @@ -162,6 +162,13 @@ Commands This may be needed for things like password prompts or real-time display of command progress. + .. versionadded:: 3.22 + The :variable:`CMAKE_TLS_VERIFY`, :variable:`CMAKE_TLS_CAINFO`, + :variable:`CMAKE_NETRC` and :variable:`CMAKE_NETRC_FILE` variables now + provide the defaults for their corresponding content options, just like + they do for :command:`ExternalProject_Add`. Previously, these variables + were ignored by the ``FetchContent`` module. + .. command:: FetchContent_MakeAvailable .. versionadded:: 3.14 @@ -1016,18 +1023,29 @@ ExternalProject_Add_Step(${contentName}-populate copyfile unset(subCMakeOpts) endif() - if(DEFINED CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY) - list(APPEND subCMakeOpts - "-DCMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY=${CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY}") - endif() + set(__FETCHCONTENT_CACHED_INFO "") + set(__passthrough_vars + CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY + CMAKE_TLS_VERIFY + CMAKE_TLS_CAINFO + CMAKE_NETRC + CMAKE_NETRC_FILE + ) + foreach(var IN LISTS __passthrough_vars) + if(DEFINED ${var}) + # Embed directly in the generated CMakeLists.txt file to avoid making + # the cmake command line excessively long. It also makes debugging and + # testing easier. + string(APPEND __FETCHCONTENT_CACHED_INFO "set(${var} [==[${${var}}]==])\n") + endif() + endforeach() # Avoid using if(... IN_LIST ...) so we don't have to alter policy settings - set(__FETCHCONTENT_CACHED_INFO "") list(FIND ARG_UNPARSED_ARGUMENTS GIT_REPOSITORY indexResult) if(indexResult GREATER_EQUAL 0) find_package(Git QUIET) - set(__FETCHCONTENT_CACHED_INFO -"# Pass through things we've already detected in the main project to avoid + string(APPEND __FETCHCONTENT_CACHED_INFO " +# Pass through things we've already detected in the main project to avoid # paying the cost of redetecting them again in ExternalProject_Add() set(GIT_EXECUTABLE [==[${GIT_EXECUTABLE}]==]) set(GIT_VERSION_STRING [==[${GIT_VERSION_STRING}]==]) diff --git a/Tests/RunCMake/FetchContent/RunCMakeTest.cmake b/Tests/RunCMake/FetchContent/RunCMakeTest.cmake index 9baeab7..e83c45e 100644 --- a/Tests/RunCMake/FetchContent/RunCMakeTest.cmake +++ b/Tests/RunCMake/FetchContent/RunCMakeTest.cmake @@ -9,6 +9,7 @@ run_cmake(DownloadTwice) run_cmake(DownloadFile) run_cmake(SameGenerator) run_cmake(VarDefinitions) +run_cmake(VarPassthroughs) run_cmake(GetProperties) run_cmake(UsesTerminalOverride) run_cmake(MakeAvailable) diff --git a/Tests/RunCMake/FetchContent/VarPassthroughs.cmake b/Tests/RunCMake/FetchContent/VarPassthroughs.cmake new file mode 100644 index 0000000..ad743d8 --- /dev/null +++ b/Tests/RunCMake/FetchContent/VarPassthroughs.cmake @@ -0,0 +1,38 @@ +include(FetchContent) + +set(CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY AAAA) +set(CMAKE_TLS_VERIFY BBBB) +set(CMAKE_TLS_CAINFO CCCC) +set(CMAKE_NETRC DDDD) +set(CMAKE_NETRC_FILE EEEE) + +FetchContent_Declare(PassThrough + DOWNLOAD_COMMAND ${CMAKE_COMMAND} -E echo "Download command executed" +) +FetchContent_Populate(PassThrough) + +set(gen_file ${FETCHCONTENT_BASE_DIR}/passthrough-subbuild/CMakeLists.txt) +if(NOT EXISTS ${gen_file}) + message(FATAL_ERROR "File does not exist: ${gen_file}") +endif() +file(READ ${gen_file} contents) + +if(NOT contents MATCHES "CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY \\[==\\[AAAA\\]==\\]") + message(FATAL_ERROR "Missing CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY") +endif() + +if(NOT contents MATCHES "CMAKE_TLS_VERIFY \\[==\\[BBBB\\]==\\]") + message(FATAL_ERROR "Missing CMAKE_TLS_VERIFY") +endif() + +if(NOT contents MATCHES "CMAKE_TLS_CAINFO \\[==\\[CCCC\\]==\\]") + message(FATAL_ERROR "Missing CMAKE_TLS_CAINFO") +endif() + +if(NOT contents MATCHES "CMAKE_NETRC \\[==\\[DDDD\\]==\\]") + message(FATAL_ERROR "Missing CMAKE_NETRC") +endif() + +if(NOT contents MATCHES "CMAKE_NETRC_FILE \\[==\\[EEEE\\]==\\]") + message(FATAL_ERROR "Missing CMAKE_NETRC_FILE") +endif() -- cgit v0.12