From 7240793f5a3c107f9562340d2c354a9a97219700 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Fri, 16 Aug 2024 11:43:03 -0400 Subject: [PATCH] Allow nested lib location for nvcomp Modify rapids_cpm_nvcomp() to allow CMAKE_INSTALL_LIBDIR and CMAKE_INSTALL_INCLUDEDIR to be nested directories. This is needed to support building wheels that set these variables in order to put their libraries in their own package directory. --- rapids-cmake/cpm/nvcomp.cmake | 14 +++- testing/cpm/CMakeLists.txt | 1 + ...oprietary_binary-lib-location-common.cmake | 80 +++++++++++++++++++ ...oprietary_binary-lib-location-nested.cmake | 19 +++++ ...comp-proprietary_binary-lib-location.cmake | 64 +-------------- 5 files changed, 112 insertions(+), 66 deletions(-) create mode 100644 testing/cpm/cpm_nvcomp-proprietary_binary-lib-location-common.cmake create mode 100644 testing/cpm/cpm_nvcomp-proprietary_binary-lib-location-nested.cmake diff --git a/rapids-cmake/cpm/nvcomp.cmake b/rapids-cmake/cpm/nvcomp.cmake index 3fceb6e6..1f3298b3 100644 --- a/rapids-cmake/cpm/nvcomp.cmake +++ b/rapids-cmake/cpm/nvcomp.cmake @@ -123,11 +123,18 @@ function(rapids_cpm_nvcomp) # nvcomp-release-targets.cmake. Guarded in an EXISTS check so we only try to do this on the # first configuration pass if(NOT EXISTS "${nvcomp_ROOT}/${lib_dir}/cmake/nvcomp/nvcomp-targets-release.cmake") + include(GNUInstallDirs) + get_filename_component(lib_dir_name "${lib_dir}" NAME) file(READ "${nvcomp_ROOT}/lib/cmake/nvcomp/nvcomp-targets-release.cmake" FILE_CONTENTS) - string(REPLACE "\$\{_IMPORT_PREFIX\}/lib/" "\$\{_IMPORT_PREFIX\}/${lib_dir}/" FILE_CONTENTS - ${FILE_CONTENTS}) + string(REPLACE "\$\{_IMPORT_PREFIX\}/lib/" "\$\{_IMPORT_PREFIX\}/${lib_dir_name}/" + FILE_CONTENTS ${FILE_CONTENTS}) file(WRITE "${nvcomp_ROOT}/lib/cmake/nvcomp/nvcomp-targets-release.cmake" ${FILE_CONTENTS}) + get_filename_component(lib_dir_parent "${lib_dir}" DIRECTORY) + file(MAKE_DIRECTORY "${nvcomp_ROOT}/${lib_dir_parent}") file(RENAME "${nvcomp_ROOT}/lib/" "${nvcomp_ROOT}/${lib_dir}/") + get_filename_component(include_dir_parent "${CMAKE_INSTALL_INCLUDEDIR}" DIRECTORY) + file(MAKE_DIRECTORY "${nvcomp_ROOT}/${include_dir_parent}") + file(RENAME "${nvcomp_ROOT}/include/" "${nvcomp_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}/") endif() # Record the nvcomp_DIR so that if USE_PROPRIETARY_BINARY is disabled we can safely clear the @@ -199,7 +206,8 @@ function(rapids_cpm_nvcomp) include(GNUInstallDirs) install(DIRECTORY "${nvcomp_ROOT}/${lib_dir}/" DESTINATION "${lib_dir}") - install(DIRECTORY "${nvcomp_ROOT}/include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") + install(DIRECTORY "${nvcomp_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}/" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") # place the license information in the location that conda uses install(FILES "${nvcomp_ROOT}/NOTICE" DESTINATION info/ RENAME NVCOMP_NOTICE) install(FILES "${nvcomp_ROOT}/LICENSE" DESTINATION info/ RENAME NVCOMP_LICENSE) diff --git a/testing/cpm/CMakeLists.txt b/testing/cpm/CMakeLists.txt index 4747ca60..70379c08 100644 --- a/testing/cpm/CMakeLists.txt +++ b/testing/cpm/CMakeLists.txt @@ -105,6 +105,7 @@ add_cmake_config_test( cpm_nvcomp-invalid-arch.cmake ) add_cmake_config_test( cpm_nvcomp-always-download-proprietary_binary.cmake SERIAL) add_cmake_config_test( cpm_nvcomp-override-clears-proprietary_binary.cmake SERIAL) add_cmake_build_test( cpm_nvcomp-proprietary_binary-lib-location.cmake SERIAL NO_CPM_CACHE) +add_cmake_build_test( cpm_nvcomp-proprietary_binary-lib-location-nested.cmake SERIAL NO_CPM_CACHE) add_cmake_build_test( cpm_nvtx-build-config-works.cmake ) add_cmake_build_test( cpm_nvtx-install-config-works.cmake ) diff --git a/testing/cpm/cpm_nvcomp-proprietary_binary-lib-location-common.cmake b/testing/cpm/cpm_nvcomp-proprietary_binary-lib-location-common.cmake new file mode 100644 index 00000000..88774c65 --- /dev/null +++ b/testing/cpm/cpm_nvcomp-proprietary_binary-lib-location-common.cmake @@ -0,0 +1,80 @@ +#============================================================================= +# Copyright (c) 2024, 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/nvcomp.cmake) +include(${rapids-cmake-dir}/cpm/package_override.cmake) + + +rapids_cpm_init() + +if(TARGET nvcomp::nvcomp) + message(FATAL_ERROR "Expected nvcomp::nvcomp not to exist") +endif() + +rapids_cpm_nvcomp(USE_PROPRIETARY_BINARY ON BUILD_EXPORT_SET nvcomp-targets INSTALL_EXPORT_SET nvcomp-targets) + +if(NOT nvcomp_proprietary_binary) + message(FATAL_ERROR "Ignored nvcomp override file failed to get proprietary binary version") +endif() + +# Check the contents of the nvcomp-targets-release.cmake file to ensure that +# every line containing "_IMPORT_PREFIX" also contains "${CMAKE_INSTALL_LIBDIR}" +file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/_deps/nvcomp_proprietary_binary-src/${CMAKE_INSTALL_LIBDIR}/cmake/nvcomp/nvcomp-targets-release.cmake" nvcomp_targets_release_contents) +foreach(line IN LISTS nvcomp_targets_release_contents) + string(FIND "${line}" "_IMPORT_PREFIX" _IMPORT_PREFIX_INDEX) + if(_IMPORT_PREFIX_INDEX EQUAL -1) + continue() + endif() + get_filename_component(lib_dir_name "${CMAKE_INSTALL_LIBDIR}" NAME) + string(FIND "${line}" "${lib_dir_name}" _LIBDIR_INDEX) + if(_LIBDIR_INDEX EQUAL -1) + message(FATAL_ERROR "nvcomp-targets-release.cmake file does not contain ${lib_dir_name}") + endif() +endforeach() + +# Install and check the install directory. +add_custom_target(install_project ALL + COMMAND ${CMAKE_COMMAND} --install "${CMAKE_BINARY_DIR}" --prefix check_nvcomp_lib_dir/install/ + ) + +# Need to capture the install directory based on the binary dir of this project, not the subproject used for testing. +set(expected_install_dir "${CMAKE_BINARY_DIR}/check_nvcomp_lib_dir/install/") + +# Add a custom command that verifies that the expect files have +# been installed for each component +file(WRITE "${CMAKE_BINARY_DIR}/check_nvcomp_lib_dir/CMakeLists.txt" " +cmake_minimum_required(VERSION 3.26.4) +project(verify_install_targets LANGUAGES CXX) + +message(\"Checking for ${CMAKE_INSTALL_LIBDIR} directory in ${expected_install_dir}\") +if (NOT EXISTS ${expected_install_dir}/${CMAKE_INSTALL_LIBDIR}) + message(FATAL_ERROR \"The ${CMAKE_INSTALL_LIBDIR} directory didn't exist!\") +endif() + +set(nvcomp_ROOT \"${expected_install_dir}/${CMAKE_INSTALL_LIBDIR}/cmake/nvcomp\") +find_package(nvcomp REQUIRED) + +file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/stub.cpp\" \" \") +add_library(uses_nvcomp SHARED stub.cpp) +target_link_libraries(uses_nvcomp PRIVATE nvcomp::nvcomp) + +") + +add_custom_target(verify_nvcomp_lib_dir ALL + COMMAND ${CMAKE_COMMAND} -E rm -rf "${CMAKE_BINARY_DIR}/check_nvcomp_lib_dir/build" + COMMAND ${CMAKE_COMMAND} -S="${CMAKE_BINARY_DIR}/check_nvcomp_lib_dir" -B="${CMAKE_BINARY_DIR}/install/build" +) +add_dependencies(verify_nvcomp_lib_dir install_project) diff --git a/testing/cpm/cpm_nvcomp-proprietary_binary-lib-location-nested.cmake b/testing/cpm/cpm_nvcomp-proprietary_binary-lib-location-nested.cmake new file mode 100644 index 00000000..2ba363df --- /dev/null +++ b/testing/cpm/cpm_nvcomp-proprietary_binary-lib-location-nested.cmake @@ -0,0 +1,19 @@ +#============================================================================= +# Copyright (c) 2024, 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. +#============================================================================= + +set(CMAKE_INSTALL_LIBDIR "nested/lib64") +set(CMAKE_INSTALL_INCLUDEDIR "nested/include") +include("${CMAKE_CURRENT_LIST_DIR}/cpm_nvcomp-proprietary_binary-lib-location-common.cmake") diff --git a/testing/cpm/cpm_nvcomp-proprietary_binary-lib-location.cmake b/testing/cpm/cpm_nvcomp-proprietary_binary-lib-location.cmake index 9027f782..62106e96 100644 --- a/testing/cpm/cpm_nvcomp-proprietary_binary-lib-location.cmake +++ b/testing/cpm/cpm_nvcomp-proprietary_binary-lib-location.cmake @@ -13,68 +13,6 @@ # 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/nvcomp.cmake) -include(${rapids-cmake-dir}/cpm/package_override.cmake) - - -rapids_cpm_init() - -if(TARGET nvcomp::nvcomp) - message(FATAL_ERROR "Expected nvcomp::nvcomp not to exist") -endif() set(CMAKE_INSTALL_LIBDIR "lib64") -rapids_cpm_nvcomp(USE_PROPRIETARY_BINARY ON BUILD_EXPORT_SET nvcomp-targets INSTALL_EXPORT_SET nvcomp-targets) - -if(NOT nvcomp_proprietary_binary) - message(FATAL_ERROR "Ignored nvcomp override file failed to get proprietary binary version") -endif() - -# Check the contents of the nvcomp-targets-release.cmake file to ensure that -# every line containing "_IMPORT_PREFIX" also contains "lib64" -file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/_deps/nvcomp_proprietary_binary-src/lib64/cmake/nvcomp/nvcomp-targets-release.cmake" nvcomp_targets_release_contents) -foreach(line IN LISTS nvcomp_targets_release_contents) - string(FIND "${line}" "_IMPORT_PREFIX" _IMPORT_PREFIX_INDEX) - if(_IMPORT_PREFIX_INDEX EQUAL -1) - continue() - endif() - string(FIND "${line}" "lib64" _LIB64_INDEX) - if(_LIB64_INDEX EQUAL -1) - message(FATAL_ERROR "nvcomp-targets-release.cmake file does not contain lib64") - endif() -endforeach() - -# Install and check the install directory. -add_custom_target(install_project ALL - COMMAND ${CMAKE_COMMAND} --install "${CMAKE_BINARY_DIR}" --prefix check_nvcomp_lib_dir/install/ - ) - -# Need to capture the install directory based on the binary dir of this project, not the subproject used for testing. -set(expected_install_dir "${CMAKE_BINARY_DIR}/check_nvcomp_lib_dir/install/") - -# Add a custom command that verifies that the expect files have -# been installed for each component -file(WRITE "${CMAKE_BINARY_DIR}/check_nvcomp_lib_dir/CMakeLists.txt" " -cmake_minimum_required(VERSION 3.26.4) -project(verify_install_targets LANGUAGES CXX) - -message(\"Checking for lib64 directory in ${expected_install_dir}\") -if (NOT EXISTS ${expected_install_dir}/lib64) - message(FATAL_ERROR \"The lib64 directory didn't exist!\") -endif() - -set(nvcomp_ROOT \"${expected_install_dir}/lib64/cmake/nvcomp\") -find_package(nvcomp REQUIRED) - -file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/stub.cpp\" \" \") -add_library(uses_nvcomp SHARED stub.cpp) -target_link_libraries(uses_nvcomp PRIVATE nvcomp::nvcomp) - -") - -add_custom_target(verify_nvcomp_lib_dir ALL - COMMAND ${CMAKE_COMMAND} -E rm -rf "${CMAKE_BINARY_DIR}/check_nvcomp_lib_dir/build" - COMMAND ${CMAKE_COMMAND} -S="${CMAKE_BINARY_DIR}/check_nvcomp_lib_dir" -B="${CMAKE_BINARY_DIR}/install/build" -) -add_dependencies(verify_nvcomp_lib_dir install_project) +include("${CMAKE_CURRENT_LIST_DIR}/cpm_nvcomp-proprietary_binary-lib-location-common.cmake")