Skip to content

Commit

Permalink
Introduce RAPIDS.cmake a new way to fetch rapids-cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmaynard committed Jul 20, 2021
1 parent 619b270 commit 7d70891
Show file tree
Hide file tree
Showing 20 changed files with 292 additions and 36 deletions.
11 changes: 6 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@
# limitations under the License.
#=============================================================================
#
# This is an entry point for all projects using rapids-cmake.
# This is the legacy entry point for projects using rapids-cmake.
#
# This will setup the following variables in the parent directory
# - CMAKE_MODULE_PATH
# - rapids-cmake-dir
#
# It will also
# This is done to make sure that rapids-cmake can be properly included
# multiple times by sibling projects without issue
#
# This is considered legacy as it has issues when multiple projects
# use rapids-cmake via CPM inside the same global project. In those
# cases it can fail due to CMAKE_MODULE_PREFIX not being exported properly

# Enfore the minimum required CMake version for all users
cmake_minimum_required(VERSION 3.20.1 FATAL_ERROR)

set(rapids-cmake-version 21.10)

set(rapids-cmake-dir "${CMAKE_CURRENT_LIST_DIR}/rapids-cmake")
if(NOT DEFINED CACHE{rapids-cmake-dir})
set(rapids-cmake-dir "${rapids-cmake-dir}" CACHE INTERNAL "" FORCE)
Expand Down
38 changes: 38 additions & 0 deletions RAPIDS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#=============================================================================
# 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.
#=============================================================================
#
# This is the preferred entry point for projects using rapids-cmake
#

set(rapids-cmake-version 21.10)

include(FetchContent)
FetchContent_Declare(
rapids-cmake
GIT_REPOSITORY https://github.com/rapidsai/rapids-cmake.git
GIT_TAG branch-${rapids-cmake-version}
)
FetchContent_GetProperties(rapids-cmake)
if(rapids-cmake_POPULATED)
# Something else has already populated rapids-cmake, only thing
# we need to do is setup the CMAKE_MODULE_PATH
if(NOT "${rapids-cmake-dir}" IN_LIST CMAKE_MODULE_PATH)
list(APPEND CMAKE_MODULE_PATH "${rapids-cmake-dir}")
endif()
else()
FetchContent_MakeAvailable(rapids-cmake)
endif()

12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ Content](https://cmake.org/cmake/help/latest/module/FetchContent.html) into your
cmake_minimum_required(...)
include(FetchContent)
FetchContent_Declare(
rapids-cmake
GIT_REPOSITORY https://github.com/rapidsai/rapids-cmake.git
GIT_TAG branch-<VERSION_MAJOR>.<VERSION_MINOR>
)
FetchContent_MakeAvailable(rapids-cmake)
file(
DOWNLOAD
https://github.com/rapidsai/rapids-cmake/blob/branch-<VERSION_MAJOR>.<VERSION_MINOR>/RAPIDS.cmake
${CMAKE_BINARY_DIR})
include(${CMAKE_BINARY_DIR}/RAPIDS.cmake)
include(rapids-cmake)
include(rapids-cpm)
include(rapids-cuda)
Expand Down
3 changes: 2 additions & 1 deletion ci/release/update-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ function sed_runner() {
sed -i.bak ''"$1"'' $2 && rm -f ${2}.bak
}

sed_runner 's/'" VERSION .*"'/'" VERSION ${NEXT_FULL_TAG}"'/g' CMakeLists.txt
sed_runner 's/'" rapids-cmake-version .*"'/'" rapids-cmake-version ${NEXT_FULL_TAG}"'/g' CMakeLists.txt
sed_runner 's/'" rapids-cmake-version .*"'/'" rapids-cmake-version ${NEXT_FULL_TAG}"'/g' RAPIDS.cmake

sed_runner 's/version=.*/version=\"'"${NEXT_FULL_TAG}"'\",/g' python/setup.py

Expand Down
12 changes: 5 additions & 7 deletions docs/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ Content <https://cmake.org/cmake/help/latest/module/FetchContent.html>`_ into yo
cmake_minimum_required(...)
include(FetchContent)
FetchContent_Declare(
rapids-cmake
GIT_REPOSITORY https://github.com/rapidsai/rapids-cmake.git
GIT_TAG branch-<VERSION_MAJOR>.<VERSION_MINOR>
)
FetchContent_MakeAvailable(rapids-cmake)
file(
DOWNLOAD
https://github.com/rapidsai/rapids-cmake/blob/branch-<VERSION_MAJOR>.<VERSION_MINOR>/RAPIDS.cmake
${CMAKE_BINARY_DIR})
include(${CMAKE_BINARY_DIR}/RAPIDS.cmake)
include(rapids-cmake)
include(rapids-cpm)
include(rapids-cuda)
Expand Down
11 changes: 4 additions & 7 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@

cmake_minimum_required(VERSION 3.18 FATAL_ERROR)

include(FetchContent)
FetchContent_Declare(
rapids-cmake
GIT_REPOSITORY https://github.com/rapidsai/rapids-cmake.git
GIT_TAG origin/branch-21.06
)
FetchContent_MakeAvailable(rapids-cmake)
file(DOWNLOAD
https://github.com/rapidsai/rapids-cmake/blob/branch-21.10/RAPIDS.cmake
${CMAKE_BINARY_DIR})
include(${CMAKE_BINARY_DIR}/RAPIDS.cmake)
include(rapids-cmake)
include(rapids-cpm)
include(rapids-cuda)
Expand Down
12 changes: 5 additions & 7 deletions rapids-cmake/cuda/init_architectures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@ Example on how to properly use :cmake:command:`rapids_cuda_init_architectures`:

cmake_minimum_required(...)

include(FetchContent)
FetchContent_Declare(
rapids-cmake
GIT_REPOSITORY https://github.com/rapidsai/rapids-cmake.git
GIT_TAG branch-<VERSION_MAJOR>.<VERSION_MINOR>
)
FetchContent_MakeAvailable(rapids-cmake)
file(
DOWNLOAD
https://github.com/rapidsai/rapids-cmake/blob/branch-<VERSION_MAJOR>.<VERSION_MINOR>/RAPIDS.cmake
${CMAKE_BINARY_DIR})
include(${CMAKE_BINARY_DIR}/RAPIDS.cmake)
include(rapids-cuda)

rapids_cuda_init_architectures(ExampleProject)
Expand Down
6 changes: 4 additions & 2 deletions testing/other/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
add_cmake_config_test( rapids_cmake-multiple-cpm )
add_cmake_config_test( rapids_cmake-multiple-simple )

add_cmake_config_test( rapids_cmake-multiple-inclusions )
add_cmake_config_test( rapids_cmake-multiple-inclusions-base_dir )
add_cmake_config_test( FetchContent-legacy )
add_cmake_config_test( FetchContent-hostile-legacy )
41 changes: 41 additions & 0 deletions testing/other/rapids_cmake-multiple-cpm/A/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#=============================================================================
# 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.
#=============================================================================

# verify no rapids-cmake variables have been specified
if(DEFINED rapids-cmake_SOURCE_DIR)
message(FATAL_ERROR "")
endif()

include("${rapids.cmake-location}")

if(NOT DEFINED rapids-cmake_SOURCE_DIR)
message(FATAL_ERROR "expected variable rapids-cmake_SOURCE_DIR to exist")
endif()

if(NOT DEFINED rapids-cmake-dir)
message(FATAL_ERROR "expected variable rapids-cmake-dir to exist")
endif()

if(NOT "${rapids-cmake-dir}" IN_LIST CMAKE_MODULE_PATH)
message(FATAL_ERROR "expected variable rapids-cmake-dir to be inside CMAKE_MODULE_PATH")
endif()

if(NOT EXISTS "${rapids-cmake_SOURCE_DIR}/init.cmake")
message(FATAL_ERROR "expected init.cmake to exist")
endif()

# Be hostile against rapids-cmake
set(CMAKE_MODULE_PATH "/not/a/directory")
38 changes: 38 additions & 0 deletions testing/other/rapids_cmake-multiple-cpm/B/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#=============================================================================
# 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.
#=============================================================================

# verify no rapids-cmake variables have been specified
if(DEFINED rapids-cmake_SOURCE_DIR)
message(FATAL_ERROR "")
endif()

include("${rapids.cmake-location}")

if(NOT DEFINED rapids-cmake_SOURCE_DIR)
message(FATAL_ERROR "expected variable rapids-cmake_SOURCE_DIR to exist")
endif()

if(NOT DEFINED rapids-cmake-dir)
message(FATAL_ERROR "expected variable rapids-cmake-dir to exist")
endif()

if(NOT "${rapids-cmake-dir}" IN_LIST CMAKE_MODULE_PATH)
message(FATAL_ERROR "expected variable rapids-cmake-dir to be inside CMAKE_MODULE_PATH")
endif()

if(NOT EXISTS "${rapids-cmake_SOURCE_DIR}/init.cmake")
message(FATAL_ERROR "expected init.cmake to exist")
endif()
37 changes: 37 additions & 0 deletions testing/other/rapids_cmake-multiple-cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#=============================================================================
# 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.
#=============================================================================
cmake_minimum_required(VERSION 3.20)
project(rapids-test-project LANGUAGES CXX)

cmake_path(GET rapids-cmake-dir PARENT_PATH rapids.cmake-location)
cmake_path(APPEND rapids.cmake-location "RAPIDS.cmake")

# Remove this cache variable so we can properly test
# fetching rapids-cmake work as intended
unset(rapids-cmake-dir CACHE)

set(CMAKE_MODULE_PATH "/not/a/directory")

function(add_A )
add_subdirectory(A)
endfunction()

function(add_B )
add_subdirectory(B)
endfunction()

add_A()
add_B()
38 changes: 38 additions & 0 deletions testing/other/rapids_cmake-multiple-simple/A/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#=============================================================================
# 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.
#=============================================================================

# verify no rapids-cmake variables have been specified
if(DEFINED rapids-cmake_SOURCE_DIR)
message(FATAL_ERROR "")
endif()

include("${rapids.cmake-location}")

if(NOT DEFINED rapids-cmake_SOURCE_DIR)
message(FATAL_ERROR "expected variable rapids-cmake_SOURCE_DIR to exist")
endif()

if(NOT DEFINED rapids-cmake-dir)
message(FATAL_ERROR "expected variable rapids-cmake-dir to exist")
endif()

if(NOT "${rapids-cmake-dir}" IN_LIST CMAKE_MODULE_PATH)
message(FATAL_ERROR "expected variable rapids-cmake-dir to be inside CMAKE_MODULE_PATH")
endif()

if(NOT EXISTS "${rapids-cmake_SOURCE_DIR}/init.cmake")
message(FATAL_ERROR "expected init.cmake to exist")
endif()
38 changes: 38 additions & 0 deletions testing/other/rapids_cmake-multiple-simple/B/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#=============================================================================
# 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.
#=============================================================================

# verify no rapids-cmake variables have been specified
if(DEFINED rapids-cmake_SOURCE_DIR)
message(FATAL_ERROR "")
endif()

include("${rapids.cmake-location}")

if(NOT DEFINED rapids-cmake_SOURCE_DIR)
message(FATAL_ERROR "expected variable rapids-cmake_SOURCE_DIR to exist")
endif()

if(NOT DEFINED rapids-cmake-dir)
message(FATAL_ERROR "expected variable rapids-cmake-dir to exist")
endif()

if(NOT "${rapids-cmake-dir}" IN_LIST CMAKE_MODULE_PATH)
message(FATAL_ERROR "expected variable rapids-cmake-dir to be inside CMAKE_MODULE_PATH")
endif()

if(NOT EXISTS "${rapids-cmake_SOURCE_DIR}/init.cmake")
message(FATAL_ERROR "expected init.cmake to exist")
endif()
31 changes: 31 additions & 0 deletions testing/other/rapids_cmake-multiple-simple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#=============================================================================
# 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.
#=============================================================================
cmake_minimum_required(VERSION 3.20)
project(rapids-test-project LANGUAGES CXX)

cmake_path(GET rapids-cmake-dir PARENT_PATH rapids.cmake-location)
cmake_path(APPEND rapids.cmake-location "RAPIDS.cmake")

# Remove this cache variable so we can properly test
# fetching rapids-cmake work as intended
unset(rapids-cmake-dir CACHE)

# Remove this cache variable so we can properly test
# fetching rapids-cmake work as intended
unset(rapids-cmake-dir CACHE)

add_subdirectory(A)
add_subdirectory(B)

0 comments on commit 7d70891

Please sign in to comment.