-
-
Notifications
You must be signed in to change notification settings - Fork 73
Description
Is your feature request related to a problem? Please describe.
I'm using libtcod with CMake's FetchContent instead of vcpkg. Since version 3.24, CMake has support for OVERRIDE_FIND_PACKAGE, which allows for transitive dependencies in subprojects to resolve correctly without needing vcpkg or other package managers.
This almost works with libtcod, but OVERRIDE_FIND_PACKAGE doesn't seem to work for install(EXPORT) targets, failing with this unfortunate error:
CMake Error: install(EXPORT "libtcodTargets" ...) includes target "libtcod" which requires target "SDL2" that is not in any export set.
CMake Error: install(EXPORT "libtcodTargets" ...) includes target "libtcod" which requires target "zlib" that is not in any export set.
I've been using this terrible hack to get around this:
set(LIBTCOD_LODEPNG "vendored" CACHE STRING "")
set(LIBTCOD_UTF8PROC "vendored" CACHE STRING "")
set(LIBTCOD_STB "vendored" CACHE STRING "")
FetchContent_Declare(libtcod GIT_REPOSITORY https://github.com/libtcod/libtcod GIT_TAG 1.24.0)
FetchContent_GetProperties(libtcod)
if(NOT libtcod_POPULATED)
FetchContent_Populate(libtcod) # Fetch libtcod
# Delete libtcod's src/CMakeLists...
file(REMOVE ${libtcod_SOURCE_DIR}/src/CMakeLists.txt)
# and replace it with a custom, patched CMakeLists.txt with the install() targets removed
configure_file(libtcod_patch.txt ${libtcod_SOURCE_DIR}/src/CMakeLists.txt COPYONLY)
add_subdirectory(${libtcod_SOURCE_DIR} ${libtcod_BINARY_DIR}) # Configure libtcod
endif()This works, but requires manually updating the patched CMakeLists.txt if it ever changes.
Describe the solution you'd like
A CMake option to disable the install targets in src/CMakeLists.txt. Something like:
# CMakeLists.txt, line 49
set(LIBTCOD_SAMPLES OFF CACHE BOOL "Build sources from the samples directory.")
set(LIBTCOD_TESTS OFF CACHE BOOL "Build unit tests.")
set(LIBTCOD_INSTALL ON CACHE BOOL "Enable install targets.")
# src/CMakeLists.txt, line 139
if(LIBTCOD_INSTALL)
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
RUNTIME LIBRARY ARCHIVE
COMPONENT Library
)
# other install targets
endif()Describe alternatives you've considered
- I'm currently patching libtcod's CMakeLists.txt after FetchContent downloads it, but this is annoying and unreliable across versions.
- I could just use vcpkg, libtcod's recommended package manager, but vcpkg has problems (and I don't really like it).
Additional context
Many other open source libraries that use CMake support disabling their install targets, such as zlib and SDL.