Skip to content

Commit

Permalink
add cmake support for module with ctre::ctre
Browse files Browse the repository at this point in the history
  • Loading branch information
hanickadot committed May 16, 2024
1 parent e80e455 commit 2c4d93a
Showing 1 changed file with 86 additions and 27 deletions.
113 changes: 86 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.8.0)
cmake_minimum_required(VERSION 3.14.0)

if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.29.20240416")
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "0e5b6991-d74f-4b3d-a41c-cf096e0b2508")
Expand Down Expand Up @@ -31,38 +31,95 @@ cmake_dependent_option(CTRE_BUILD_PACKAGE_RPM
"Create RPM Package (${PROJECT_NAME})" ON
"CTRE_BUILD_PACKAGE;CTRE_RPMBUILD_FOUND" OFF)

add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

if (NOT CTRE_CXX_STANDARD)
set(CTRE_CXX_STANDARD 20)
endif()

target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_${CTRE_CXX_STANDARD})

if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.29.20240416")
add_library(${PROJECT_NAME}_module)
add_library(${PROJECT_NAME}::module ALIAS ${PROJECT_NAME}_module)

target_sources(${PROJECT_NAME}_module PUBLIC FILE_SET CXX_MODULES FILES ctre.cppm)

if (NOT CTRE_CXX_MODULE_STANDARD)
set(CTRE_CXX_MODULE_STANDARD ${CTRE_CXX_STANDARD})
option(CTRE_MODULE "build C++ module" OFF)

if(CTRE_MODULE)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.29.20240416")
add_library(${PROJECT_NAME})

target_sources(${PROJECT_NAME} PUBLIC FILE_SET CXX_MODULES TYPE CXX_MODULES FILES ctre.cppm)
target_sources(${PROJECT_NAME} PUBLIC FILE_SET HEADERS TYPE HEADERS FILES
include/ctll.hpp
include/ctre/functions.hpp
include/ctre/utility.hpp
include/ctre/utf8.hpp
include/ctre/evaluation.hpp
include/ctre/starts_with_anchor.hpp
include/ctre/pcre_actions.hpp
include/ctre/rotate.hpp
include/ctre/iterators.hpp
include/ctre/literals.hpp
include/ctre/return_type.hpp
include/ctre/find_captures.hpp
include/ctre/id.hpp
include/ctre/atoms_characters.hpp
include/ctre/actions/mode.inc.hpp
include/ctre/actions/characters.inc.hpp
include/ctre/actions/class.inc.hpp
include/ctre/actions/look.inc.hpp
include/ctre/actions/sequence.inc.hpp
include/ctre/actions/fusion.inc.hpp
include/ctre/actions/asserts.inc.hpp
include/ctre/actions/capture.inc.hpp
include/ctre/actions/named_class.inc.hpp
include/ctre/actions/backreference.inc.hpp
include/ctre/actions/options.inc.hpp
include/ctre/actions/atomic_group.inc.hpp
include/ctre/actions/set.inc.hpp
include/ctre/actions/hexdec.inc.hpp
include/ctre/actions/repeat.inc.hpp
include/ctre/actions/properties.inc.hpp
include/ctre/actions/boundaries.inc.hpp
include/ctre/operators.hpp
include/ctre/pcre.hpp
include/ctre/atoms_unicode.hpp
include/ctre/range.hpp
include/ctre/wrapper.hpp
include/ctre/first.hpp
include/ctre/flags_and_modes.hpp
include/ctre/atoms.hpp
include/unicode-db.hpp
include/unicode-db/unicode_interface.hpp
include/unicode-db/unicode-db.hpp
include/ctll/parser.hpp
include/ctll/actions.hpp
include/ctll/fixed_string.hpp
include/ctll/list.hpp
include/ctll/utilities.hpp
include/ctll/grammars.hpp
include/ctre.hpp
include/ctre-unicode.hpp
)

# we are using `import std;`
if (CTRE_CXX_STANDARD LESS 23)
set(CTRE_CXX_STANDARD 23)
endif()

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_${CTRE_CXX_STANDARD})
else()
message(FATAL_ERROR "unsupported cmake for c++ modules")
endif()
else()
add_library(${PROJECT_NAME} INTERFACE)

if (CTRE_CXX_MODULE_STANDARD LESS 23)
set(CTRE_CXX_MODULE_STANDARD 23)
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

if (NOT CTRE_CXX_STANDARD)
set(CTRE_CXX_STANDARD 20)
endif()

target_compile_features(${PROJECT_NAME}_module PUBLIC cxx_std_${CTRE_CXX_MODULE_STANDARD})
target_link_libraries(${PROJECT_NAME}_module PRIVATE ${PROJECT_NAME})
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_${CTRE_CXX_STANDARD})

install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-targets)
endif()

install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-targets)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

if (NOT CTRE_MODULE)

if (NOT EXISTS "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake.in")
file(WRITE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake.in [[
Expand Down Expand Up @@ -132,3 +189,5 @@ install(FILES "${PKG_CONFIG_FILE_NAME}"
list(APPEND CPACK_SOURCE_IGNORE_FILES /.git/ /build/ .gitignore .DS_Store)

include(CPack)

endif()

0 comments on commit 2c4d93a

Please sign in to comment.