Skip to content

Commit a27e4b9

Browse files
When installing also install the module (.cppm) files (#58)
* Rename directories: module/ -> modules/ * When installing the library also install the module (.cppm) files. * minor cleanup
1 parent 11973a7 commit a27e4b9

15 files changed

Lines changed: 27 additions & 13 deletions

CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ if(BUILD_POSTGRESQL_CONNECTOR)
9999
endif()
100100

101101
if(BUILD_WITH_MODULES)
102-
add_subdirectory(module)
102+
add_subdirectory(modules)
103103
endif()
104104

105105
### Packaging
@@ -112,7 +112,6 @@ write_basic_package_version_file(Sqlpp23ConfigVersion.cmake
112112
ARCH_INDEPENDENT
113113
)
114114

115-
116115
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Sqlpp23ConfigVersion.cmake
117116
DESTINATION ${SQLPP23_INSTALL_CMAKEDIR}
118117
)
@@ -151,7 +150,6 @@ if(BUILD_POSTGRESQL_CONNECTOR)
151150
install_component(NAME Sqlpp23PostgreSQL TARGETS sqlpp23_postgresql DIRECTORY postgresql)
152151
endif()
153152

154-
155153
### Tests
156154
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
157155
add_subdirectory(tests)
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@
2222
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2323
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2424

25+
# The module targets should really be of INTERFACE type, because it is a header-only
26+
# library which doesn't build any library files for them. However CMake disallows
27+
# using the INTERFACE library type if the library has any C++20 modules. For details
28+
# see https://discourse.cmake.org/t/header-only-libraries-and-c-20-modules/10680
29+
#
30+
# On the other hand using a regular library type for the module libraries means
31+
# that any call to install(TARGET...) for the module targets will fail because it will
32+
# also try to install the non-existent library file. This in turn means that we cannot
33+
# use install(TARGET...) to install the .cmm files and have to resort to
34+
# install(FILES...)
35+
36+
set(SQLPP23_INSTALL_MODULE_DIR ${CMAKE_INSTALL_PREFIX}/modules/sqlpp23)
37+
2538
# Core library module
2639
add_library(sqlpp23.core.module)
2740
target_sources(sqlpp23.core.module
@@ -30,6 +43,7 @@ target_sources(sqlpp23.core.module
3043
sqlpp23.core.cppm
3144
)
3245
target_link_libraries(sqlpp23.core.module PUBLIC sqlpp23)
46+
install(FILES sqlpp23.core.cppm DESTINATION ${SQLPP23_INSTALL_MODULE_DIR})
3347

3448
add_library(sqlpp23.mock_db.module)
3549
target_sources(sqlpp23.mock_db.module
@@ -38,6 +52,7 @@ target_sources(sqlpp23.mock_db.module
3852
sqlpp23.mock_db.cppm
3953
)
4054
target_link_libraries(sqlpp23.mock_db.module PUBLIC sqlpp23.core.module)
55+
install(FILES sqlpp23.mock_db.cppm DESTINATION ${SQLPP23_INSTALL_MODULE_DIR})
4156

4257
if(BUILD_SQLITE3_CONNECTOR OR BUILD_SQLCIPHER_CONNECTOR)
4358
add_library(sqlpp23.sqlite3.module)
@@ -47,6 +62,7 @@ if(BUILD_SQLITE3_CONNECTOR OR BUILD_SQLCIPHER_CONNECTOR)
4762
sqlpp23.sqlite3.cppm
4863
)
4964
target_link_libraries(sqlpp23.sqlite3.module PUBLIC sqlpp23.core.module sqlpp23::sqlite3)
65+
install(FILES sqlpp23.sqlite3.cppm DESTINATION ${SQLPP23_INSTALL_MODULE_DIR})
5066
endif()
5167

5268
if(BUILD_MYSQL_CONNECTOR OR BUILD_MARIADB_CONNECTOR)
@@ -57,6 +73,7 @@ if(BUILD_MYSQL_CONNECTOR OR BUILD_MARIADB_CONNECTOR)
5773
sqlpp23.mysql.cppm
5874
)
5975
target_link_libraries(sqlpp23.mysql.module PUBLIC sqlpp23.core.module sqlpp23::mysql)
76+
install(FILES sqlpp23.mysql.cppm DESTINATION ${SQLPP23_INSTALL_MODULE_DIR})
6077
endif()
6178

6279
if(BUILD_POSTGRESQL_CONNECTOR)
@@ -67,6 +84,5 @@ if(BUILD_POSTGRESQL_CONNECTOR)
6784
sqlpp23.postgresql.cppm
6885
)
6986
target_link_libraries(sqlpp23.postgresql.module PUBLIC sqlpp23.core.module sqlpp23::postgresql)
87+
install(FILES sqlpp23.postgresql.cppm DESTINATION ${SQLPP23_INSTALL_MODULE_DIR})
7088
endif()
71-
72-

tests/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if(BUILD_WITH_MODULES)
2727
target_sources(sqlpp23.test.core.tables.module
2828
PUBLIC
2929
FILE_SET all_my_modules TYPE CXX_MODULES FILES
30-
module/sqlpp23.test.core.tables.cppm
30+
modules/sqlpp23.test.core.tables.cppm
3131
)
3232
target_link_libraries(sqlpp23.test.core.tables.module PUBLIC sqlpp23.core.module)
3333
endif()

tests/core/module/sqlpp23.test.core.tables.cppm renamed to tests/core/modules/sqlpp23.test.core.tables.cppm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module;
22

33
// clang-format off
4-
// generated by ./scripts/sqlpp23-ddl2cpp --path-to-ddl tests/include/sqlpp23/tests/core/tables.sql --path-to-module tests/core/module/sqlpp23.test.core.tables.cppm --module-name=sqlpp23.test.core.tables --namespace test --assume-auto-id
4+
// generated by ./scripts/sqlpp23-ddl2cpp --path-to-ddl tests/include/sqlpp23/tests/core/tables.sql --path-to-module tests/core/modules/sqlpp23.test.core.tables.cppm --module-name=sqlpp23.test.core.tables --namespace test --assume-auto-id
55

66
#include <optional>
77

tests/mysql/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if(BUILD_WITH_MODULES)
2727
target_sources(sqlpp23.test.mysql.tables.module
2828
PUBLIC
2929
FILE_SET all_my_modules TYPE CXX_MODULES FILES
30-
module/sqlpp23.test.mysql.tables.cppm
30+
modules/sqlpp23.test.mysql.tables.cppm
3131
)
3232
target_link_libraries(sqlpp23.test.mysql.tables.module PUBLIC sqlpp23.core.module)
3333
endif()

0 commit comments

Comments
 (0)