Skip to content

Commit 6b78d4a

Browse files
committed
Modularize the whole project.
Switch to C++23 and enable import std;
1 parent a984b2c commit 6b78d4a

269 files changed

Lines changed: 16296 additions & 1188 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# CMakeList.txt : Top-level CMake project file, do global configuration
22
# and include sub-projects here.
33
#
4-
cmake_minimum_required(VERSION 3.25)
4+
cmake_minimum_required(VERSION 3.30)
55

6-
project(cpp-essence C CXX)
6+
# Set experimental flag to enable `import std` support from CMake.
7+
# This must be enabled before C++ language support.
8+
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "0e5b6991-d74f-4b3d-a41c-cf096e0b2508")
9+
set(CMAKE_CXX_MODULE_STD ON)
10+
11+
project(cpp-essence CXX)
712

813
option(ES_WITH_NET "Whether to include the net support." ON)
914
option(ES_WITH_JNI "Whether to include JNI support." ON)
@@ -29,6 +34,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
2934
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
3035
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
3136
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
37+
3238
set(ES_PUBLIC_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
3339

3440
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
@@ -56,15 +62,13 @@ include(CTest)
5662
include(FeatureTests.cmake)
5763
include(Dependencies.cmake)
5864

59-
add_subdirectory(src)
65+
set(ES_PACKAGING_TARGETS "")
66+
set(ES_PROJECT_VERSION 0.2.0)
6067

61-
if(EMSCRIPTEN)
62-
add_subdirectory(src/port/wasm)
63-
endif()
68+
add_subdirectory(src)
6469

6570
if(ES_WITH_JNI OR ANDROID)
6671
add_subdirectory(src/jni)
67-
add_subdirectory(src/port/jni)
6872
endif()
6973

7074
if(ES_WITH_TESTS)
@@ -78,3 +82,14 @@ endif()
7882
if(ES_WITH_TESTS)
7983
add_subdirectory(lang)
8084
endif()
85+
86+
include(ESPackaging)
87+
88+
message(STATUS "ES_PACKAGING_TARGETS: ${ES_PACKAGING_TARGETS}")
89+
90+
es_make_install_package(
91+
TARGETS ${ES_PACKAGING_TARGETS}
92+
PACKAGE_NAME CppEssence
93+
VERSION 0.2.0
94+
PATH_VARS CMAKE_INSTALL_PREFIX
95+
)

Dependencies.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ if(CMAKE_CROSSCOMPILING AND NOT EMSCRIPTEN)
7373
endif()
7474
endif()
7575

76+
es_make_install_third_party_library(
77+
nlohmann_json
78+
REQUIRED
79+
${runtime_args}
80+
PARALLEL_BUILD
81+
SYNC_BUILD_TYPE
82+
GENERATOR ${CMAKE_GENERATOR}
83+
CMAKE_ARGS
84+
-DJSON_BuildTests=OFF
85+
${extra_cmake_args}
86+
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/third-party/json
87+
INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
88+
)
89+
7690
es_make_install_third_party_library(
7791
fmt
7892
REQUIRED

cmake/ESLangCompiler.cmake

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function(es_add_lang_resources target_name)
3131
endif()
3232

3333
set(options PUBLIC INTERFACE PRIVATE)
34-
set(one_value_args NAME ROOT_DIRECTORY NAMESPACE)
34+
set(one_value_args NAME ROOT_DIRECTORY NAMESPACE RESULT_VARIABLE_LANG_TARGET_NAME)
3535
set(multi_value_args "")
3636
cmake_parse_arguments(PARSE_ARGV 1 ARG "${options}" "${one_value_args}" "${multi_value_args}")
3737
es_ensure_parameters(es_execute_process ARG NAME ROOT_DIRECTORY NAMESPACE)
@@ -41,6 +41,10 @@ function(es_add_lang_resources target_name)
4141
set(glob_pattern ${ARG_ROOT_DIRECTORY}/*.json)
4242
set(header_access_level PRIVATE)
4343

44+
if(ARG_RESULT_VARIABLE_LANG_TARGET_NAME)
45+
set(${ARG_RESULT_VARIABLE_LANG_TARGET_NAME} ${cmrc_target_name} PARENT_SCOPE)
46+
endif()
47+
4448
if(ARG_PUBLIC)
4549
set(header_access_level PUBLIC)
4650
endif()
@@ -98,26 +102,38 @@ function(es_add_lang_resources target_name)
98102
set(ES_USER_NAME ${ARG_NAME})
99103
set(ES_USER_NAMESPACE ${ARG_NAMESPACE})
100104

101-
set(header_file ${output_dir}/user_globalization_${ES_USER_NAME}.hpp)
102-
set(source_file ${output_dir}/user_globalization_${ES_USER_NAME}.cpp)
105+
set(base_dir ${output_dir})
106+
set(miu_source_file ${base_dir}/user_globalization_${ES_USER_NAME}.ixx)
107+
set(private_source_file ${base_dir}/user_globalization_${ES_USER_NAME}.cpp)
103108

104109
configure_file(
105-
${_es_lang_compiler_absolute_current_dir}/config/user_globalization.hpp.in
106-
${header_file}
110+
${_es_lang_compiler_absolute_current_dir}/config/user_globalization.ixx.in
111+
${miu_source_file}
107112
@ONLY
108113
)
109114

110115
configure_file(
111116
${_es_lang_compiler_absolute_current_dir}/config/user_globalization.cpp.in
112-
${source_file}
117+
${private_source_file}
113118
@ONLY
114119
)
115120

121+
get_target_property(target_type ${target_name} TYPE)
122+
123+
if("${target_type}" STREQUAL "EXECUTABLE")
124+
set(cxx_modules_access PRIVATE)
125+
elseif()
126+
set(cxx_modules_access PUBLIC)
127+
endif()
128+
116129
target_sources(
117130
${target_name}
131+
${cxx_modules_access}
132+
FILE_SET CXX_MODULES
133+
FILES ${miu_source_file}
134+
BASE_DIRS ${base_dir}
118135
PRIVATE
119-
${header_file}
120-
${source_file}
136+
${private_source_file}
121137
)
122138

123139
if(ES_WITH_EXPORTS)

0 commit comments

Comments
 (0)