Skip to content

Commit

Permalink
Remove rapids_export_write_dependencies generated rapids-cmake depend…
Browse files Browse the repository at this point in the history
…ency

The generated output file from rapids_export_write_dependencies can't
depend on rapid-cmake being reachable. This behavior has been restored
by refactoring out the cpm download logic to `cpm/detail/download.cmake'
  • Loading branch information
robertmaynard committed Aug 13, 2021
1 parent 5ccc8f4 commit 8c37d6a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 23 deletions.
65 changes: 65 additions & 0 deletions rapids-cmake/cpm/detail/download.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#=============================================================================
# Copyright (c) 2018-2021, 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:
rapids_cpm_download
-------------------

.. versionadded:: v21.10.00

Does the downloading of the `CPM` module

.. code-block:: cmake

rapids_cpm_download()

The CPM module will be downloaded based on the state of :cmake:variable:`CPM_SOURCE_CACHE` and
:cmake:variable:`ENV{CPM_SOURCE_CACHE}`.

.. note::
Use `rapids_cpm_init` instead of this function, as this is an implementation detail
required for proper cpm project exporting in build directories

This function can't call other rapids-cmake functions, due to the
restrictions of `write_dependencies.cmake`

#]=======================================================================]
function(rapids_cpm_download)
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.download")

set(CPM_DOWNLOAD_VERSION 7644c3a40fc7889f8dee53ce21e85dc390b883dc) # 0.32.1

if(CPM_SOURCE_CACHE)
# Expand relative path. This is important if the provided path contains a tilde (~)
cmake_path(ABSOLUTE_PATH CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(VERBOSE "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://raw.githubusercontent.com/cpm-cmake/CPM.cmake/${CPM_DOWNLOAD_VERSION}/cmake/CPM.cmake
${CPM_DOWNLOAD_LOCATION})
endif()

include(${CPM_DOWNLOAD_LOCATION})

endfunction()
24 changes: 3 additions & 21 deletions rapids-cmake/cpm/init.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ include_guard(GLOBAL)

#[=======================================================================[.rst:
rapids_cpm_init
-------------------
---------------

.. versionadded:: v21.06.00

Expand All @@ -42,25 +42,7 @@ function(rapids_cpm_init)
include("${rapids-cmake-dir}/cpm/detail/load_preset_versions.cmake")
rapids_cpm_load_preset_versions()

set(CPM_DOWNLOAD_VERSION 7644c3a40fc7889f8dee53ce21e85dc390b883dc) # 0.32.1

if(CPM_SOURCE_CACHE)
# Expand relative path. This is important if the provided path contains a tilde (~)
cmake_path(ABSOLUTE_PATH CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(VERBOSE "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://raw.githubusercontent.com/cpm-cmake/CPM.cmake/${CPM_DOWNLOAD_VERSION}/cmake/CPM.cmake
${CPM_DOWNLOAD_LOCATION})
endif()

include(${CPM_DOWNLOAD_LOCATION})
include("${rapids-cmake-dir}/cpm/detail/download.cmake")
rapids_cpm_download()

endfunction()
4 changes: 2 additions & 2 deletions rapids-cmake/export/write_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ function(rapids_export_write_dependencies type export_set file_path)
# Do we need a Template header?
set(RAPIDS_EXPORT_CONTENTS)
if(uses_cpm)
file(READ "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../cpm/init.cmake" cpm_logic)
file(READ "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../cpm/detail/download.cmake" cpm_logic)
string(APPEND RAPIDS_EXPORT_CONTENTS ${cpm_logic})
string(APPEND RAPIDS_EXPORT_CONTENTS "rapids_cpm_init()\n\n")
string(APPEND RAPIDS_EXPORT_CONTENTS "rapids_cpm_download()\n\n")

if(type STREQUAL build)
string(APPEND
Expand Down

0 comments on commit 8c37d6a

Please sign in to comment.