Tessil / robin-map

C++ implementation of a fast hash map and hash set using robin hood hashing
MIT License
1.28k stars 118 forks source link

CMake: not exporting if IS_SUBPROJECT breaks use through FetchContent #66

Open BerengerBerthoul opened 1 year ago

BerengerBerthoul commented 1 year ago

PR #60 added the follwing lines to CMakeLists.txt :

set(IS_SUBPROJECT TRUE)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
  set(IS_SUBPROJECT FALSE)
endif()

# Installation (only compatible with CMake version >= 3.3)
if(NOT IS_SUBPROJECT AND ${CMAKE_VERSION} VERSION_GREATER "3.2")

If I include robin-map in my project with FetchContent, like this :

FetchContent_Declare(
  robin-map
  GIT_REPOSITORY https://github.com/tessil/robin-map.git
  GIT_TAG        master
)
FetchContent_MakeAvailable(robin-map)

Then add a public dependency :

target_link_libraries(${PROJECT_NAME}
  INTERFACE
    tsl::robin_map
)

I now get the following message :

CMake Error: install(EXPORT "myLibTargets" ...) includes target "myLib" which requires target "robin_map" that is not in any export set.

Issue #59 mentionned Catch2 as a way to implement the change in #60 but I think the reason it works in Catch2 is because Catch2 is included as part of the private interface of executables (since it is used to produce unit test executables, not libraries)

Anyway, a way to correct #60 would be to let the user decide whether he wants to install or not. In fmt, they use the FMT_INSTALL option.

Tessil commented 1 year ago

Hi,

Thank you for the report and sorry for the delay.

I created a PR to address the issue if you could take a look. It's similar to the SDL project https://github.com/libsdl-org/SDL/blob/b6ae281e97c4e4680a9010e7e13fe1222c0bcd4b/CMakeLists.txt#L367 though I use a ENABLE variable instead of a DISABLE one. The change keeps compatibility with #59 .