diff --git a/docs/packages/rapids_cpm_versions.rst b/docs/packages/rapids_cpm_versions.rst index e73d5e72..5f29221f 100644 --- a/docs/packages/rapids_cpm_versions.rst +++ b/docs/packages/rapids_cpm_versions.rst @@ -126,6 +126,8 @@ as needed. Supports the following placeholders: - ``${rapids-cmake-version}`` will be evaluated to 'major.minor' of the current rapids-cmake cal-ver value. - ``${version}`` will be evaluated to the contents of the ``version`` field. + - ``${cuda-toolkit-version}`` will be evaluated to 'major.minor' of the current CUDA Toolkit version. + - ``${cuda-toolkit-version-major}`` will be evaluated to 'major' of the current CUDA Toolkit version. If this field exists in the default package, the value will be ignored when an override file entry exists for the package. This ensures that the git url or `proprietary_binary` entry in the override will be used. diff --git a/rapids-cmake/cpm/detail/download_proprietary_binary.cmake b/rapids-cmake/cpm/detail/download_proprietary_binary.cmake new file mode 100644 index 00000000..f30f1561 --- /dev/null +++ b/rapids-cmake/cpm/detail/download_proprietary_binary.cmake @@ -0,0 +1,46 @@ +#============================================================================= +# Copyright (c) 2022-2023, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +include_guard(GLOBAL) + +#[=======================================================================[.rst: +download_proprietary_binary +------------------- + +.. versionadded:: v23.04.00 + +Download the associated proprietary binary from the providied URL and make +it part of the project with `FetchContent_MakeAvailable` + +#]=======================================================================] +function(rapids_cpm_download_proprietary_binary package_name url) + list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.rapids_cpm_download_proprietary_binary") + + # download and extract the binaries since they don't exist on the machine + include(FetchContent) + set(pkg_name "${package_name}_proprietary_binary") + + if(POLICY CMP0135) + cmake_policy(SET CMP0135 NEW) + set(CMAKE_POLICY_DEFAULT_CMP0135 NEW) + endif() + + FetchContent_Declare(${pkg_name} URL ${url}) + FetchContent_MakeAvailable(${pkg_name}) + + # Tell the subsequent rapids_cpm_find where to search so that it uses this binary + set(${package_name}_ROOT "${${pkg_name}_SOURCE_DIR}" PARENT_SCOPE) + set(${package_name}_proprietary_binary ON PARENT_SCOPE) +endfunction() diff --git a/rapids-cmake/cpm/detail/get_proprietary_binary.cmake b/rapids-cmake/cpm/detail/get_proprietary_binary_url.cmake similarity index 62% rename from rapids-cmake/cpm/detail/get_proprietary_binary.cmake rename to rapids-cmake/cpm/detail/get_proprietary_binary_url.cmake index 195eda5e..c922322c 100644 --- a/rapids-cmake/cpm/detail/get_proprietary_binary.cmake +++ b/rapids-cmake/cpm/detail/get_proprietary_binary_url.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2022, NVIDIA CORPORATION. +# Copyright (c) 2022-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,22 +16,21 @@ include_guard(GLOBAL) #[=======================================================================[.rst: -get_proprietary_binary +rapids_cpm_get_proprietary_binary_url ------------------- -.. versionadded:: v22.06.00 +.. versionadded:: v23.04.00 -Download the associated proprietary binary for the given project based on -the current CPU target architecture ( x86_64, aarch64, etc ) +Generated the url for the associated proprietary binary for the given project based +on the current CPU target architecture ( x86_64, aarch64, etc ) .. note:: if override => the proprietary entry only in the override will be evaluated if no override => the proprietary entry only in the default will be evaluated - #]=======================================================================] -function(rapids_cpm_get_proprietary_binary package_name version) - list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.rapids_cpm_get_proprietary_binary") +function(rapids_cpm_get_proprietary_binary_url package_name version url_var) + list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.rapids_cpm_get_proprietary_binary_url") include("${rapids-cmake-dir}/cpm/detail/get_default_json.cmake") include("${rapids-cmake-dir}/cpm/detail/get_override_json.cmake") @@ -61,25 +60,28 @@ function(rapids_cpm_get_proprietary_binary package_name version) include("${rapids-cmake-dir}/rapids-version.cmake") endif() + # Determine the CUDA Toolkit version so that we properly evaluate the placeholders in + # `proprietary_binary` + if(proprietary_binary MATCHES "{cuda-toolkit-version") + if(CUDAToolkit_VERSION_MAJOR) + set(cuda-toolkit-version ${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}) + set(cuda-toolkit-version-major ${CUDAToolkit_VERSION_MAJOR}) + elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" AND CMAKE_CUDA_COMPILER_VERSION MATCHES + [=[([0-9]+)\.([0-9]+)\.([0-9]+)]=]) + # Use if(MATCHES) so we get the MATCH_`N` variables. Use same regex as used by FindCUDAToolkit + set(cuda-toolkit-version-major "${CMAKE_MATCH_1}") + set(cuda-toolkit-version "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}") + else() + find_package(CUDAToolkit REQUIRED) + set(cuda-toolkit-version ${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}) + set(cuda-toolkit-version-major ${CUDAToolkit_VERSION_MAJOR}) + endif() + endif() + # Evaluate any magic placeholders in the proprietary_binary value including the # `rapids-cmake-version` value cmake_language(EVAL CODE "set(proprietary_binary ${proprietary_binary})") - if(proprietary_binary) - # download and extract the binaries since they don't exist on the machine - include(FetchContent) - set(pkg_name "${package_name}_proprietary_binary") - - if(POLICY CMP0135) - cmake_policy(SET CMP0135 NEW) - set(CMAKE_POLICY_DEFAULT_CMP0135 NEW) - endif() - - FetchContent_Declare(${pkg_name} URL ${proprietary_binary}) - FetchContent_MakeAvailable(${pkg_name}) - - # Tell the subsequent rapids_cpm_find where to search so that it uses this binary - set(${package_name}_ROOT "${${pkg_name}_SOURCE_DIR}" PARENT_SCOPE) - set(${package_name}_proprietary_binary ON PARENT_SCOPE) - endif() + # Tell the caller what the URL will be for this binary + set(${url_var} "${proprietary_binary}" PARENT_SCOPE) endfunction() diff --git a/rapids-cmake/cpm/nvcomp.cmake b/rapids-cmake/cpm/nvcomp.cmake index 7c34675d..60594250 100644 --- a/rapids-cmake/cpm/nvcomp.cmake +++ b/rapids-cmake/cpm/nvcomp.cmake @@ -90,8 +90,12 @@ function(rapids_cpm_nvcomp) # first see if we have a proprietary pre-built binary listed in versions.json and it if requested. set(nvcomp_proprietary_binary OFF) # will be set to true by rapids_cpm_get_proprietary_binary if(_RAPIDS_USE_PROPRIETARY_BINARY) - include("${rapids-cmake-dir}/cpm/detail/get_proprietary_binary.cmake") - rapids_cpm_get_proprietary_binary(nvcomp ${version}) + include("${rapids-cmake-dir}/cpm/detail/get_proprietary_binary_url.cmake") + include("${rapids-cmake-dir}/cpm/detail/download_proprietary_binary.cmake") + rapids_cpm_get_proprietary_binary_url(nvcomp ${version} nvcomp_url) + if(nvcomp_url) + rapids_cpm_download_proprietary_binary(nvcomp ${nvcomp_url}) + endif() # Record the nvcomp_DIR so that if USE_PROPRIETARY_BINARY is disabled we can safely clear the # nvcomp_DIR value diff --git a/testing/cpm/CMakeLists.txt b/testing/cpm/CMakeLists.txt index 7eebf575..7e44e0c3 100644 --- a/testing/cpm/CMakeLists.txt +++ b/testing/cpm/CMakeLists.txt @@ -71,6 +71,10 @@ add_cmake_config_test( cpm_nvcomp-simple.cmake ) add_cmake_config_test( cpm_nvcomp-invalid-arch.cmake ) add_cmake_config_test( cpm_nvcomp-override-clears-proprietary_binary.cmake ) +add_cmake_config_test( cpm_proprietary-url-ctk-version-find-ctk.cmake ) +add_cmake_config_test( cpm_proprietary-url-ctk-version-from-cuda-lang.cmake ) +add_cmake_config_test( cpm_proprietary-url-ctk-version.cmake ) + add_cmake_config_test( cpm_rmm-export.cmake ) add_cmake_config_test( cpm_rmm-simple.cmake ) diff --git a/testing/cpm/cpm_proprietary-url-ctk-version-find-ctk.cmake b/testing/cpm/cpm_proprietary-url-ctk-version-find-ctk.cmake new file mode 100644 index 00000000..6ca4c0e0 --- /dev/null +++ b/testing/cpm/cpm_proprietary-url-ctk-version-find-ctk.cmake @@ -0,0 +1,50 @@ +#============================================================================= +# Copyright (c) 2021-2023, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +include(${rapids-cmake-dir}/cpm/init.cmake) +include(${rapids-cmake-dir}/cpm/package_override.cmake) +include(${rapids-cmake-dir}/cpm/detail/get_proprietary_binary_url.cmake) +include(${rapids-cmake-dir}/cpm/detail/package_details.cmake) + +rapids_cpm_init() + +# Need to write out an override file with a proprietary blob url +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json + [=[ +{ + "packages" : { + "test_binary" : { + "version" : "2.6.1", + "proprietary_binary" : { + "x86_64-linux" : "https://fake.url.com/${version}/${cuda-toolkit-version}/x86_64_${cuda-toolkit-version-major}.tgz", + "aarch64-linux" : "https://fake.url.com/${version}/${cuda-toolkit-version}/aarch64_${cuda-toolkit-version-major}.tgz", + } + } + } +} +]=]) +rapids_cpm_package_override(${CMAKE_CURRENT_BINARY_DIR}/override.json) + +# Verify that the place-holders are evaluated correctly from `enable_language(CUDA)` +rapids_cpm_package_details(test_binary version repository tag shallow exclude) +rapids_cpm_get_proprietary_binary_url(test_binary ${version} url) + +find_package(CUDAToolkit) +set(CTK_VER ${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}) +set(CTK_VER_M ${CUDAToolkit_VERSION_MAJOR}) +set(valid_url "https://fake.url.com/2.6.1/${CTK_VER}/${CMAKE_SYSTEM_PROCESSOR}_${CTK_VER_M}.tgz") +if(NOT valid_url STREQUAL url) + message(FATAL_ERROR "Expected: ${valid_url} got: ${url}") +endif() diff --git a/testing/cpm/cpm_proprietary-url-ctk-version-from-cuda-lang.cmake b/testing/cpm/cpm_proprietary-url-ctk-version-from-cuda-lang.cmake new file mode 100644 index 00000000..91e9a3e8 --- /dev/null +++ b/testing/cpm/cpm_proprietary-url-ctk-version-from-cuda-lang.cmake @@ -0,0 +1,51 @@ +#============================================================================= +# Copyright (c) 2021-2023, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +include(${rapids-cmake-dir}/cpm/init.cmake) +include(${rapids-cmake-dir}/cpm/package_override.cmake) +include(${rapids-cmake-dir}/cpm/detail/get_proprietary_binary_url.cmake) +include(${rapids-cmake-dir}/cpm/detail/package_details.cmake) + +rapids_cpm_init() + +# Need to write out an override file with a proprietary blob url +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json + [=[ +{ + "packages" : { + "test_binary" : { + "version" : "2.6.1", + "proprietary_binary" : { + "x86_64-linux" : "https://fake.url.com/${version}/${cuda-toolkit-version}/x86_64_${cuda-toolkit-version-major}.tgz", + "aarch64-linux" : "https://fake.url.com/${version}/${cuda-toolkit-version}/aarch64_${cuda-toolkit-version-major}.tgz", + } + } + } +} +]=]) +rapids_cpm_package_override(${CMAKE_CURRENT_BINARY_DIR}/override.json) + +# Verify that the place-holders are evaluated correctly from `enable_language(CUDA)` +enable_language(CUDA) +rapids_cpm_package_details(test_binary version repository tag shallow exclude) +rapids_cpm_get_proprietary_binary_url(test_binary ${version} url) + +find_package(CUDAToolkit) +set(CTK_VER ${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}) +set(CTK_VER_M ${CUDAToolkit_VERSION_MAJOR}) +set(valid_url "https://fake.url.com/2.6.1/${CTK_VER}/${CMAKE_SYSTEM_PROCESSOR}_${CTK_VER_M}.tgz") +if(NOT valid_url STREQUAL url) + message(FATAL_ERROR "Expected: ${valid_url} got: ${url}") +endif() diff --git a/testing/cpm/cpm_proprietary-url-ctk-version.cmake b/testing/cpm/cpm_proprietary-url-ctk-version.cmake new file mode 100644 index 00000000..04d98471 --- /dev/null +++ b/testing/cpm/cpm_proprietary-url-ctk-version.cmake @@ -0,0 +1,51 @@ +#============================================================================= +# Copyright (c) 2021-2023, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +include(${rapids-cmake-dir}/cpm/init.cmake) +include(${rapids-cmake-dir}/cpm/package_override.cmake) +include(${rapids-cmake-dir}/cpm/detail/get_proprietary_binary_url.cmake) +include(${rapids-cmake-dir}/cpm/detail/package_details.cmake) + +rapids_cpm_init() + +# Need to write out an override file with a proprietary blob url +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json + [=[ +{ + "packages" : { + "test_binary" : { + "version" : "2.6.1", + "proprietary_binary" : { + "x86_64-linux" : "https://fake.url.com/${version}/${cuda-toolkit-version}/x86_64_${cuda-toolkit-version-major}.tgz", + "aarch64-linux" : "https://fake.url.com/${version}/${cuda-toolkit-version}/aarch64_${cuda-toolkit-version-major}.tgz", + } + } + } +} +]=]) +rapids_cpm_package_override(${CMAKE_CURRENT_BINARY_DIR}/override.json) + +# Verify that the place-holders are evaluated correctly from `find_package(CUDAToolkit)` +find_package(CUDAToolkit REQUIRED) +rapids_cpm_package_details(test_binary version repository tag shallow exclude) +rapids_cpm_get_proprietary_binary_url(test_binary ${version} url) + +find_package(CUDAToolkit) +set(CTK_VER ${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}) +set(CTK_VER_M ${CUDAToolkit_VERSION_MAJOR}) +set(valid_url "https://fake.url.com/2.6.1/${CTK_VER}/${CMAKE_SYSTEM_PROCESSOR}_${CTK_VER_M}.tgz") +if(NOT valid_url STREQUAL url) + message(FATAL_ERROR "Expected: ${valid_url} got: ${url}") +endif() diff --git a/testing/cpm/cpm_proprietary-url-no-ctk-parsing.cmake b/testing/cpm/cpm_proprietary-url-no-ctk-parsing.cmake new file mode 100644 index 00000000..faf9b897 --- /dev/null +++ b/testing/cpm/cpm_proprietary-url-no-ctk-parsing.cmake @@ -0,0 +1,46 @@ +#============================================================================= +# Copyright (c) 2021-2023, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +include(${rapids-cmake-dir}/cpm/init.cmake) +include(${rapids-cmake-dir}/cpm/package_override.cmake) +include(${rapids-cmake-dir}/cpm/detail/get_proprietary_binary_url.cmake) +include(${rapids-cmake-dir}/cpm/detail/package_details.cmake) + +rapids_cpm_init() + +# Need to write out an override file with a proprietary blob url +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/override.json + [=[ +{ + "packages" : { + "test_binary" : { + "version" : "2.6.1", + "proprietary_binary" : { + "x86_64-linux" : "https://fake.url.com/x86_${version}.tgz", + "aarch64-linux" : "https://fake.url.com/aarch_${version}.tgz", + } + } + } +} +]=]) +rapids_cpm_package_override(${CMAKE_CURRENT_BINARY_DIR}/override.json) + +rapids_cpm_package_details(test_binary version repository tag shallow exclude) +rapids_cpm_get_proprietary_binary_url(test_binary ${version} nvcomp_url) + +# Verify that we didn't go searching for the CUDAToolkit +if(TARGET CUDA::cudart_static OR TARGET CUDA::cudart) + message(FATAL_ERROR "test_binary didn't use the cuda toolkit placeholder, but searching for it still occurred") +endif() diff --git a/testing/utils/project_template.cmake.in b/testing/utils/project_template.cmake.in index 83a49dce..7e33b42b 100644 --- a/testing/utils/project_template.cmake.in +++ b/testing/utils/project_template.cmake.in @@ -49,5 +49,5 @@ add_subdirectory(${rapids-cmake_SOURCE_DIR} ${rapids-cmake_BINARY_DIR}) # We need to enable at least one language so that we get properly # generated system search paths. -project(@test_name@ LANGUAGES CXX) +project(@test_name_stem@ LANGUAGES CXX) include("@test_cmake_file@")