Skip to content

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

@BerengerBerthoul

Description

@BerengerBerthoul

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions