From 97215b1c53c13e8c147775512737dcc7d1c124e9 Mon Sep 17 00:00:00 2001 From: MeanSquaredError <35379301+MeanSquaredError@users.noreply.github.com> Date: Sat, 27 Jun 2026 07:56:40 +0300 Subject: [PATCH 1/5] CMake: Simplify the testing targets. Fix linking of C++20 module object files. --- tests/core/CMakeLists.txt | 35 ++++++++++++------------- tests/mysql/CMakeLists.txt | 39 ++++++++++++++-------------- tests/postgresql/CMakeLists.txt | 35 ++++++++++++------------- tests/sqlite3/CMakeLists.txt | 46 ++++++++++++++++----------------- 4 files changed, 75 insertions(+), 80 deletions(-) diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index cf7eac9d..4229f3e4 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -23,27 +23,26 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. if(BUILD_WITH_MODULES) - add_library(sqlpp23.test.core.tables.module) - target_sources(sqlpp23.test.core.tables.module - PUBLIC - FILE_SET all_my_modules TYPE CXX_MODULES FILES - modules/sqlpp23.test.core.tables.cppm - ) - target_link_libraries(sqlpp23.test.core.tables.module PUBLIC sqlpp23::core_module) + set(LIB_TYPE) + set(LIB_PROP_SCOPE PUBLIC) +else() + set(LIB_TYPE INTERFACE) + set(LIB_PROP_SCOPE INTERFACE) endif() - -add_library(sqlpp23_core_testing INTERFACE) -target_include_directories(sqlpp23_core_testing INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) - +add_library(sqlpp23_core_testing ${LIB_TYPE}) +target_include_directories(sqlpp23_core_testing ${LIB_PROP_SCOPE} ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(sqlpp23_core_testing ${LIB_PROP_SCOPE} sqlpp23_testing) if(BUILD_WITH_MODULES) - target_link_libraries(sqlpp23_core_testing INTERFACE - sqlpp23_testing - sqlpp23::mock_db_module - sqlpp23.test.core.tables.module + target_sources( + sqlpp23_core_testing + PUBLIC + FILE_SET CXX_MODULES FILES modules/sqlpp23.test.core.tables.cppm ) -else() - target_link_libraries(sqlpp23_core_testing INTERFACE - sqlpp23_testing + target_link_libraries( + sqlpp23_core_testing + PUBLIC + sqlpp23::core_module + sqlpp23::mock_db_module ) endif() diff --git a/tests/mysql/CMakeLists.txt b/tests/mysql/CMakeLists.txt index 828b1306..4cd61365 100644 --- a/tests/mysql/CMakeLists.txt +++ b/tests/mysql/CMakeLists.txt @@ -22,33 +22,32 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +find_package(Threads REQUIRED) if(BUILD_WITH_MODULES) - add_library(sqlpp23.test.mysql.tables.module) - target_sources(sqlpp23.test.mysql.tables.module - PUBLIC - FILE_SET all_my_modules TYPE CXX_MODULES FILES - modules/sqlpp23.test.mysql.tables.cppm - ) - target_link_libraries(sqlpp23.test.mysql.tables.module PUBLIC sqlpp23::core_module) + set(LIB_TYPE) + set(LIB_PROP_SCOPE PUBLIC) +else() + set(LIB_TYPE INTERFACE) + set(LIB_PROP_SCOPE INTERFACE) endif() - -find_package(Threads REQUIRED) -add_library(sqlpp23_mysql_testing INTERFACE) -target_include_directories(sqlpp23_mysql_testing INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) - +add_library(sqlpp23_mysql_testing ${LIB_TYPE}) +target_include_directories(sqlpp23_mysql_testing ${LIB_PROP_SCOPE} ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(sqlpp23_mysql_testing ${LIB_PROP_SCOPE} sqlpp23_testing) if(BUILD_WITH_MODULES) - target_link_libraries(sqlpp23_mysql_testing INTERFACE - sqlpp23_testing - sqlpp23::mysql_module - sqlpp23.test.mysql.tables.module + target_sources( + sqlpp23_mysql_testing + PUBLIC + FILE_SET CXX_MODULES FILES modules/sqlpp23.test.mysql.tables.cppm ) -else() - target_link_libraries(sqlpp23_mysql_testing INTERFACE - sqlpp23_testing + target_link_libraries( + sqlpp23_mysql_testing + PUBLIC + sqlpp23::core_module + sqlpp23::mysql_module ) endif() if (MSVC) - target_compile_options(sqlpp23_mysql_testing INTERFACE -DNOMINMAX) + target_compile_options(sqlpp23_mysql_testing PUBLIC -DNOMINMAX) endif () add_subdirectory(asserts) diff --git a/tests/postgresql/CMakeLists.txt b/tests/postgresql/CMakeLists.txt index d4eff8dd..4e488744 100644 --- a/tests/postgresql/CMakeLists.txt +++ b/tests/postgresql/CMakeLists.txt @@ -23,27 +23,26 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. if(BUILD_WITH_MODULES) - add_library(sqlpp23.test.postgresql.tables.module) - target_sources(sqlpp23.test.postgresql.tables.module - PUBLIC - FILE_SET all_my_modules TYPE CXX_MODULES FILES - modules/sqlpp23.test.postgresql.tables.cppm - ) - target_link_libraries(sqlpp23.test.postgresql.tables.module PUBLIC sqlpp23::core_module) + set(LIB_TYPE) + set(LIB_PROP_SCOPE PUBLIC) +else() + set(LIB_TYPE INTERFACE) + set(LIB_PROP_SCOPE INTERFACE) endif() - -add_library(sqlpp23_postgresql_testing INTERFACE) -target_include_directories(sqlpp23_postgresql_testing INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) - +add_library(sqlpp23_postgresql_testing ${LIB_TYPE}) +target_include_directories(sqlpp23_postgresql_testing ${LIB_PROP_SCOPE} ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(sqlpp23_postgresql_testing ${LIB_PROP_SCOPE} sqlpp23_testing) if(BUILD_WITH_MODULES) - target_link_libraries(sqlpp23_postgresql_testing INTERFACE - sqlpp23_testing - sqlpp23::postgresql_module - sqlpp23.test.postgresql.tables.module + target_sources( + sqlpp23_postgresql_testing + PUBLIC + FILE_SET CXX_MODULES FILES modules/sqlpp23.test.postgresql.tables.cppm ) -else() - target_link_libraries(sqlpp23_postgresql_testing INTERFACE - sqlpp23_testing + target_link_libraries( + sqlpp23_postgresql_testing + PUBLIC + sqlpp23::core_module + sqlpp23::postgresql_module ) endif() diff --git a/tests/sqlite3/CMakeLists.txt b/tests/sqlite3/CMakeLists.txt index 9cffd503..084b8f9c 100644 --- a/tests/sqlite3/CMakeLists.txt +++ b/tests/sqlite3/CMakeLists.txt @@ -23,37 +23,35 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. if(BUILD_WITH_MODULES) - add_library(sqlpp23.test.sqlite3.tables.module) - target_sources(sqlpp23.test.sqlite3.tables.module - PUBLIC - FILE_SET all_my_modules TYPE CXX_MODULES FILES - modules/sqlpp23.test.sqlite3.tables.cppm - ) - target_link_libraries(sqlpp23.test.sqlite3.tables.module PUBLIC sqlpp23::core_module) + set(LIB_TYPE) + set(LIB_PROP_SCOPE PUBLIC) +else() + set(LIB_TYPE INTERFACE) + set(LIB_PROP_SCOPE INTERFACE) endif() - -add_library(sqlpp23_sqlite3_testing INTERFACE) -target_include_directories(sqlpp23_sqlite3_testing INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) - +add_library(sqlpp23_sqlite3_testing ${LIB_TYPE}) +target_include_directories(sqlpp23_sqlite3_testing ${LIB_PROP_SCOPE} ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(sqlpp23_sqlite3_testing ${LIB_PROP_SCOPE} sqlpp23_testing) if(BUILD_WITH_MODULES) - target_link_libraries(sqlpp23_sqlite3_testing INTERFACE - sqlpp23_testing - sqlpp23::sqlite3_module - sqlpp23.test.sqlite3.tables.module + target_sources( + sqlpp23_sqlite3_testing + PUBLIC + FILE_SET CXX_MODULES FILES modules/sqlpp23.test.sqlite3.tables.cppm ) -else() - target_link_libraries(sqlpp23_sqlite3_testing INTERFACE - sqlpp23_testing + target_link_libraries( + sqlpp23_sqlite3_testing PUBLIC + sqlpp23::core_module + sqlpp23::sqlite3_module ) endif() function(sqlpp_slite3_test_add_target_link_libraries name) -target_link_libraries(${name} PRIVATE sqlpp23_testing sqlpp23_sqlite3_testing) -if (BUILD_SQLCIPHER_CONNECTOR) - target_link_libraries(${name} PRIVATE sqlpp23::sqlcipher) -else() - target_link_libraries(${name} PRIVATE sqlpp23::sqlite3) -endif() + target_link_libraries(${name} PRIVATE sqlpp23_testing sqlpp23_sqlite3_testing) + if (BUILD_SQLCIPHER_CONNECTOR) + target_link_libraries(${name} PRIVATE sqlpp23::sqlcipher) + else() + target_link_libraries(${name} PRIVATE sqlpp23::sqlite3) + endif() endfunction() add_subdirectory(asserts) From c4d93cbfeba5d9fe42cd2d21ab3811acf4f9d010 Mon Sep 17 00:00:00 2001 From: MeanSquaredError <35379301+MeanSquaredError@users.noreply.github.com> Date: Sat, 27 Jun 2026 12:30:40 +0300 Subject: [PATCH 2/5] CMake: Rename cmake/Sqlpp23TargetHelper.cmake -> cmake/sqlpp23_target_helper.cmake --- CMakeLists.txt | 2 +- .../{Sqlpp23TargetHelper.cmake => sqlpp23_target_helper.cmake} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename cmake/{Sqlpp23TargetHelper.cmake => sqlpp23_target_helper.cmake} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 168c0dbf..3a00eb10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules) include(GNUInstallDirs) include(CTest) -include(Sqlpp23TargetHelper) +include(sqlpp23_target_helper) option(BUILD_MYSQL_CONNECTOR "Build MySQL Connector" OFF) option(BUILD_MARIADB_CONNECTOR "Build MariaDB Connector" OFF) diff --git a/cmake/Sqlpp23TargetHelper.cmake b/cmake/sqlpp23_target_helper.cmake similarity index 100% rename from cmake/Sqlpp23TargetHelper.cmake rename to cmake/sqlpp23_target_helper.cmake From d49082fce35ea1ab30b81d82b4166fc1b1505899 Mon Sep 17 00:00:00 2001 From: MeanSquaredError <35379301+MeanSquaredError@users.noreply.github.com> Date: Sat, 27 Jun 2026 17:00:39 +0300 Subject: [PATCH 3/5] CMake: Move the common code that creates test targets into add_testing_target() --- cmake/sqlpp23_testing_helper.cmake | 65 ++++++++++++++++++++++++++++++ tests/core/CMakeLists.txt | 26 ++---------- tests/mysql/CMakeLists.txt | 30 +++----------- tests/postgresql/CMakeLists.txt | 26 ++---------- tests/sqlite3/CMakeLists.txt | 25 ++---------- 5 files changed, 80 insertions(+), 92 deletions(-) create mode 100644 cmake/sqlpp23_testing_helper.cmake diff --git a/cmake/sqlpp23_testing_helper.cmake b/cmake/sqlpp23_testing_helper.cmake new file mode 100644 index 00000000..16682a11 --- /dev/null +++ b/cmake/sqlpp23_testing_helper.cmake @@ -0,0 +1,65 @@ +# Copyright (c) 2026, Vesselin Atanasov +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this +# list of conditions and the following disclaimer in the documentation and/or +# other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +function(add_testing_target) + set(options) + set(oneValueArgs NAME) + set(multiValueArgs DEFINES MOD_DEPS) + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + set(BASE_DIR "${PROJECT_SOURCE_DIR}/tests/${ARG_NAME}") + if(BUILD_WITH_MODULES) + # We are building with modules, so the _testing target created by this function MUST be a regular + # (non-INTERFACE) library. Otherwise, the object files owned by the OBJECT library dependencies + # in MOD_DEPS won't be linked, and we are going to get missing symbols during the linking (namely + # the static module initializer function won't be found). + # + # For details on how OBJECT libraries are linked see + # https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#object-libraries + # https://cmake.org/cmake/help/latest/command/target_link_libraries.html#linking-object-libraries + set(LIB_TYPE) + set(LIB_PROP_SCOPE PUBLIC) + else() + # We are building without modules and the _testing target created by this function won't have any + # compiled files, and CMake will not let us build a empty regular (non-INTERFACE) library. So in + # this case we have to use an INTERFACE library. + set(LIB_TYPE INTERFACE) + set(LIB_PROP_SCOPE INTERFACE) + endif() + set(TARGET_NAME "sqlpp23_${ARG_NAME}_testing") + add_library(${TARGET_NAME} ${LIB_TYPE}) + if(ARG_DEFINES) + target_compile_definitions(${TARGET_NAME} ${LIB_PROP_SCOPE} ${ARG_DEFINES}) + endif() + target_include_directories(${TARGET_NAME} ${LIB_PROP_SCOPE} "${BASE_DIR}") + target_link_libraries(${TARGET_NAME} ${LIB_PROP_SCOPE} sqlpp23_testing) + if(BUILD_WITH_MODULES) + target_sources( + ${TARGET_NAME} + PUBLIC + FILE_SET CXX_MODULES FILES "${BASE_DIR}/modules/sqlpp23.test.${ARG_NAME}.tables.cppm" + ) + target_link_libraries(${TARGET_NAME} PUBLIC sqlpp23::core_module ${ARG_MOD_DEPS}) + endif() +endfunction() diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index 4229f3e4..7ff9da39 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -22,29 +22,9 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -if(BUILD_WITH_MODULES) - set(LIB_TYPE) - set(LIB_PROP_SCOPE PUBLIC) -else() - set(LIB_TYPE INTERFACE) - set(LIB_PROP_SCOPE INTERFACE) -endif() -add_library(sqlpp23_core_testing ${LIB_TYPE}) -target_include_directories(sqlpp23_core_testing ${LIB_PROP_SCOPE} ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(sqlpp23_core_testing ${LIB_PROP_SCOPE} sqlpp23_testing) -if(BUILD_WITH_MODULES) - target_sources( - sqlpp23_core_testing - PUBLIC - FILE_SET CXX_MODULES FILES modules/sqlpp23.test.core.tables.cppm - ) - target_link_libraries( - sqlpp23_core_testing - PUBLIC - sqlpp23::core_module - sqlpp23::mock_db_module - ) -endif() +include(sqlpp23_testing_helper) + +add_testing_target(NAME core MOD_DEPS sqlpp23::mock_db_module) add_subdirectory(asserts) add_subdirectory(constraints) diff --git a/tests/mysql/CMakeLists.txt b/tests/mysql/CMakeLists.txt index 4cd61365..cd73eafa 100644 --- a/tests/mysql/CMakeLists.txt +++ b/tests/mysql/CMakeLists.txt @@ -22,33 +22,15 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +include(sqlpp23_testing_helper) + find_package(Threads REQUIRED) -if(BUILD_WITH_MODULES) - set(LIB_TYPE) - set(LIB_PROP_SCOPE PUBLIC) -else() - set(LIB_TYPE INTERFACE) - set(LIB_PROP_SCOPE INTERFACE) -endif() -add_library(sqlpp23_mysql_testing ${LIB_TYPE}) -target_include_directories(sqlpp23_mysql_testing ${LIB_PROP_SCOPE} ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(sqlpp23_mysql_testing ${LIB_PROP_SCOPE} sqlpp23_testing) -if(BUILD_WITH_MODULES) - target_sources( - sqlpp23_mysql_testing - PUBLIC - FILE_SET CXX_MODULES FILES modules/sqlpp23.test.mysql.tables.cppm - ) - target_link_libraries( - sqlpp23_mysql_testing - PUBLIC - sqlpp23::core_module - sqlpp23::mysql_module - ) -endif() + +set(DEFINES) if (MSVC) - target_compile_options(sqlpp23_mysql_testing PUBLIC -DNOMINMAX) + list(APPEND DEFINES -DNOMINMAX) endif () +add_testing_target(NAME mysql DEFINES ${DEFINES} MOD_DEPS sqlpp23::mysql_module) add_subdirectory(asserts) add_subdirectory(constraints) diff --git a/tests/postgresql/CMakeLists.txt b/tests/postgresql/CMakeLists.txt index 4e488744..0f358ba8 100644 --- a/tests/postgresql/CMakeLists.txt +++ b/tests/postgresql/CMakeLists.txt @@ -22,29 +22,9 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -if(BUILD_WITH_MODULES) - set(LIB_TYPE) - set(LIB_PROP_SCOPE PUBLIC) -else() - set(LIB_TYPE INTERFACE) - set(LIB_PROP_SCOPE INTERFACE) -endif() -add_library(sqlpp23_postgresql_testing ${LIB_TYPE}) -target_include_directories(sqlpp23_postgresql_testing ${LIB_PROP_SCOPE} ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(sqlpp23_postgresql_testing ${LIB_PROP_SCOPE} sqlpp23_testing) -if(BUILD_WITH_MODULES) - target_sources( - sqlpp23_postgresql_testing - PUBLIC - FILE_SET CXX_MODULES FILES modules/sqlpp23.test.postgresql.tables.cppm - ) - target_link_libraries( - sqlpp23_postgresql_testing - PUBLIC - sqlpp23::core_module - sqlpp23::postgresql_module - ) -endif() +include(sqlpp23_testing_helper) + +add_testing_target(NAME postgresql MOD_DEPS sqlpp23::postgresql_module) add_subdirectory(asserts) add_subdirectory(constraints) diff --git a/tests/sqlite3/CMakeLists.txt b/tests/sqlite3/CMakeLists.txt index 084b8f9c..59a34883 100644 --- a/tests/sqlite3/CMakeLists.txt +++ b/tests/sqlite3/CMakeLists.txt @@ -22,28 +22,9 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -if(BUILD_WITH_MODULES) - set(LIB_TYPE) - set(LIB_PROP_SCOPE PUBLIC) -else() - set(LIB_TYPE INTERFACE) - set(LIB_PROP_SCOPE INTERFACE) -endif() -add_library(sqlpp23_sqlite3_testing ${LIB_TYPE}) -target_include_directories(sqlpp23_sqlite3_testing ${LIB_PROP_SCOPE} ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(sqlpp23_sqlite3_testing ${LIB_PROP_SCOPE} sqlpp23_testing) -if(BUILD_WITH_MODULES) - target_sources( - sqlpp23_sqlite3_testing - PUBLIC - FILE_SET CXX_MODULES FILES modules/sqlpp23.test.sqlite3.tables.cppm - ) - target_link_libraries( - sqlpp23_sqlite3_testing PUBLIC - sqlpp23::core_module - sqlpp23::sqlite3_module - ) -endif() +include(sqlpp23_testing_helper) + +add_testing_target(NAME sqlite3 MOD_DEPS sqlpp23::sqlite3_module) function(sqlpp_slite3_test_add_target_link_libraries name) target_link_libraries(${name} PRIVATE sqlpp23_testing sqlpp23_sqlite3_testing) From 43dc0e0b5ab2062804480c7faefcee98807d1941 Mon Sep 17 00:00:00 2001 From: MeanSquaredError <35379301+MeanSquaredError@users.noreply.github.com> Date: Sat, 27 Jun 2026 18:28:09 +0300 Subject: [PATCH 4/5] CMake: Expand the comment explaining why we use OBJECT instead of INTERFACE libraries for our module targets. --- cmake/sqlpp23_target_helper.cmake | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cmake/sqlpp23_target_helper.cmake b/cmake/sqlpp23_target_helper.cmake index 35f3eb87..6b5600c9 100644 --- a/cmake/sqlpp23_target_helper.cmake +++ b/cmake/sqlpp23_target_helper.cmake @@ -130,11 +130,15 @@ function(add_common) # Initialize helper variables based on target type (regular or module) if(ARG_MODULE_INTERFACE) set(TARGET_SUFFIX "_module") - # FILE_SETs of type CXX_MODULES cannot have the INTERFACE scope (exept - # on IMPORTED targets) and INTERFACE libraries only allow INTERFACE - # scope on their properties. That's why we cannot use the INTERFACE - # library type. For details see the discussion at - # https://discourse.cmake.org/t/header-only-libraries-and-c-20-modules/10680/11 + # CMake has the following two limitations: + # - FILE_SETs of type CXX_MODULES cannot have the INTERFACE scope (except on IMPORTED targets). + # - INTERFACE libraries only allow INTERFACE scope on their properties. + # From these two limitations it follows that INTERFACE libraries cannot have FILE_SETs of type + # CXX_MODULES. That's why, as a workaround, we use an OBJECT library. + # + # For details see the discussion at + # https://discourse.cmake.org/t/header-only-libraries-and-c-20-modules/10680 + # where the CMake devs explain that this limitation exists to prevent possible ODR violations. set(LIB_TYPE OBJECT) set(LIB_PROP_SCOPE PUBLIC) else() From a44c9399b4301ff133039fcf6106c597c9802c35 Mon Sep 17 00:00:00 2001 From: MeanSquaredError <35379301+MeanSquaredError@users.noreply.github.com> Date: Sun, 28 Jun 2026 03:22:41 +0300 Subject: [PATCH 5/5] CMake: add_testing_target: Don't add the component directory to the target include path, because we don't actually use it as an include directory. --- cmake/sqlpp23_testing_helper.cmake | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/cmake/sqlpp23_testing_helper.cmake b/cmake/sqlpp23_testing_helper.cmake index 16682a11..becee726 100644 --- a/cmake/sqlpp23_testing_helper.cmake +++ b/cmake/sqlpp23_testing_helper.cmake @@ -28,7 +28,6 @@ function(add_testing_target) set(multiValueArgs DEFINES MOD_DEPS) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - set(BASE_DIR "${PROJECT_SOURCE_DIR}/tests/${ARG_NAME}") if(BUILD_WITH_MODULES) # We are building with modules, so the _testing target created by this function MUST be a regular # (non-INTERFACE) library. Otherwise, the object files owned by the OBJECT library dependencies @@ -52,14 +51,10 @@ function(add_testing_target) if(ARG_DEFINES) target_compile_definitions(${TARGET_NAME} ${LIB_PROP_SCOPE} ${ARG_DEFINES}) endif() - target_include_directories(${TARGET_NAME} ${LIB_PROP_SCOPE} "${BASE_DIR}") target_link_libraries(${TARGET_NAME} ${LIB_PROP_SCOPE} sqlpp23_testing) if(BUILD_WITH_MODULES) - target_sources( - ${TARGET_NAME} - PUBLIC - FILE_SET CXX_MODULES FILES "${BASE_DIR}/modules/sqlpp23.test.${ARG_NAME}.tables.cppm" - ) + set(MOD_FILE "${PROJECT_SOURCE_DIR}/tests/${ARG_NAME}/modules/sqlpp23.test.${ARG_NAME}.tables.cppm") + target_sources(${TARGET_NAME} PUBLIC FILE_SET CXX_MODULES FILES "${MOD_FILE}") target_link_libraries(${TARGET_NAME} PUBLIC sqlpp23::core_module ${ARG_MOD_DEPS}) endif() endfunction()