Skip to content

Commit c8d157d

Browse files
committed
Use an object library for using fmt in static builds
1 parent 0a15b37 commit c8d157d

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

CMakeLists.txt

+2-10
Original file line numberDiff line numberDiff line change
@@ -1392,16 +1392,8 @@ add_custom_target(clang-tidy-check ${CLANG_TIDY_EXECUTABLE} -format-style=file -
13921392
if(LIBTYPE STREQUAL "STATIC")
13931393
add_library(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS})
13941394
target_compile_definitions(${IMPL_TARGET} PUBLIC AL_LIBTYPE_STATIC)
1395-
# Instead of "linking" with the fmt-header-only interface target, which
1396-
# puts an unwanted dependency on the target when exporting/installing, just
1397-
# copy the properties.
1398-
target_compile_definitions(${IMPL_TARGET} PRIVATE
1399-
$<TARGET_PROPERTY:alsoft::fmt-header-only,INTERFACE_COMPILE_DEFINITIONS>)
1400-
target_include_directories(${IMPL_TARGET} PRIVATE
1401-
$<TARGET_PROPERTY:alsoft::fmt-header-only,INTERFACE_INCLUDE_DIRECTORIES>)
1402-
target_compile_options(${IMPL_TARGET} PRIVATE
1403-
$<TARGET_PROPERTY:alsoft::fmt-header-only,INTERFACE_COMPILE_OPTIONS>)
1404-
target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1395+
target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB}
1396+
$<BUILD_LOCAL_INTERFACE:alsoft::fmt-objects>)
14051397

14061398
if(WIN32)
14071399
# This option is for static linking OpenAL Soft into another project

fmt-11.0.2/CMakeLists.txt

+27-14
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ function(join result_var)
1717
set(${result_var} "${result}" PARENT_SCOPE)
1818
endfunction()
1919

20-
set(FMT_USE_CMAKE_MODULES FALSE)
21-
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.28 AND
22-
CMAKE_GENERATOR STREQUAL "Ninja")
23-
set(FMT_USE_CMAKE_MODULES TRUE)
24-
endif ()
25-
2620
include(CMakeParseArguments)
2721

2822
project(ALSOFT_FMT CXX)
@@ -42,10 +36,6 @@ message(STATUS "{fmt} version: ${FMT_VERSION}")
4236

4337
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
4438

45-
if (NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
46-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
47-
endif ()
48-
4939
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
5040
"${CMAKE_CURRENT_SOURCE_DIR}/support/cmake")
5141

@@ -60,6 +50,8 @@ function(add_headers VAR)
6050
set(${VAR} ${headers} PARENT_SCOPE)
6151
endfunction()
6252

53+
set(ALSOFT_FMT_DEBUG_POSTFIX d CACHE STRING "Debug library postfix.")
54+
6355
# Define the fmt library, its includes and the needed defines.
6456
add_headers(FMT_HEADERS args.h base.h chrono.h color.h compile.h core.h format.h
6557
format-inl.h os.h ostream.h printf.h ranges.h std.h
@@ -78,15 +70,13 @@ endif ()
7870
target_include_directories(alsoft.fmt PUBLIC
7971
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
8072

81-
set(ALSOFT_FMT_DEBUG_POSTFIX d CACHE STRING "Debug library postfix.")
82-
8373
set_target_properties(alsoft.fmt PROPERTIES ${ALSOFT_STD_VERSION_PROPS}
8474
VERSION ${FMT_VERSION} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR}
85-
PUBLIC_HEADER "${FMT_HEADERS}"
8675
DEBUG_POSTFIX "${ALSOFT_FMT_DEBUG_POSTFIX}"
8776
POSITION_INDEPENDENT_CODE TRUE
8877
C_VISIBILITY_PRESET hidden
8978
CXX_VISIBILITY_PRESET hidden
79+
EXCLUDE_FROM_ALL TRUE
9080

9181
# Workaround for Visual Studio 2017:
9282
# Ensure the .pdb is created with the same name and in the same directory
@@ -96,12 +86,35 @@ set_target_properties(alsoft.fmt PROPERTIES ${ALSOFT_STD_VERSION_PROPS}
9686
COMPILE_PDB_NAME "fmt"
9787
COMPILE_PDB_NAME_DEBUG "fmt${ALSOFT_FMT_DEBUG_POSTFIX}")
9888

99-
add_library(alsoft.fmt-header-only INTERFACE)
89+
90+
91+
add_library(alsoft.fmt-objects OBJECT ${FMT_SOURCES} ${FMT_HEADERS} README.md ChangeLog.md)
92+
add_library(alsoft::fmt-objects ALIAS alsoft.fmt-objects)
93+
94+
if (cxx_std_11 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
95+
target_compile_features(alsoft.fmt-objects PUBLIC cxx_std_11)
96+
else ()
97+
message(WARNING "Feature cxx_std_11 is unknown for the CXX compiler")
98+
endif ()
99+
100+
target_include_directories(alsoft.fmt-objects PUBLIC
101+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
102+
103+
set_target_properties(alsoft.fmt-objects PROPERTIES ${ALSOFT_STD_VERSION_PROPS}
104+
POSITION_INDEPENDENT_CODE TRUE
105+
C_VISIBILITY_PRESET hidden
106+
CXX_VISIBILITY_PRESET hidden
107+
EXCLUDE_FROM_ALL TRUE)
108+
109+
110+
111+
add_library(alsoft.fmt-header-only INTERFACE EXCLUDE_FROM_ALL)
100112
add_library(alsoft::fmt-header-only ALIAS alsoft.fmt-header-only)
101113

102114
if (MSVC)
103115
# Unicode support requires compiling with /utf-8.
104116
target_compile_options(alsoft.fmt PUBLIC $<$<COMPILE_LANGUAGE:CXX>:/utf-8>)
117+
target_compile_options(alsoft.fmt-objects PUBLIC $<$<COMPILE_LANGUAGE:CXX>:/utf-8>)
105118
target_compile_options(alsoft.fmt-header-only INTERFACE $<$<COMPILE_LANGUAGE:CXX>:/utf-8>)
106119
endif ()
107120

0 commit comments

Comments
 (0)