Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure nvcomps build and install layouts are consistent #602

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions rapids-cmake/cpm/nvcomp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,37 @@ function(rapids_cpm_nvcomp)
rapids_cpm_get_proprietary_binary_url(nvcomp ${version} nvcomp_url)
if(nvcomp_url)
rapids_cpm_download_proprietary_binary(nvcomp ${nvcomp_url})

# Unset CPM_DOWNLOAD_ALL if we have a proprietary binary enabled. This ensures we actually use
# the proprietary binary
unset(CPM_DOWNLOAD_ALL)
endif()

# Record the nvcomp_DIR so that if USE_PROPRIETARY_BINARY is disabled we can safely clear the
# nvcomp_DIR value
if(nvcomp_proprietary_binary)
set(nvcomp_proprietary_binary_dir "${nvcomp_ROOT}/lib/cmake/nvcomp")
# Set up the version of nvcomp we have downloaded to match the OS layout. that means ensuring
# we have a `lib64` directory on Fedora based machines
include("${rapids-cmake-dir}/cmake/install_lib_dir.cmake")
rapids_cmake_install_lib_dir(lib_dir)

# Replace ${_IMPORT_PREFIX}/lib/ with ${_IMPORT_PREFIX}/${lib_dir}/ in
# 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")
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})
file(RENAME "${nvcomp_ROOT}/lib/" "${nvcomp_ROOT}/${lib_dir}/")
endif()

# Record the nvcomp_DIR so that if USE_PROPRIETARY_BINARY is disabled we can safely clear the
# nvcomp_DIR value
set(nvcomp_proprietary_binary_dir "${nvcomp_ROOT}/${lib_dir}/cmake/nvcomp")
cmake_path(NORMAL_PATH nvcomp_proprietary_binary_dir)
set(rapids_cpm_nvcomp_proprietary_binary_dir "${nvcomp_proprietary_binary_dir}"
CACHE INTERNAL "nvcomp proprietary location")

# Enforce that we need to find the local download of nvcomp and nothing else when we have a
# proprietary binary enabled.
list(APPEND CMAKE_PREFIX_PATH "${nvcomp_ROOT}/${lib_dir}/cmake/nvcomp")
unset(CPM_DOWNLOAD_ALL)
set(CPM_USE_LOCAL_PACKAGES ON)
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
endif()
elseif(DEFINED nvcomp_DIR)
cmake_path(NORMAL_PATH nvcomp_DIR)
Expand Down Expand Up @@ -175,26 +193,20 @@ function(rapids_cpm_nvcomp)

# Set up up install rules when using the proprietary_binary. When building from source, 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_dir}")

install(DIRECTORY "${nvcomp_ROOT}/${lib_dir}/" 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
include("${rapids-cmake-dir}/export/find_package_root.cmake")
rapids_export_find_package_root(BUILD nvcomp "${nvcomp_ROOT}"
EXPORT_SET ${_RAPIDS_BUILD_EXPORT_SET}
CONDITION nvcomp_proprietary_binary)
Expand Down
2 changes: 1 addition & 1 deletion testing/cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +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_build_test( cpm_nvcomp-proprietary_binary-lib-location.cmake SERIAL NO_CPM_CACHE)

add_cmake_config_test( cpm_proprietary-url-ctk-version-find-ctk.cmake )
add_cmake_config_test( cpm_proprietary-url-ctk-version.cmake )
Expand Down
10 changes: 9 additions & 1 deletion testing/cpm/cpm_nvcomp-proprietary_binary-lib-location.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ 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)
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)
Expand Down Expand Up @@ -63,6 +63,14 @@ 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
Expand Down
Loading