Skip to content

Commit

Permalink
Restore changes from #653 and #655 and correct cmake component depend…
Browse files Browse the repository at this point in the history
…encies (#686)

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

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

URL: #686
  • Loading branch information
robertmaynard authored May 27, 2022
1 parent 958f8c1 commit 2450bdd
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 54 deletions.
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ fi
if hasArg tests || (( ${NUMARGS} == 0 )); then
BUILD_TESTS=ON
ENABLE_NN_DEPENDENCIES=ON
COMPILE_NN_LIBRARY=ON
CMAKE_TARGET="${CMAKE_TARGET};test_raft"
fi

Expand Down
95 changes: 49 additions & 46 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ if(RAFT_COMPILE_DIST_LIBRARY)
POSITION_INDEPENDENT_CODE ON
INTERFACE_POSITION_INDEPENDENT_CODE ON)

target_link_libraries(raft_distance_lib PRIVATE raft::raft)
target_link_libraries(raft_distance_lib
PUBLIC raft::raft
cuco::cuco
)
target_compile_options(raft_distance_lib
PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${RAFT_CXX_FLAGS}>"
"$<$<COMPILE_LANGUAGE:CUDA>:${RAFT_CUDA_FLAGS}>"
Expand All @@ -281,7 +284,6 @@ endif()

target_link_libraries(raft_distance INTERFACE
raft::raft
$<$<BOOL:${RAFT_ENABLE_cuco_DEPENDENCY}>:cuco::cuco>
$<TARGET_NAME_IF_EXISTS:raft_distance_lib>
$<TARGET_NAME_IF_EXISTS:raft::raft_distance_lib>
)
Expand Down Expand Up @@ -321,7 +323,9 @@ if(RAFT_COMPILE_NN_LIBRARY)
POSITION_INDEPENDENT_CODE ON
INTERFACE_POSITION_INDEPENDENT_CODE ON)

target_link_libraries(raft_nn_lib PUBLIC faiss::faiss PRIVATE raft::raft)
target_link_libraries(raft_nn_lib
PUBLIC faiss::faiss
raft::raft)
target_compile_options(raft_nn_lib
PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${RAFT_CXX_FLAGS}>"
"$<$<COMPILE_LANGUAGE:CUDA>:${RAFT_CUDA_FLAGS}>"
Expand All @@ -335,7 +339,6 @@ endif()

target_link_libraries(raft_nn INTERFACE
raft::raft
$<$<BOOL:${RAFT_ENABLE_NN_DEPENDENCIES}>:faiss::faiss>
$<TARGET_NAME_IF_EXISTS:raft_nn_lib>
$<TARGET_NAME_IF_EXISTS:raft::raft_nn_lib>)

Expand All @@ -352,18 +355,18 @@ install(TARGETS raft

install(TARGETS raft_distance
DESTINATION ${lib_dir}
COMPONENT raft_distance
COMPONENT raft
EXPORT raft-distance-exports)

install(TARGETS raft_nn
DESTINATION ${lib_dir}
COMPONENT raft_nn
COMPONENT raft
EXPORT raft-nn-exports)

if(TARGET raft_distance_lib)
install(TARGETS raft_distance_lib
DESTINATION ${lib_dir}
COMPONENT raft_distance
COMPONENT distance
EXPORT raft-distance-lib-exports)
install(DIRECTORY include/raft_distance
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
Expand All @@ -372,7 +375,7 @@ endif()
if(TARGET raft_nn_lib)
install(TARGETS raft_nn_lib
DESTINATION ${lib_dir}
COMPONENT raft_nn
COMPONENT nn
EXPORT raft-nn-lib-exports)
endif()

Expand All @@ -390,6 +393,44 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/raft/version_config.hpp
COMPONENT raft
DESTINATION include/raft)

##############################################################################
# - export/install optional components --------------------------------------

include("${rapids-cmake-dir}/export/write_dependencies.cmake")

set(raft_components distance nn)
set(raft_install_comp raft raft)
if(TARGET raft_distance_lib)
list(APPEND raft_components distance-lib)
list(APPEND raft_install_comp distance)
endif()
if(TARGET raft_nn_lib)
list(APPEND raft_components nn-lib)
list(APPEND raft_install_comp nn)
endif()

foreach(comp install_comp IN ZIP_LISTS raft_components raft_install_comp)
install(
EXPORT raft-${comp}-exports
FILE raft-${comp}-targets.cmake
NAMESPACE raft::
DESTINATION "${lib_dir}/cmake/raft"
COMPONENT ${install_comp}
)
export(
EXPORT raft-${comp}-exports
FILE ${RAFT_BINARY_DIR}/raft-${comp}-targets.cmake
NAMESPACE raft::
)
rapids_export_write_dependencies(
BUILD raft-${comp}-exports "${PROJECT_BINARY_DIR}/raft-${comp}-dependencies.cmake"
)
rapids_export_write_dependencies(
INSTALL raft-${comp}-exports "${PROJECT_BINARY_DIR}/rapids-cmake/raft/export/${install_comp}/raft-${comp}-dependencies.cmake"
)

endforeach()

##############################################################################
# - install export -----------------------------------------------------------
set(doc_string
Expand Down Expand Up @@ -458,44 +499,6 @@ raft_export(BUILD raft
NAMESPACE raft::
FINAL_CODE_BLOCK code_string)

##############################################################################
# - export/install optional components --------------------------------------

include("${rapids-cmake-dir}/export/write_dependencies.cmake")

set(raft_components distance nn)
set(raft_install_comp distance nn)
if(TARGET raft_distance_lib)
list(APPEND raft_components distance-lib)
list(APPEND raft_install_comp distance)
endif()
if(TARGET raft_nn_lib)
list(APPEND raft_components nn-lib)
list(APPEND raft_install_comp nn)
endif()

foreach(comp install_comp IN ZIP_LISTS raft_components raft_install_comp)
install(
EXPORT raft-${comp}-exports
FILE raft-${comp}-targets.cmake
NAMESPACE raft::
DESTINATION "${lib_dir}/cmake/raft"
COMPONENT raft_${install_comp}
)
export(
EXPORT raft-${comp}-exports
FILE ${RAFT_BINARY_DIR}/raft-${comp}-targets.cmake
NAMESPACE raft::
)
rapids_export_write_dependencies(
BUILD raft-${comp}-exports "${PROJECT_BINARY_DIR}/raft-${comp}-dependencies.cmake"
)
rapids_export_write_dependencies(
INSTALL raft-${comp}-exports "${PROJECT_BINARY_DIR}/rapids-cmake/raft/export/${install_comp}/raft-${comp}-dependencies.cmake"
)

endforeach()

##############################################################################
# - build test executable ----------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion cpp/cmake/modules/raft_export.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function(raft_export type project_name)
set(scratch_dir "${PROJECT_BINARY_DIR}/rapids-cmake/${project_name}/export/${comp}/")
file(MAKE_DIRECTORY "${scratch_dir}")
install(DIRECTORY "${scratch_dir}" DESTINATION "${install_location}"
COMPONENT raft_${comp})
COMPONENT ${comp})
endforeach()

else()
Expand Down
4 changes: 2 additions & 2 deletions cpp/cmake/thirdparty/get_cuco.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function(find_and_configure_cuco VERSION)

rapids_cpm_find(cuco ${VERSION}
GLOBAL_TARGETS cuco::cuco
BUILD_EXPORT_SET raft-distance-exports
INSTALL_EXPORT_SET raft-distance-exports
BUILD_EXPORT_SET raft-distance-lib-exports
INSTALL_EXPORT_SET raft-distance-lib-exports
CPM_ARGS
GIT_REPOSITORY https://github.com/NVIDIA/cuCollections.git
GIT_TAG 6ec8b6dcdeceea07ab4456d32461a05c18864411
Expand Down
9 changes: 4 additions & 5 deletions cpp/cmake/thirdparty/get_faiss.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function(find_and_configure_faiss)

rapids_cpm_find(faiss ${PKG_VERSION}
GLOBAL_TARGETS faiss::faiss
INSTALL_EXPORT_SET raft-nn-exports
CPM_ARGS
GIT_REPOSITORY https://github.com/facebookresearch/faiss.git
GIT_TAG ${PKG_PINNED_TAG}
Expand All @@ -58,13 +57,13 @@ function(find_and_configure_faiss)
endif()

# We generate the faiss-config files when we built faiss locally, so always do `find_dependency`
rapids_export_package(BUILD OpenMP raft-nn-exports) # faiss uses openMP but doesn't export a need for it
rapids_export_package(BUILD faiss raft-nn-exports GLOBAL_TARGETS faiss::faiss faiss)
rapids_export_package(INSTALL faiss raft-nn-exports GLOBAL_TARGETS faiss::faiss faiss)
rapids_export_package(BUILD OpenMP raft-nn-lib-exports) # faiss uses openMP but doesn't export a need for it
rapids_export_package(BUILD faiss raft-nn-lib-exports GLOBAL_TARGETS faiss::faiss faiss)
rapids_export_package(INSTALL faiss raft-nn-lib-exports GLOBAL_TARGETS faiss::faiss faiss)

# Tell cmake where it can find the generated faiss-config.cmake we wrote.
include("${rapids-cmake-dir}/export/find_package_root.cmake")
rapids_export_find_package_root(BUILD faiss [=[${CMAKE_CURRENT_LIST_DIR}]=] raft-nn-exports)
rapids_export_find_package_root(BUILD faiss [=[${CMAKE_CURRENT_LIST_DIR}]=] raft-nn-lib-exports)
endfunction()

find_and_configure_faiss(VERSION 1.7.0
Expand Down

0 comments on commit 2450bdd

Please sign in to comment.