cpm-cmake / CPM.cmake

📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.
MIT License
3.08k stars 188 forks source link

cpm_add_subdirectory(fmt ... EXCLUDE) must be OFF or fmt targets will NOT be installed! #444

Open ClausKlein opened 1 year ago

ClausKlein commented 1 year ago

see https://discourse.cmake.org/t/is-install-of-a-target-with-exclude-from-all-true-really-undefined/5666/6 and https://github.com/ClausKlein/ModernCmakeStarter/pull/5

TheLartians commented 1 year ago

Not sure I understand. Is this a CPM problem or an issue with the starter project?

ClausKlein commented 1 year ago

A CPM.cmake feature: EXCLUDE_FROM_ALL is default set!

NOTE: EXCLUDE_FROM_ALL must be OFF or fmt target will NOT be installed!

option(FMT_INSTALL "create an installable target" YES)
CPMAddPackage(
  NAME fmt
  GIT_TAG 9.1.0
  GITHUB_REPOSITORY fmtlib/fmt
  EXCLUDE_FROM_ALL NO
  # TODO DOWNLOAD_ONLY YES
  SYSTEM YES # used in case of cmake v3.25
)
if(fmt_SOURCE_DIR) # TODO AND NOT TARGET fmt::fmt)
  # TODO add_subdirectory(${fmt_SOURCE_DIR} fmt SYSTEM)
  message(TRACE "add_subdirectory(${fmt_SOURCE_DIR} fmt SYSTEM)")
  target_disable_clang_tidy(fmt)
  check_system_property(${fmt_SOURCE_DIR})
endif()

# ...

packageProject(
  NAME ${PROJECT_NAME}
  VERSION ${PROJECT_VERSION} NAMESPACE ${PROJECT_NAME}
  BINARY_DIR ${PROJECT_BINARY_DIR}
  INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
  INCLUDE_DESTINATION include/${PROJECT_NAME}
  VERSION_HEADER ${VERSION_HEADER_LOCATION} DISABLE_VERSION_SUFFIX YES
  COMPATIBILITY SameMajorVersion
  DEPENDENCIES "fmt 9.1.0"
)

... but the exported config set is than not useable!