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

Use built-in CMake support when CMake >= 3.28 #25

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.11)
cmake_minimum_required(VERSION 3.11...3.28)
project(HELLO CXX)

# Include module library
Expand Down
10 changes: 7 additions & 3 deletions modules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function(add_module_library name)
target_compile_options(${name} PUBLIC -fmodules-ts)
endif ()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_VERSION VERSION_LESS 3.28)
# `std` is affected by CMake options and may be higher than C++20.
# Clang does not support c++23/c++26 names, so replace it with 2b.
get_target_property(std ${name} CXX_STANDARD)
Expand Down Expand Up @@ -203,9 +203,13 @@ function(add_module_library name)
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()
Comment on lines +206 to +210
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to restructure the code to check CMake version in one place instead of three, something like:

if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.28)
    target_sources(${name} PUBLIC FILE_SET fmt_module TYPE CXX_MODULES FILES ${sources})
    return()
endif ()

earlier in this function

Also note spaces before opening parentheses in statement-like constructs like if.


if (MSVC)
if (MSVC AND CMAKE_VERSION VERSION_LESS 3.28)
foreach (src ${sources})
# Compile file as a module interface.
set_source_files_properties(${src} PROPERTIES COMPILE_FLAGS /interface)
Expand Down