mirror of
https://github.com/fmtlib/fmt.git
synced 2026-08-03 20:14:20 +02:00
a749e9d880
export() was scoped inside if (FMT_INSTALL), so projects that pull in fmt via add_subdirectory()/FetchContent without installing it had no way to get the exported fmt::* targets. If such a project tries to export its own targets that depend on fmt, CMake fails with "target ... requires target fmt that is not in any export set". Hoist the target list/export name and the export() call itself out of the FMT_INSTALL guard so the build-tree export file is always generated; the install()-only pieces (config/version files, pkgconfig, install(EXPORT ...)) stay behind the guard and installed behavior is unchanged. Fixes #4806 Co-authored-by: flink <w741069229@gmail.com>
27 lines
954 B
CMake
27 lines
954 B
CMake
cmake_minimum_required(VERSION 3.8...3.25)
|
|
|
|
project(fmt-test CXX)
|
|
|
|
add_subdirectory(../.. fmt)
|
|
|
|
add_executable(library-test main.cc)
|
|
target_include_directories(library-test PUBLIC SYSTEM .)
|
|
target_compile_options(library-test PRIVATE ${PEDANTIC_COMPILE_FLAGS})
|
|
target_link_libraries(library-test fmt::fmt)
|
|
|
|
if (TARGET fmt::fmt-header-only)
|
|
add_executable(header-only-test main.cc)
|
|
target_include_directories(header-only-test PUBLIC SYSTEM .)
|
|
target_compile_options(header-only-test PRIVATE ${PEDANTIC_COMPILE_FLAGS})
|
|
target_link_libraries(header-only-test fmt::fmt-header-only)
|
|
endif ()
|
|
|
|
# Test that a target publicly depending on fmt can itself be exported even
|
|
# though fmt is added via add_subdirectory and FMT_INSTALL is off (#4806).
|
|
add_library(export-test STATIC export-lib.cc)
|
|
target_link_libraries(export-test PUBLIC fmt::fmt)
|
|
export(
|
|
TARGETS export-test
|
|
NAMESPACE test::
|
|
FILE ${CMAKE_CURRENT_BINARY_DIR}/export-test-targets.cmake)
|