eBay / NuRaft

C++ implementation of Raft core logic as a replication library
Apache License 2.0
996 stars 236 forks source link

Export CMake targets #452

Closed JosiahWI closed 1 year ago

JosiahWI commented 1 year ago

This exports both the shared and static library targets. A downstream project can use then use them as follows:

find_package(NuRaft REQUIRED)
target_link_libraries(downstream_target PRIVATE NuRaft::static_lib)

Closes #450

tisonkun commented 1 year ago

@JosiahWI how we exactly achieve this? I tried:

include(FetchContent)

FetchContent_Declare(
        nuraft
        GIT_REPOSITORY https://ghproxy.com/https://github.com/eBay/NuRaft.git
        GIT_TAG 188947bcc73ce38ab1c3cf9d01015ca8a29decd9
        GIT_SUBMODULES_RECURSE TRUE
)
FetchContent_MakeAvailable(nuraft)
find_package(NuRaft REQUIRED)

add_executable(mephisto main.cpp)
target_link_libraries(mephisto PRIVATE NuRaft::static_lib)

... and get:

CMake Error at CMakeLists.txt:15 (find_package):
  By not providing "FindNuRaft.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "NuRaft", but
  CMake did not find one.

  Could not find a package configuration file provided by "NuRaft" with any
  of the following names:

    NuRaftConfig.cmake
    nuraft-config.cmake

  Add the installation prefix of "NuRaft" to CMAKE_PREFIX_PATH or set
  "NuRaft_DIR" to a directory containing one of the above files.  If "NuRaft"
  provides a separate development package or SDK, be sure it has been
  installed.

-- Configuring incomplete, errors occurred!
tisonkun commented 1 year ago

It seems the config file locates in _deps/nuraft-build/NuRaftConfig.cmake but the find_package cannot find it.