From 2c146a7fc5499669ea0aa8bf37fd4ef5c1c517e4 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 9 Mar 2023 07:39:36 -0500 Subject: FindCUDA: Add policy to remove this module The `FindCUDA` module has been deprecated since CMake 3.10. Add a policy to pretend it doesn't exist in order to encourage projects to port away from it. --- Help/manual/cmake-policies.7.rst | 1 + Help/policy/CMP0146.rst | 29 ++++++++++++++++++++++ Help/release/dev/FindCUDA-remove.rst | 6 +++++ Modules/FindCUDA.cmake | 17 ++++++++++++- Source/cmFindPackageCommand.cxx | 1 + Source/cmIncludeCommand.cxx | 1 + Source/cmPolicies.h | 4 ++- Tests/RunCMake/find_package/CMP0146-NEW-stderr.txt | 4 +++ Tests/RunCMake/find_package/CMP0146-NEW.cmake | 7 ++++++ Tests/RunCMake/find_package/CMP0146-OLD.cmake | 7 ++++++ .../RunCMake/find_package/CMP0146-WARN-stderr.txt | 8 ++++++ Tests/RunCMake/find_package/CMP0146-WARN.cmake | 6 +++++ Tests/RunCMake/find_package/RunCMakeTest.cmake | 3 +++ Tests/RunCMake/include/CMP0146-NEW-name-result.txt | 1 + Tests/RunCMake/include/CMP0146-NEW-name-stderr.txt | 6 +++++ Tests/RunCMake/include/CMP0146-NEW-name.cmake | 2 ++ Tests/RunCMake/include/CMP0146-NEW-path-result.txt | 1 + Tests/RunCMake/include/CMP0146-NEW-path-stderr.txt | 6 +++++ Tests/RunCMake/include/CMP0146-NEW-path.cmake | 2 ++ Tests/RunCMake/include/CMP0146-OLD.cmake | 7 ++++++ Tests/RunCMake/include/CMP0146-WARN-stderr.txt | 8 ++++++ Tests/RunCMake/include/CMP0146-WARN.cmake | 7 ++++++ Tests/RunCMake/include/RunCMakeTest.cmake | 5 ++++ 23 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 Help/policy/CMP0146.rst create mode 100644 Help/release/dev/FindCUDA-remove.rst create mode 100644 Tests/RunCMake/find_package/CMP0146-NEW-stderr.txt create mode 100644 Tests/RunCMake/find_package/CMP0146-NEW.cmake create mode 100644 Tests/RunCMake/find_package/CMP0146-OLD.cmake create mode 100644 Tests/RunCMake/find_package/CMP0146-WARN-stderr.txt create mode 100644 Tests/RunCMake/find_package/CMP0146-WARN.cmake create mode 100644 Tests/RunCMake/include/CMP0146-NEW-name-result.txt create mode 100644 Tests/RunCMake/include/CMP0146-NEW-name-stderr.txt create mode 100644 Tests/RunCMake/include/CMP0146-NEW-name.cmake create mode 100644 Tests/RunCMake/include/CMP0146-NEW-path-result.txt create mode 100644 Tests/RunCMake/include/CMP0146-NEW-path-stderr.txt create mode 100644 Tests/RunCMake/include/CMP0146-NEW-path.cmake create mode 100644 Tests/RunCMake/include/CMP0146-OLD.cmake create mode 100644 Tests/RunCMake/include/CMP0146-WARN-stderr.txt create mode 100644 Tests/RunCMake/include/CMP0146-WARN.cmake diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst index 28272ad..811547b 100644 --- a/Help/manual/cmake-policies.7.rst +++ b/Help/manual/cmake-policies.7.rst @@ -57,6 +57,7 @@ Policies Introduced by CMake 3.27 .. toctree:: :maxdepth: 1 + CMP0146: The FindCUDA module is removed. CMP0145: The Dart and FindDart modules are removed. CMP0144: find_package uses upper-case PACKAGENAME_ROOT variables. diff --git a/Help/policy/CMP0146.rst b/Help/policy/CMP0146.rst new file mode 100644 index 0000000..c7cac22 --- /dev/null +++ b/Help/policy/CMP0146.rst @@ -0,0 +1,29 @@ +CMP0146 +------- + +.. versionadded:: 3.27 + +The :module:`FindCUDA` module is removed. + +The :module:`FindCUDA` module has been deprecated since CMake 3.10. +CMake 3.27 and above prefer to not provide the module. +This policy provides compatibility for projects that have not been +ported away from it. + +Projects using the :module:`FindCUDA` module should be updated to use +CMake's first-class ``CUDA`` language support. List ``CUDA`` among the +languages named in the top-level call to the :command:`project` command, +or call the :command:`enable_language` command with ``CUDA``. +Then one can add CUDA (``.cu``) sources directly to targets, +similar to other languages. + +The ``OLD`` behavior of this policy is for ``find_package(CUDA)`` to +load the deprecated module. The ``NEW`` behavior is for uses of the +module to fail as if it does not exist. + +This policy was introduced in CMake version 3.27. CMake version +|release| warns when the policy is not set and uses ``OLD`` behavior. +Use the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` +explicitly. + +.. include:: DEPRECATED.txt diff --git a/Help/release/dev/FindCUDA-remove.rst b/Help/release/dev/FindCUDA-remove.rst new file mode 100644 index 0000000..e8b09d4 --- /dev/null +++ b/Help/release/dev/FindCUDA-remove.rst @@ -0,0 +1,6 @@ +FindCUDA-remove +--------------- + +* The :module:`FindCUDA` module has been fully deprecated via policy + :policy:`CMP0146`. Port projects to CMake's first-class ``CUDA`` + language support. diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake index c928157..c2ec82e 100644 --- a/Modules/FindCUDA.cmake +++ b/Modules/FindCUDA.cmake @@ -2,7 +2,12 @@ FindCUDA -------- -.. warning:: *Deprecated since version 3.10.* +.. versionchanged:: 3.27 + This module is available only if policy :policy:`CMP0146` is not set to ``NEW``. + Port projects to CMake's first-class ``CUDA`` language support. + +.. deprecated:: 3.10 + Do not use this module in new code. It is no longer necessary to use this module or call ``find_package(CUDA)`` for compiling CUDA code. Instead, list ``CUDA`` among the languages named @@ -555,6 +560,16 @@ The script defines the following variables: # ############################################################################### +cmake_policy(GET CMP0146 _FindCUDA_CMP0146) +if(_FindCUDA_CMP0146 STREQUAL "NEW") + message(FATAL_ERROR "The FindCUDA module has been removed by policy CMP0146.") +endif() + +if(_FindCUDA_testing) + set(_FindCUDA_included TRUE) + return() +endif() + # FindCUDA.cmake # This macro helps us find the location of helper files we will need the full path to diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 8acfe83..4024dff 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -502,6 +502,7 @@ cmFindPackageCommand::cmFindPackageCommand(cmExecutionStatus& status) this->DebugMode = false; this->AppendSearchPathGroups(); + this->DeprecatedFindModules["CUDA"] = cmPolicies::CMP0146; this->DeprecatedFindModules["Dart"] = cmPolicies::CMP0145; this->DeprecatedFindModules["Qt"] = cmPolicies::CMP0084; } diff --git a/Source/cmIncludeCommand.cxx b/Source/cmIncludeCommand.cxx index 3564cf7..56883fb 100644 --- a/Source/cmIncludeCommand.cxx +++ b/Source/cmIncludeCommand.cxx @@ -22,6 +22,7 @@ bool cmIncludeCommand(std::vector const& args, if (DeprecatedModules.empty()) { DeprecatedModules["Dart"] = cmPolicies::CMP0145; DeprecatedModules["Documentation"] = cmPolicies::CMP0106; + DeprecatedModules["FindCUDA"] = cmPolicies::CMP0146; DeprecatedModules["FindDart"] = cmPolicies::CMP0145; DeprecatedModules["WriteCompilerDetectionHeader"] = cmPolicies::CMP0120; } diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 830e14b..06ac21e 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -439,7 +439,9 @@ class cmMakefile; "find_package uses upper-case _ROOT variables.", 3, 27, \ 0, cmPolicies::WARN) \ SELECT(POLICY, CMP0145, "The Dart and FindDart modules are removed.", 3, \ - 27, 0, cmPolicies::WARN) + 27, 0, cmPolicies::WARN) \ + SELECT(POLICY, CMP0146, "The FindCUDA module is removed.", 3, 27, 0, \ + cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) #define CM_FOR_EACH_POLICY_ID(POLICY) \ diff --git a/Tests/RunCMake/find_package/CMP0146-NEW-stderr.txt b/Tests/RunCMake/find_package/CMP0146-NEW-stderr.txt new file mode 100644 index 0000000..0162852 --- /dev/null +++ b/Tests/RunCMake/find_package/CMP0146-NEW-stderr.txt @@ -0,0 +1,4 @@ +^CMake Warning at CMP0146-NEW\.cmake:[0-9]+ \(find_package\): + No "FindCUDA\.cmake" found in CMAKE_MODULE_PATH\. +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/find_package/CMP0146-NEW.cmake b/Tests/RunCMake/find_package/CMP0146-NEW.cmake new file mode 100644 index 0000000..b373227 --- /dev/null +++ b/Tests/RunCMake/find_package/CMP0146-NEW.cmake @@ -0,0 +1,7 @@ +cmake_policy(SET CMP0146 NEW) +set(_FindCUDA_testing TRUE) +find_package(CUDA MODULE) + +if(_FindCUDA_included) + message(FATAL_ERROR "FindCUDA.cmake erroneously included") +endif() diff --git a/Tests/RunCMake/find_package/CMP0146-OLD.cmake b/Tests/RunCMake/find_package/CMP0146-OLD.cmake new file mode 100644 index 0000000..77cd1f5 --- /dev/null +++ b/Tests/RunCMake/find_package/CMP0146-OLD.cmake @@ -0,0 +1,7 @@ +cmake_policy(SET CMP0146 OLD) +set(_FindCUDA_testing TRUE) +find_package(CUDA MODULE) + +if(NOT _FindCUDA_included) + message(FATAL_ERROR "FindCUDA.cmake not included") +endif() diff --git a/Tests/RunCMake/find_package/CMP0146-WARN-stderr.txt b/Tests/RunCMake/find_package/CMP0146-WARN-stderr.txt new file mode 100644 index 0000000..2cd9c5f --- /dev/null +++ b/Tests/RunCMake/find_package/CMP0146-WARN-stderr.txt @@ -0,0 +1,8 @@ +CMake Warning \(dev\) at CMP0146-WARN\.cmake:[0-9]+ \(find_package\): + Policy CMP0146 is not set: The FindCUDA module is removed\. Run "cmake + --help-policy CMP0146" for policy details\. Use the cmake_policy command to + set the policy and suppress this warning\. + +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) +This warning is for project developers\. Use -Wno-dev to suppress it\.$ diff --git a/Tests/RunCMake/find_package/CMP0146-WARN.cmake b/Tests/RunCMake/find_package/CMP0146-WARN.cmake new file mode 100644 index 0000000..276daf2 --- /dev/null +++ b/Tests/RunCMake/find_package/CMP0146-WARN.cmake @@ -0,0 +1,6 @@ +set(_FindCUDA_testing TRUE) +find_package(CUDA MODULE) + +if(NOT _FindCUDA_included) + message(FATAL_ERROR "FindCUDA.cmake not included") +endif() diff --git a/Tests/RunCMake/find_package/RunCMakeTest.cmake b/Tests/RunCMake/find_package/RunCMakeTest.cmake index f0bb011..924aa66 100644 --- a/Tests/RunCMake/find_package/RunCMakeTest.cmake +++ b/Tests/RunCMake/find_package/RunCMakeTest.cmake @@ -39,6 +39,9 @@ run_cmake(CMP0084-NEW) run_cmake(CMP0145-OLD) run_cmake(CMP0145-WARN) run_cmake(CMP0145-NEW) +run_cmake(CMP0146-OLD) +run_cmake(CMP0146-WARN) +run_cmake(CMP0146-NEW) run_cmake(WrongVersionRange) run_cmake(EmptyVersionRange) run_cmake(VersionRangeWithEXACT) diff --git a/Tests/RunCMake/include/CMP0146-NEW-name-result.txt b/Tests/RunCMake/include/CMP0146-NEW-name-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/include/CMP0146-NEW-name-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/include/CMP0146-NEW-name-stderr.txt b/Tests/RunCMake/include/CMP0146-NEW-name-stderr.txt new file mode 100644 index 0000000..7d9e7d8 --- /dev/null +++ b/Tests/RunCMake/include/CMP0146-NEW-name-stderr.txt @@ -0,0 +1,6 @@ +^CMake Error at CMP0146-NEW-name\.cmake:[0-9]+ \(include\): + include could not find requested file: + + FindCUDA +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/include/CMP0146-NEW-name.cmake b/Tests/RunCMake/include/CMP0146-NEW-name.cmake new file mode 100644 index 0000000..feedc6f --- /dev/null +++ b/Tests/RunCMake/include/CMP0146-NEW-name.cmake @@ -0,0 +1,2 @@ +cmake_policy(SET CMP0146 NEW) +include(FindCUDA) diff --git a/Tests/RunCMake/include/CMP0146-NEW-path-result.txt b/Tests/RunCMake/include/CMP0146-NEW-path-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/include/CMP0146-NEW-path-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/include/CMP0146-NEW-path-stderr.txt b/Tests/RunCMake/include/CMP0146-NEW-path-stderr.txt new file mode 100644 index 0000000..916672b --- /dev/null +++ b/Tests/RunCMake/include/CMP0146-NEW-path-stderr.txt @@ -0,0 +1,6 @@ +^CMake Error at [^ +]*/Modules/FindCUDA.cmake:[0-9]+ \(message\): + The FindCUDA module has been removed by policy CMP0146\. +Call Stack \(most recent call first\): + CMP0146-NEW-path\.cmake:[0-9]+ \(include\) + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/include/CMP0146-NEW-path.cmake b/Tests/RunCMake/include/CMP0146-NEW-path.cmake new file mode 100644 index 0000000..6768d4d --- /dev/null +++ b/Tests/RunCMake/include/CMP0146-NEW-path.cmake @@ -0,0 +1,2 @@ +cmake_policy(SET CMP0146 NEW) +include(${CMAKE_ROOT}/Modules/FindCUDA.cmake) diff --git a/Tests/RunCMake/include/CMP0146-OLD.cmake b/Tests/RunCMake/include/CMP0146-OLD.cmake new file mode 100644 index 0000000..654cdf7 --- /dev/null +++ b/Tests/RunCMake/include/CMP0146-OLD.cmake @@ -0,0 +1,7 @@ +cmake_policy(SET CMP0146 OLD) +set(_FindCUDA_testing 1) +include(FindCUDA) + +if(NOT _FindCUDA_included) + message(FATAL_ERROR "FindCUDA.cmake not included") +endif() diff --git a/Tests/RunCMake/include/CMP0146-WARN-stderr.txt b/Tests/RunCMake/include/CMP0146-WARN-stderr.txt new file mode 100644 index 0000000..aaaf1dc --- /dev/null +++ b/Tests/RunCMake/include/CMP0146-WARN-stderr.txt @@ -0,0 +1,8 @@ +^CMake Warning \(dev\) at CMP0146-WARN\.cmake:[0-9]+ \(include\): + Policy CMP0146 is not set: The FindCUDA module is removed\. Run "cmake + --help-policy CMP0146" for policy details\. Use the cmake_policy command to + set the policy and suppress this warning\. + +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) +This warning is for project developers\. Use -Wno-dev to suppress it\.$ diff --git a/Tests/RunCMake/include/CMP0146-WARN.cmake b/Tests/RunCMake/include/CMP0146-WARN.cmake new file mode 100644 index 0000000..bce1ae8 --- /dev/null +++ b/Tests/RunCMake/include/CMP0146-WARN.cmake @@ -0,0 +1,7 @@ +# Do not set CMP0146. +set(_FindCUDA_testing 1) +include(FindCUDA) + +if(NOT _FindCUDA_included) + message(FATAL_ERROR "FindCUDA.cmake not included") +endif() diff --git a/Tests/RunCMake/include/RunCMakeTest.cmake b/Tests/RunCMake/include/RunCMakeTest.cmake index 8fb7201..b6fdb54 100644 --- a/Tests/RunCMake/include/RunCMakeTest.cmake +++ b/Tests/RunCMake/include/RunCMakeTest.cmake @@ -7,3 +7,8 @@ run_cmake(CMP0024-NEW) run_cmake(ExportExportInclude) run_cmake(IncludeIsDirectory) run_cmake(IncludeMalformed) + +run_cmake(CMP0146-OLD) +run_cmake(CMP0146-WARN) +run_cmake(CMP0146-NEW-name) +run_cmake(CMP0146-NEW-path) -- cgit v0.12