Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for CMake 3.28 C++ module features #3679

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.8...3.26)
cmake_minimum_required(VERSION 3.8...3.28)

# Fallback for using newer policies on CMake <3.12.
if(${CMAKE_VERSION} VERSION_LESS 3.12)
Expand Down Expand Up @@ -26,7 +26,7 @@ endfunction()

# DEPRECATED! Should be merged into add_module_library.
function(enable_module target)
if (MSVC)
if (MSVC AND CMAKE_VERSION VERSION_LESS 3.28)
set(BMI ${CMAKE_CURRENT_BINARY_DIR}/${target}.ifc)
target_compile_options(${target}
PRIVATE /interface /ifcOutput ${BMI}
Expand Down Expand Up @@ -65,7 +65,7 @@ function(add_module_library name)
# `std` is affected by CMake options and may be higher than C++20.
get_target_property(std ${name} CXX_STANDARD)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_VERSION VERSION_LESS 3.28)
set(pcms)
foreach (src ${sources})
get_filename_component(pcm ${src} NAME_WE)
Expand Down Expand Up @@ -103,7 +103,11 @@ function(add_module_library name)
DEPENDS ${pcm})
endforeach ()
endif ()
target_sources(${name} PRIVATE ${sources})
if(CMAKE_VERSION VERSION_LESS 3.28)
target_sources(${name} PRIVATE ${sources})
else()
target_sources(${name} PUBLIC FILE_SET fmt_module TYPE CXX_MODULES FILES ${sources})
endif()
endfunction()

include(CMakeParseArguments)
Expand Down Expand Up @@ -384,8 +388,14 @@ if (FMT_INSTALL)
LIBRARY DESTINATION ${FMT_LIB_DIR}
ARCHIVE DESTINATION ${FMT_LIB_DIR}
PUBLIC_HEADER DESTINATION "${FMT_INC_DIR}/fmt"
FILE_SET fmt_module DESTINATION "${FMT_LIB_DIR}/cxx/miu"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

if(FMT_MODULE AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.28)
#Install format.cc and os.cc which are #included by the fmt.cc module interface file
install(FILES src/format.cc src/os.cc DESTINATION "${FMT_LIB_DIR}/cxx/miu/src")
endif()

# Use a namespace because CMake provides better diagnostics for namespaced
# imported targets.
export(TARGETS ${INSTALL_TARGETS} NAMESPACE fmt::
Expand Down