Skip to content

Commit

Permalink
Correctly set the install location for nvcomp when using the propriet…
Browse files Browse the repository at this point in the history
…ary binary (#597)

When we download the nvcomp binaries, we have to ensure that those binaries are also using the location determined by `rapids_cmake_install_lib_dir`.

Authors:
  - Vyas Ramasubramani (https://github.com/vyasr)

Approvers:
  - Mike Sarahan (https://github.com/msarahan)
  - Robert Maynard (https://github.com/robertmaynard)

URL: #597
  • Loading branch information
vyasr authored May 6, 2024
1 parent 365322a commit 591e654
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
15 changes: 12 additions & 3 deletions rapids-cmake/cpm/nvcomp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function(rapids_cpm_nvcomp)
endif()
endif()

# second see if we have a proprietary pre-built binary listed in versions.json and it if
# second see if we have a proprietary pre-built binary listed in versions.json and download it if
# requested.
set(nvcomp_proprietary_binary OFF) # will be set to true by rapids_cpm_get_proprietary_binary
if(_RAPIDS_USE_PROPRIETARY_BINARY AND NOT nvcomp_FOUND)
Expand Down Expand Up @@ -177,12 +177,21 @@ function(rapids_cpm_nvcomp)
# will set the correct install rules
include("${rapids-cmake-dir}/export/find_package_root.cmake")
if(NOT to_exclude AND nvcomp_proprietary_binary)
include("${rapids-cmake-dir}/cmake/install_lib_dir.cmake")
rapids_cmake_install_lib_dir(lib_dir)
include(GNUInstallDirs)
install(DIRECTORY "${nvcomp_ROOT}/lib/" DESTINATION lib)
install(DIRECTORY "${nvcomp_ROOT}/include/" DESTINATION include)
install(DIRECTORY "${nvcomp_ROOT}/lib/" DESTINATION "${lib_dir}")
install(DIRECTORY "${nvcomp_ROOT}/include/" 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)

# Replace ${_IMPORT_PREFIX}/lib/ with ${_IMPORT_PREFIX}/${lib_dir}/ in
# nvcomp-release-targets.cmake
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})
file(WRITE "${nvcomp_ROOT}/lib/cmake/nvcomp/nvcomp-targets-release.cmake" ${FILE_CONTENTS})
endif()

# point our consumers to where they can find the pre-built version
Expand Down
1 change: 1 addition & 0 deletions testing/cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ add_cmake_config_test( cpm_nvcomp-simple.cmake )
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)

add_cmake_config_test( cpm_proprietary-url-ctk-version-find-ctk.cmake )
add_cmake_config_test( cpm_proprietary-url-ctk-version.cmake )
Expand Down
72 changes: 72 additions & 0 deletions testing/cpm/cpm_nvcomp-proprietary_binary-lib-location.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#=============================================================================
# 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()

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/lib/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.23.1)
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()
")

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)

0 comments on commit 591e654

Please sign in to comment.