Skip to content

Commit

Permalink
Always add raft::raft_nn_lib and raft::raft_distance_lib aliases (#…
Browse files Browse the repository at this point in the history
…727)

Always add `raft::raft_nn_lib` and `raft::raft_distance_lib` aliases so adding raft as a submodule provides the same library targets as using it as a package.

Here's an example of the differences between using RAFT as a submodule and using it as a package (preinstalled or otherwise):

```cmake
# Build raft from source
set(RAFT_COMPILE_LIBRARIES ON)
add_subdirectory(/raft/cpp)
if(TARGET raft_nn_lib) # FALSE
if(TARGET raft_distance_lib) # FALSE
if(TARGET raft::raft_nn_lib) # TRUE
if(TARGET raft::raft_distance_lib) # TRUE

# Find the RAFT package
set(raft_ROOT /raft/cpp/build)
find_package(raft)
if(TARGET raft_nn_lib) # FALSE
if(TARGET raft_distance_lib) # FALSE
if(TARGET raft::raft_nn_lib) # TRUE
if(TARGET raft::raft_distance_lib) # TRUE
```

The problem is exacerbated if we use `CPMFindPackage`, since the available raft targets will be different based on whether this is the first time we've configured or if we're re-configuring:
```cmake
if(EXISTS ${CMAKE_BINARY_DIR}/_deps/raft-build)
  set(raft_ROOT ${CMAKE_BINARY_DIR}/_deps/raft-build)
endif()
# Find or build RAFT from source
CPMFindPackage(NAME raft ...)
if(TARGET raft_nn_lib) # initial configure=TRUE, reconfigure=FALSE
if(TARGET raft_distance_lib) # initial configure=TRUE, reconfigure=FALSE
if(TARGET raft::raft_nn_lib) # initial configure=FALSE, reconfigure=TRUE
if(TARGET raft::raft_distance_lib) # initial configure=FALSE, reconfigure=TRUE
```

Authors:
  - Paul Taylor (https://github.com/trxcllnt)

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

URL: #727
  • Loading branch information
trxcllnt authored Jun 29, 2022
1 parent 5c827de commit 5f12112
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,12 @@ if(RAFT_COMPILE_DIST_LIBRARY)

endif()

if(TARGET raft_distance_lib AND (NOT TARGET raft::raft_distance_lib))
add_library(raft::raft_distance_lib ALIAS raft_distance_lib)
endif()

target_link_libraries(raft_distance INTERFACE
raft::raft
$<TARGET_NAME_IF_EXISTS:raft_distance_lib>
$<TARGET_NAME_IF_EXISTS:raft::raft_distance_lib>
)

Expand Down Expand Up @@ -341,9 +344,12 @@ if(RAFT_COMPILE_NN_LIBRARY)
INTERFACE "RAFT_NN_COMPILED")
endif()

if(TARGET raft_nn_lib AND (NOT TARGET raft::raft_nn_lib))
add_library(raft::raft_nn_lib ALIAS raft_nn_lib)
endif()

target_link_libraries(raft_nn INTERFACE
raft::raft
$<TARGET_NAME_IF_EXISTS:raft_nn_lib>
$<TARGET_NAME_IF_EXISTS:raft::raft_nn_lib>)

##############################################################################
Expand Down

0 comments on commit 5f12112

Please sign in to comment.