From 2e28b1f851f52bd34295a0a3754e2c20e291f689 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Fri, 14 May 2021 13:35:21 -0400 Subject: [PATCH] rapids_export now correctly generates the documented version variables --- rapids-cmake/export/export.cmake | 1 + rapids-cmake/export/template/config.cmake.in | 18 +++++-- testing/export/CMakeLists.txt | 1 + testing/export/export-verify-version.cmake | 49 ++++++++++++++++++++ 4 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 testing/export/export-verify-version.cmake diff --git a/rapids-cmake/export/export.cmake b/rapids-cmake/export/export.cmake index 5f0bcf1c7..72eff71fb 100644 --- a/rapids-cmake/export/export.cmake +++ b/rapids-cmake/export/export.cmake @@ -106,6 +106,7 @@ function(rapids_export type project_name) #Write configuration and version files string(TOLOWER ${project_name} project_name) + string(TOUPPER ${project_name} project_name_uppercase) if(type STREQUAL "install") set(install_location "${CMAKE_INSTALL_LIBDIR}/cmake/${project_name}") set(scratch_dir "${PROJECT_BINARY_DIR}/rapids-cmake/${project_name}/export") diff --git a/rapids-cmake/export/template/config.cmake.in b/rapids-cmake/export/template/config.cmake.in index 699e9ca71..b80fc658a 100644 --- a/rapids-cmake/export/template/config.cmake.in +++ b/rapids-cmake/export/template/config.cmake.in @@ -23,10 +23,10 @@ Result Variables This module will set the following variables:: - @project_name@_FOUND - @project_name@_VERSION - @project_name@_VERSION_MAJOR - @project_name@_VERSION_MINOR + @project_name_uppercase@_FOUND + @project_name_uppercase@_VERSION + @project_name_uppercase@_VERSION_MAJOR + @project_name_uppercase@_VERSION_MINOR #]=======================================================================] @@ -43,9 +43,17 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/@project_name@-dependencies.cmake") include("${CMAKE_CURRENT_LIST_DIR}/@project_name@-dependencies.cmake") endif() -include("${CMAKE_CURRENT_LIST_DIR}/@project_name@-targets.cmake") +if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/@project_name@-targets.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/@project_name@-targets.cmake") +endif() + include("${CMAKE_CURRENT_LIST_DIR}/@project_name@-config-version.cmake") +# Set our version variables +set(@project_name_uppercase@_VERSION_MAJOR ${CVF_VERSION_MAJOR}) +set(@project_name_uppercase@_VERSION_MINOR ${CVF_VERSION_MINOR}) +set(@project_name_uppercase@_VERSION "${CVF_VERSION_MAJOR}.${CVF_VERSION_MINOR}") + set(rapids_global_targets @RAPIDS_GLOBAL_TARGETS@) if("rapids_config_@type@" STREQUAL "rapids_config_install") diff --git a/testing/export/CMakeLists.txt b/testing/export/CMakeLists.txt index 07c97697c..2e1f49cb3 100644 --- a/testing/export/CMakeLists.txt +++ b/testing/export/CMakeLists.txt @@ -18,6 +18,7 @@ add_cmake_config_test( export_cpm-build.cmake ) add_cmake_config_test( export_cpm-install.cmake ) add_cmake_config_test( export-verify-file-names.cmake ) +add_cmake_config_test( export-verify-version.cmake ) add_cmake_config_test( export_package-build.cmake ) add_cmake_config_test( export_package-install.cmake ) diff --git a/testing/export/export-verify-version.cmake b/testing/export/export-verify-version.cmake new file mode 100644 index 000000000..310e77aba --- /dev/null +++ b/testing/export/export-verify-version.cmake @@ -0,0 +1,49 @@ +#============================================================================= +# 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(${rapids-cmake-dir}/export/cpm.cmake) +include(${rapids-cmake-dir}/export/export.cmake) + +project(test LANGUAGES CXX VERSION 3.1.4) + +add_library(fakeLib INTERFACE) +install(TARGETS fakeLib EXPORT fake_set) + +rapids_export(BUILD test + EXPORT_SET fake_set + LANGUAGES CXX + ) + +# Verify that build files have correct names +if(NOT EXISTS "${CMAKE_BINARY_DIR}/test-config.cmake") + message(FATAL_ERROR "rapids_export failed to generate correct config file name") +endif() + +unset(TEST_VERSION) +unset(TEST_VERSION_MAJOR) +unset(TEST_VERSION_MINOR) + +set(CMAKE_FIND_PACKAGE_NAME test) # Emulate `find_package` +include("${CMAKE_BINARY_DIR}/test-config.cmake") + +if(NOT TEST_VERSION VERSION_EQUAL 3.1) + message(FATAL_ERROR "rapids_export failed to export version information") +endif() + +if(NOT "${TEST_VERSION_MAJOR}.${TEST_VERSION_MINOR}" VERSION_EQUAL 3.1) + message(FATAL_ERROR "rapids_export failed to export version major/minor information") +endif() + +