Cleanup cmake

This commit is contained in:
Victor Zverovich 2024-06-14 08:04:11 -07:00
parent a245a8d4b9
commit 98dd673cf8

View File

@ -36,6 +36,12 @@ function(enable_module target)
endif () endif ()
endfunction() endfunction()
set(FMT_USE_CMAKE_MODULES FALSE)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.28 AND
CMAKE_GENERATOR STREQUAL "Ninja")
set(FMT_USE_CMAKE_MODULES TRUE)
endif ()
# Adds a library compiled with C++20 module support. # Adds a library compiled with C++20 module support.
# `enabled` is a CMake variables that specifies if modules are enabled. # `enabled` is a CMake variables that specifies if modules are enabled.
# If modules are disabled `add_module_library` falls back to creating a # If modules are disabled `add_module_library` falls back to creating a
@ -65,8 +71,9 @@ function(add_module_library name)
target_compile_definitions(${name} PRIVATE FMT_MODULE) target_compile_definitions(${name} PRIVATE FMT_MODULE)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.28 AND CMAKE_GENERATOR STREQUAL "Ninja") if (FMT_USE_CMAKE_MODULES)
target_sources(${name} PUBLIC FILE_SET fmt TYPE CXX_MODULES FILES ${sources}) target_sources(${name} PUBLIC FILE_SET fmt TYPE CXX_MODULES
FILES ${sources})
else() else()
# `std` is affected by CMake options and may be higher than C++20. # `std` is affected by CMake options and may be higher than C++20.
get_target_property(std ${name} CXX_STANDARD) get_target_property(std ${name} CXX_STANDARD)
@ -403,10 +410,9 @@ if (FMT_INSTALL)
set(INSTALL_TARGETS fmt fmt-header-only) set(INSTALL_TARGETS fmt fmt-header-only)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.28 AND CMAKE_GENERATOR STREQUAL "Ninja") set(INSTALL_FILE_SET)
if (FMT_USE_CMAKE_MODULES)
set(INSTALL_FILE_SET FILE_SET fmt DESTINATION "${FMT_INC_DIR}/fmt") set(INSTALL_FILE_SET FILE_SET fmt DESTINATION "${FMT_INC_DIR}/fmt")
else()
set(INSTALL_FILE_SET)
endif() endif()
# Install the library and headers. # Install the library and headers.