11cmake_minimum_required (VERSION 3.14)
2- project (NekoThreadPool VERSION 1.0 LANGUAGES CXX)
2+ project (NekoThreadPool VERSION 1.0.0 LANGUAGES CXX)
33
44# ================
55# === Config ====
66# ================
77
88option (NEKO_THREAD_POOL_BUILD_TESTS "Neko Thread Pool Build tests" ON )
99option (NEKO_THREAD_POOL_AUTO_FETCH_DEPS "Neko Thread Pool Automatically fetch dependencies" ON )
10+ option (NEKO_THREAD_POOL_ENABLE_MODULE "Neko Thread Pool Enable C++20 module" OFF )
1011
11- find_package (GTest CONFIG QUIET )
12+ find_package (NekoSchema QUIET )
13+ find_package (GTest QUIET )
1214
1315# Print configuration summary
1416message (STATUS "Start configuration Neko Thread Pool..." )
@@ -18,22 +20,31 @@ message(STATUS " - CMake version: ${CMAKE_VERSION}")
1820message (STATUS "" )
1921message (STATUS " - Neko Thread Pool Auto fetch deps: ${NEKO_THREAD_POOL_AUTO_FETCH_DEPS} " )
2022message (STATUS " - Neko Thread Pool Build tests: ${NEKO_THREAD_POOL_BUILD_TESTS} " )
23+ message (STATUS " - Neko Thread Pool Enable module: ${NEKO_THREAD_POOL_ENABLE_MODULE} " )
2124message (STATUS "" )
2225message (STATUS "Dependency summary:" )
26+ message (STATUS " - NekoSchema : ${NekoSchema_FOUND} version : ${NekoSchema_VERSION} " )
2327message (STATUS " - GTest : ${GTest_FOUND} version : ${GTest_VERSION} " )
2428message (STATUS "" )
2529
2630if (NEKO_THREAD_POOL_AUTO_FETCH_DEPS)
2731 include (FetchContent)
2832
29- FetchContent_Declare(
30- NekoSchema
31- GIT_REPOSITORY https://github.com/moehoshio/NekoSchema.git
32- GIT_TAG main
33- )
34- FetchContent_MakeAvailable(NekoSchema)
33+ if (NOT NekoSchema_FOUND)
34+ message (STATUS "NekoSchema not found; Neko Thread Pool Fetching NekoSchema..." )
35+
36+ FetchContent_Declare(
37+ NekoSchema
38+ GIT_REPOSITORY https://github.com/moehoshio/NekoSchema.git
39+ GIT_TAG main
40+ )
41+ if (NEKO_THREAD_POOL_ENABLE_MODULE)
42+ set (NEKO_SCHEMA_ENABLE_MODULE ON CACHE BOOL "" FORCE)
43+ endif ()
44+ FetchContent_MakeAvailable(NekoSchema)
45+ endif ()
3546
36- if (NOT GTEST_FOUND AND NEKO_THREAD_POOL_BUILD_TESTS)
47+ if (NOT GTest_FOUND AND NEKO_THREAD_POOL_BUILD_TESTS)
3748 message (STATUS "GTest not found; Neko Thread Pool Fetching GoogleTest..." )
3849
3950 FetchContent_Declare(
@@ -65,6 +76,52 @@ target_include_directories(NekoThreadPool INTERFACE
6576target_link_libraries (NekoThreadPool INTERFACE NekoSchema)
6677target_compile_features (NekoThreadPool INTERFACE cxx_std_20)
6778
79+ # ================
80+ # = C++20 Module =
81+ # ================
82+
83+ if (NEKO_THREAD_POOL_ENABLE_MODULE)
84+ message (STATUS "NekoThreadPool C++20 module enabled (NEKO_THREAD_POOL_ENABLE_MODULE=ON)" )
85+
86+ # Check CMake version for module support
87+ if (CMAKE_VERSION VERSION_LESS 3.28)
88+ message (WARNING "CMake 3.28+ is recommended for full C++20 module support" )
89+ endif ()
90+
91+ # Create module library
92+ add_library (NekoThreadPool_module)
93+ add_library (Neko::ThreadPool::Module ALIAS NekoThreadPool_module)
94+
95+ target_sources (NekoThreadPool_module
96+ PUBLIC
97+ FILE_SET CXX_MODULES FILES
98+ ${CMAKE_CURRENT_SOURCE_DIR} /include /neko/thread/neko.thread.cppm
99+ )
100+
101+ target_compile_features (NekoThreadPool_module PUBLIC cxx_std_20)
102+
103+ # Link dependencies (needed for module compilation)
104+ target_link_libraries (NekoThreadPool_module PUBLIC NekoSchema_module)
105+
106+ # Compiler-specific module flags
107+ if (MSVC )
108+ target_compile_options (NekoThreadPool_module PUBLIC /experimental:module)
109+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
110+ target_compile_options (NekoThreadPool_module PUBLIC -fmodules-ts)
111+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
112+ target_compile_options (NekoThreadPool_module PUBLIC -fmodules)
113+ endif ()
114+
115+ # Module still needs access to the include directory for the headers
116+ target_include_directories (NekoThreadPool_module PUBLIC
117+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /include >
118+ $<INSTALL_INTERFACE:include >
119+ )
120+
121+ else ()
122+ message (STATUS "NekoThreadPool C++20 module disabled (NEKO_THREAD_POOL_ENABLE_MODULE=OFF)" )
123+ endif ()
124+
68125# ================
69126# ==== Tests =====
70127# ================
@@ -85,9 +142,71 @@ if(NEKO_THREAD_POOL_BUILD_TESTS)
85142
86143 include (GoogleTest)
87144 gtest_discover_tests(threadPool_test)
145+
146+ # Module-based tests (if module is enabled)
147+ if (NEKO_THREAD_POOL_ENABLE_MODULE)
148+ message (STATUS "Neko Thread Pool module tests enabled" )
149+ add_executable (threadPool_module_test tests/threadPool_module_test.cpp)
150+ target_link_libraries (threadPool_module_test PRIVATE NekoSchema_module NekoThreadPool_module GTest::gtest GTest::gtest_main)
151+ target_compile_features (threadPool_module_test PRIVATE cxx_std_20)
152+ gtest_discover_tests(threadPool_module_test)
153+ endif ()
88154
89155else ()
90156 message (STATUS "NekoThreadPool tests disabled (NEKO_THREAD_POOL_BUILD_TESTS=OFF)" )
91157endif ()
92158
159+
160+ # ================
161+ # == Install =====
162+ # ================
163+
164+ include (GNUInstallDirs)
165+ include (CMakePackageConfigHelpers)
166+
167+ # Install headers
168+ install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} /include /
169+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
170+ FILES_MATCHING
171+ PATTERN "*.hpp"
172+ PATTERN "*.cppm"
173+ )
174+
175+ # Install targets
176+ install (TARGETS NekoThreadPool
177+ EXPORT NekoThreadPoolTargets
178+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
179+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
180+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
181+ INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
182+ FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
183+ )
184+
185+ # Install export targets
186+ install (EXPORT NekoThreadPoolTargets
187+ FILE NekoThreadPoolTargets.cmake
188+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/NekoThreadPool
189+ )
190+
191+ # Create and install Config file
192+ configure_package_config_file(
193+ ${CMAKE_CURRENT_SOURCE_DIR} /cmake/NekoThreadPoolConfig.cmake.in
194+ ${CMAKE_CURRENT_BINARY_DIR} /NekoThreadPoolConfig.cmake
195+ INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/NekoThreadPool
196+ )
197+
198+ # Create and install Version file
199+ write_basic_package_version_file(
200+ ${CMAKE_CURRENT_BINARY_DIR} /NekoThreadPoolConfigVersion.cmake
201+ VERSION ${PROJECT_VERSION}
202+ COMPATIBILITY SameMajorVersion
203+ ARCH_INDEPENDENT
204+ )
205+
206+ install (FILES
207+ ${CMAKE_CURRENT_BINARY_DIR} /NekoThreadPoolConfig.cmake
208+ ${CMAKE_CURRENT_BINARY_DIR} /NekoThreadPoolConfigVersion.cmake
209+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/NekoThreadPool
210+ )
211+
93212message (STATUS "Neko Thread Pool End of configuration" )
0 commit comments