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

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

Open
BerengerBerthoul opened this issue Mar 6, 2023 · 1 comment

Comments

@BerengerBerthoul
Copy link

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
Copy link
Owner

Tessil commented Mar 31, 2023

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 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants