Skip to content

Commit

Permalink
Update rapids-cmake to require cmake 3.23.1 (#227)
Browse files Browse the repository at this point in the history
This moves rapids-cmake to require CMake 3.23.1 or newer.

Along with that we are able to do the following improvements:

- Use CMake's FindGTest as it now provides all the targets we require
- Simplify install_lib_dir logic 
- Simplify logic around version values that are all zeroes

Authors:
  - Robert Maynard (https://github.com/robertmaynard)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #227
  • Loading branch information
robertmaynard authored Aug 29, 2022
1 parent 4505c37 commit 776f13f
Show file tree
Hide file tree
Showing 50 changed files with 84 additions and 113 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# 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)
cmake_minimum_required(VERSION 3.23.1 FATAL_ERROR)

set(rapids-cmake-dir "${CMAKE_CURRENT_LIST_DIR}/rapids-cmake")
if(NOT DEFINED CACHE{rapids-cmake-dir})
Expand Down
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#=============================================================================

cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
cmake_minimum_required(VERSION 3.23.1 FATAL_ERROR)

if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/EXAMPLE_RAPIDS.cmake)
file(DOWNLOAD https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-22.10/RAPIDS.cmake
Expand Down
3 changes: 2 additions & 1 deletion rapids-cmake/cmake/build_type.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Establish the :cmake:variable:`CMAKE_BUILD_TYPE` default value.
rapids_cmake_build_type(default_type)

If the generator is `Ninja` or `Makefile` the :cmake:variable:`CMAKE_BUILD_TYPE`
variable will be established if not explicitly set by the user. This removes
variable will be established if not explicitly set by the user either by
the env variable `CMAKE_BUILD_TYPE` or by passing `-DCMAKE_BUILD_TYPE=`. This removes
situations where the `No-Config` / `Empty` build type is used.

``default_type``
Expand Down
63 changes: 17 additions & 46 deletions rapids-cmake/cmake/install_lib_dir.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,54 +53,25 @@ function(rapids_cmake_install_lib_dir out_variable_name)
cmake_path(ABSOLUTE_PATH install_prefix NORMALIZE)

set(use_conda_lib_dir FALSE)
if(CMAKE_VERSION VERSION_LESS 3.22)
# Starting with 3.22, CMake is fully aware of the conda 'lib' requirements so we don't need to
# do this check at all
if(DEFINED ENV{CONDA_BUILD} AND DEFINED ENV{PREFIX})
set(conda_prefix "$ENV{PREFIX}")
cmake_path(ABSOLUTE_PATH conda_prefix NORMALIZE)
if(install_prefix STREQUAL conda_prefix)
set(use_conda_lib_dir TRUE)
endif()
elseif(DEFINED ENV{CONDA_PREFIX})
set(conda_prefix "$ENV{CONDA_PREFIX}")
cmake_path(ABSOLUTE_PATH conda_prefix NORMALIZE)
if(install_prefix STREQUAL conda_prefix)
set(use_conda_lib_dir TRUE)
endif()
endif()
endif()

set(computed_path)
if(use_conda_lib_dir)
# CONDA requires everything to be installed to 'lib' no matter the distro
set(computed_path "lib")
if(modify_install_libdir)
# GNUInstallDirs sets `CMAKE_INSTALL_LIBDIR` as a cache path, so we need to do that as well
set(CMAKE_INSTALL_LIBDIR ${computed_path} CACHE PATH
"Object code libraries (${computed_path})")

# Make sure our path overrides any local variable
set(CMAKE_INSTALL_LIBDIR ${computed_path} PARENT_SCOPE)
endif()
else()
# We need to defer to GNUInstallDirs but not allow it to set CMAKE_INSTALL_LIBDIR
set(remove_install_dir TRUE)
if(DEFINED CMAKE_INSTALL_LIBDIR)
set(remove_install_dir FALSE)
endif()

include(GNUInstallDirs)
set(computed_path "${CMAKE_INSTALL_LIBDIR}")
if(modify_install_libdir)
# GNUInstallDirs will have set `CMAKE_INSTALL_LIBDIR` as a cache path So we only need to make
# sure our path overrides any local variable
set(CMAKE_INSTALL_LIBDIR ${computed_path} PARENT_SCOPE)
endif()

if(remove_install_dir)
unset(CMAKE_INSTALL_LIBDIR CACHE)
endif()

# We need to defer to GNUInstallDirs but not allow it to set CMAKE_INSTALL_LIBDIR
set(remove_install_dir TRUE)
if(DEFINED CMAKE_INSTALL_LIBDIR)
set(remove_install_dir FALSE)
endif()

include(GNUInstallDirs)
set(computed_path "${CMAKE_INSTALL_LIBDIR}")
if(modify_install_libdir)
# GNUInstallDirs will have set `CMAKE_INSTALL_LIBDIR` as a cache path so we only need to make
# sure our path overrides any local variable
set(CMAKE_INSTALL_LIBDIR ${computed_path} PARENT_SCOPE)
endif()

if(remove_install_dir)
unset(CMAKE_INSTALL_LIBDIR CACHE)
endif()

set(${out_variable_name} ${computed_path} PARENT_SCOPE)
Expand Down
9 changes: 1 addition & 8 deletions rapids-cmake/cpm/gtest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,10 @@ function(rapids_cpm_gtest)
include("${rapids-cmake-dir}/cpm/detail/package_details.cmake")
rapids_cpm_package_details(GTest version repository tag shallow exclude)

set(EXTRA_CPM_ARGS)
if(CMAKE_VERSION VERSION_LESS 3.23)
# CMake 3.23+ built-in FindGTest is required to have the GTest::gmock_main and GTest::gmock
# targets so always use gtest-config.cmake for now
string(APPEND EXTRA_CPM_ARGS "NO_MODULE")
endif()

include("${rapids-cmake-dir}/cpm/find.cmake")
rapids_cpm_find(GTest ${version} ${ARGN}
GLOBAL_TARGETS GTest::gtest GTest::gmock GTest::gtest_main GTest::gmock_main
CPM_ARGS FIND_PACKAGE_ARGUMENTS "EXACT ${EXTRA_CPM_ARGS}"
CPM_ARGS FIND_PACKAGE_ARGUMENTS "EXACT"
GIT_REPOSITORY ${repository}
GIT_TAG ${tag}
GIT_SHALLOW ${shallow}
Expand Down
3 changes: 1 addition & 2 deletions rapids-cmake/cpm/rmm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ function(rapids_cpm_rmm)
endif()

include("${rapids-cmake-dir}/cpm/find.cmake")
# Once we can require CMake 3.22 this can use `only_major_minor` for version searches
rapids_cpm_find(rmm "${version}.0" ${_RAPIDS_UNPARSED_ARGUMENTS}
rapids_cpm_find(rmm ${version} ${ARGN} {_RAPIDS_UNPARSED_ARGUMENTS}
GLOBAL_TARGETS rmm::rmm
CPM_ARGS
GIT_REPOSITORY ${repository}
Expand Down
17 changes: 12 additions & 5 deletions rapids-cmake/export/detail/parse_version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,29 @@ function(rapids_export_parse_version rapids_version orig_prefix ver_value)
rapids_cmake_parse_version(MINOR "${rapids_version}" orig_minor_version)
rapids_cmake_parse_version(PATCH "${rapids_version}" orig_patch_version)

# Generate an explicit VERSION string without zeroes to work around:
# https://gitlab.kitware.com/cmake/cmake/-/issues/22207
set(version_compat SameMajorVersion)
if(DEFINED orig_major_version)
math(EXPR rapids_major_version "${orig_major_version} + 0" OUTPUT_FORMAT DECIMAL)
set(rapids_major_version "${orig_major_version}")
if(rapids_major_version MATCHES "^0+$")
set(rapids_major_version "0")
endif()
string(APPEND rapids_project_version "${rapids_major_version}")
endif()

if(DEFINED orig_minor_version)
math(EXPR rapids_minor_version "${orig_minor_version} + 0" OUTPUT_FORMAT DECIMAL)
set(rapids_minor_version "${orig_minor_version}")
if(rapids_minor_version MATCHES "^0+$")
set(rapids_minor_version "0")
endif()
string(APPEND rapids_project_version ".${rapids_minor_version}")
set(version_compat SameMinorVersion)
endif()

if(DEFINED orig_patch_version)
math(EXPR rapids_patch_version "${orig_patch_version} + 0" OUTPUT_FORMAT DECIMAL)
set(rapids_patch_version "${orig_patch_version}")
if(rapids_patch_version MATCHES "^0+$")
set(rapids_patch_version "0")
endif()
string(APPEND rapids_project_version ".${rapids_patch_version}")
set(version_compat SameMinorVersion)
endif()
Expand Down
2 changes: 1 addition & 1 deletion testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#=============================================================================

cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
cmake_minimum_required(VERSION 3.23.1 FATAL_ERROR)
project(rapids-cmake-testing LANGUAGES NONE)

enable_testing()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#=============================================================================
include(${rapids-cmake-dir}/cmake/write_git_revision_file.cmake)

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)

project(DEMO VERSION 2.4 LANGUAGES CXX)
rapids_cmake_write_git_revision_file(demo_version "${CMAKE_CURRENT_BINARY_DIR}/demo/demo_git_version.hpp")
Expand Down
2 changes: 1 addition & 1 deletion testing/cmake/write_git_revision-dirty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#=============================================================================
include(${rapids-cmake-dir}/cmake/write_git_revision_file.cmake)

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)

project(DEMO VERSION 2.4 LANGUAGES CXX)

Expand Down
2 changes: 1 addition & 1 deletion testing/cmake/write_git_revision-embed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#=============================================================================
include(${rapids-cmake-dir}/cmake/write_git_revision_file.cmake)

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)

project(DEMO VERSION 2.4 LANGUAGES CXX)
rapids_cmake_write_git_revision_file(git_generated_header "${CMAKE_CURRENT_BINARY_DIR}/demo/git_version.hpp")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)
file(STRINGS "${EXECUTABLE}" contents)

execute_process(
Expand Down
2 changes: 1 addition & 1 deletion testing/cmake/write_git_revision-no-git/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#=============================================================================
include(${rapids-cmake-dir}/cmake/write_git_revision_file.cmake)

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)

project(DEMO VERSION 2.4 LANGUAGES CXX)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)
file(STRINGS "${EXECUTABLE}" contents)

execute_process(
Expand Down
2 changes: 1 addition & 1 deletion testing/cmake/write_git_revision-simple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#=============================================================================
include(${rapids-cmake-dir}/cmake/write_git_revision_file.cmake)

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)

project(DEMO VERSION 2.4 LANGUAGES CXX)
rapids_cmake_write_git_revision_file(demo_version "${CMAKE_CURRENT_BINARY_DIR}/demo/demo_git_version.hpp")
Expand Down
2 changes: 1 addition & 1 deletion testing/cmake/write_version-absolute/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#=============================================================================
include(${rapids-cmake-dir}/cmake/write_version_file.cmake)

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)

project(DEMO VERSION 2.4 LANGUAGES NONE)
rapids_cmake_write_version_file("${CMAKE_CURRENT_BINARY_DIR}/demo/version.h")
Expand Down
2 changes: 1 addition & 1 deletion testing/cmake/write_version-all-zeroes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#=============================================================================
include(${rapids-cmake-dir}/cmake/write_version_file.cmake)

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)

project(DEMO VERSION 0.0000.1 LANGUAGES NONE)
rapids_cmake_write_version_file(version.h)
Expand Down
2 changes: 1 addition & 1 deletion testing/cmake/write_version-custom-prefix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#=============================================================================
include(${rapids-cmake-dir}/cmake/write_version_file.cmake)

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)

project(RandomProjectName VERSION 3.2.0 LANGUAGES NONE)
rapids_cmake_write_version_file(demo_version.hpp PREFIX DEMO)
Expand Down
4 changes: 2 additions & 2 deletions testing/cmake/write_version-leading-zeroes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
#=============================================================================
include(${rapids-cmake-dir}/cmake/write_version_file.cmake)

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)

project(DEMO VERSION 09.00008.02 LANGUAGES NONE)
rapids_cmake_write_version_file(version.h)

enable_language(CXX)
add_executable(write_version main.cpp)
target_include_directories(write_version PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
target_compile_features(write_version PRIVATE cxx_std_14)
target_compile_features(write_version PRIVATE cxx_std_14)
4 changes: 2 additions & 2 deletions testing/cmake/write_version-relative/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#=============================================================================
include(${rapids-cmake-dir}/cmake/write_version_file.cmake)

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)

project(DEMO VERSION 3.2.0 LANGUAGES NONE)
rapids_cmake_write_version_file(demo_version.hpp)
Expand All @@ -26,4 +26,4 @@ rapids_cmake_write_version_file(nested_version.hpp)
enable_language(CXX)
add_executable(write_version main.cpp)
target_include_directories(write_version PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
target_compile_features(write_version PRIVATE cxx_std_14)
target_compile_features(write_version PRIVATE cxx_std_14)
2 changes: 1 addition & 1 deletion testing/cpm/cpm_find-add-pkg-source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
include(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/find.cmake)

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)
project(rapids-cpm-find-add-pkg-source LANGUAGES CXX)

set(CPM_ZLIB_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/mock_zlib_source_dir")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)
project(ZLIB LANGUAGES CXX)

add_library(MOCK_ZLIB INTERFACE)
2 changes: 1 addition & 1 deletion testing/cpm/cpm_find-and-find_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
include(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/find.cmake)

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)
project(rapids-test-project LANGUAGES CXX)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)
project(mock_cucxx LANGUAGES CXX)

add_library(MOCK_CUCXX INTERFACE)
2 changes: 1 addition & 1 deletion testing/cpm/cpm_find-existing-build-dir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
include(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/find.cmake)

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)
project(rapids-test-project LANGUAGES CXX)

include("${rapids-cmake-testing-dir}/cpm/make_fake_project_build_dir_with_config.cmake")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)

include(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/find.cmake)
Expand Down
2 changes: 1 addition & 1 deletion testing/cpm/cpm_find-existing-target/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
include(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/find.cmake)

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)
project(rapids-existing-target LANGUAGES CXX)

include("${rapids-cmake-testing-dir}/cpm/make_fake_project_build_dir_with_config.cmake")
Expand Down
2 changes: 1 addition & 1 deletion testing/cpm/cpm_find-options-escaped/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
include(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/find.cmake)

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)
project(rapids-test-project LANGUAGES CXX)

rapids_cpm_init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#=============================================================================
@PACKAGE_INIT@

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)

include("${CMAKE_CURRENT_LIST_DIR}/rapidstest-config-version.cmake")

Expand Down
2 changes: 1 addition & 1 deletion testing/cpm/cpm_find-restore-cpm-vars/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
include(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/find.cmake)

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)
project(rapids-cpm-find-add-pkg-source LANGUAGES CXX)

set(CPM_ZLIB_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/mock_zlib_source_dir")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.23.1)
project(ZLIB LANGUAGES CXX VERSION 1.0)

add_library(MOCK_ZLIB INTERFACE)
Loading

0 comments on commit 776f13f

Please sign in to comment.