From f02cdc95d24ecd2a0b35db53a6d40d69995cb001 Mon Sep 17 00:00:00 2001 From: Derek Huang Date: Sat, 23 Aug 2025 03:34:26 -0400 Subject: [PATCH 1/5] src/CMakeLists.txt: avoid unnecessary rebuilds/update to soci-config.h on Windows modified: src/CMakeLists.txt Use file(GENERATE) to enforce LF line endings are used consistently, which allows us to avoid needless re-writing of soci-config.h on Windows due to file(WRITE) using CRLF instead of the LF as expected --- src/CMakeLists.txt | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7aff9587..11bf67f2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,18 +57,20 @@ list(APPEND CONFIG_LINES "#endif") list(JOIN CONFIG_LINES "\n" CONFIG_CONTENT) -string(MD5 CONFIG_CONTENT_HASH "${CONFIG_CONTENT}") -if (EXISTS "${SOCI_GENERATED_INCLUDES_DIR}/soci/soci-config.h") - file(MD5 "${SOCI_GENERATED_INCLUDES_DIR}/soci/soci-config.h" CONFIG_FILE_HASH) -else() - set(CONFIG_FILE_HASH 0) -endif() - -# Only overwrite the soci-config.h file if the generated content is different from the -# file's content in order to avoid needless rebuilding -if (NOT (CONFIG_CONTENT_HASH STREQUAL CONFIG_FILE_HASH)) - file(WRITE "${SOCI_GENERATED_INCLUDES_DIR}/soci/soci-config.h" "${CONFIG_CONTENT}") -endif() +# We use file(GENERATE) to only overwrite soci-config.h if the generated +# content to be written has differed from the file's content. Note that we do +# *not* use file(WRITE) because the line endings would be CRLF on Windows, so +# the file MD5 hash would *never* equal that of the content hash, as the string +# content is of course using standard LF line endings. +# +# Therefore, this means that soci-config.h is updated on each configure, so +# each subsequent cmake --build results in the needless rebuilding we wanted to +# avoid in the first place. +# +file(GENERATE + OUTPUT "${SOCI_GENERATED_INCLUDES_DIR}/soci/soci-config.h" + CONTENT "${CONFIG_CONTENT}" NEWLINE_STYLE LF +) # Append the generated config header to the public headers of the core target target_sources(soci_core From b5c9ea9a7b185c1e41996b6a61d321627fcb0572 Mon Sep 17 00:00:00 2001 From: Derek Huang Date: Sat, 23 Aug 2025 03:48:58 -0400 Subject: [PATCH 2/5] CMakeLists.txt: ensure build types are displayed for multi-config generators correctly --- CMakeLists.txt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9cc3380..5a44abb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,9 @@ option(SOCI_TESTS "Enable building SOCI test cases" ${PROJECT_IS_TOP_LEVEL}) option(WITH_BOOST "Enable Boost support" ON) cmake_dependent_option(SOCI_LTO "Enable link time optimizations in release builds" ON "LTO_AVAILABLE" OFF) +# Determine if the CMake generator is single or multi config. This will be +# useful later when printing the SOCI configuration in show_config. +get_property(SOCI_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) # Configure LTO for anything but Debug builds (if enabled in the first place) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ${SOCI_LTO}) @@ -159,10 +162,16 @@ endif() # Also make it possible to see SOCI configuration later. add_custom_target(show_config - COMMAND ${CMAKE_COMMAND} -E echo "SOCI ${SOCI_VERSION} configured with:" - COMMAND ${CMAKE_COMMAND} -E echo " Build type: ${CMAKE_BUILD_TYPE}" - COMMAND ${CMAKE_COMMAND} -E echo " Library type: ${SOCI_LIB_TYPE}" - COMMAND ${CMAKE_COMMAND} -E echo " Enabled backends: ${SOCI_ENABLED_BACKENDS}" + COMMAND ${CMAKE_COMMAND} -E echo + "SOCI ${SOCI_VERSION} configured with:" + COMMAND ${CMAKE_COMMAND} -E echo + # If using multi-config generator CMAKE_BUILD_TYPE is not meaningful. One + # would instead select a build type from CMAKE_CONFIGURATION_TYPES. + " Build type: $" + COMMAND ${CMAKE_COMMAND} -E echo + " Library type: ${SOCI_LIB_TYPE}" + COMMAND ${CMAKE_COMMAND} -E echo + " Enabled backends: ${SOCI_ENABLED_BACKENDS}" COMMENT "Show SOCI build configuration summary" VERBATIM From abbbc246068d254822beb944db802564cb62aac5 Mon Sep 17 00:00:00 2001 From: Derek Huang Date: Sat, 23 Aug 2025 04:08:16 -0400 Subject: [PATCH 3/5] src/CMakeLists.txt: update comment for clarity --- src/CMakeLists.txt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 11bf67f2..a4cf2e83 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,11 +61,9 @@ list(JOIN CONFIG_LINES "\n" CONFIG_CONTENT) # content to be written has differed from the file's content. Note that we do # *not* use file(WRITE) because the line endings would be CRLF on Windows, so # the file MD5 hash would *never* equal that of the content hash, as the string -# content is of course using standard LF line endings. -# -# Therefore, this means that soci-config.h is updated on each configure, so -# each subsequent cmake --build results in the needless rebuilding we wanted to -# avoid in the first place. +# content is of course using standard LF line endings. Usinf file(WRITE) would +# mean that soci-config.h is updated on each configure, so each subsequent +# cmake --build would result in the needless rebuilding we wanted to avoid. # file(GENERATE OUTPUT "${SOCI_GENERATED_INCLUDES_DIR}/soci/soci-config.h" From 533f7abb17911a473b8b81001c7992601c995880 Mon Sep 17 00:00:00 2001 From: Derek Huang Date: Sat, 23 Aug 2025 04:09:04 -0400 Subject: [PATCH 4/5] src/CMakeLists.txt: fix typo in comment --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a4cf2e83..f95535b2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,7 +61,7 @@ list(JOIN CONFIG_LINES "\n" CONFIG_CONTENT) # content to be written has differed from the file's content. Note that we do # *not* use file(WRITE) because the line endings would be CRLF on Windows, so # the file MD5 hash would *never* equal that of the content hash, as the string -# content is of course using standard LF line endings. Usinf file(WRITE) would +# content is of course using standard LF line endings. Using file(WRITE) would # mean that soci-config.h is updated on each configure, so each subsequent # cmake --build would result in the needless rebuilding we wanted to avoid. # From f9496daf4dbfd734e46360621e2f4934fc177322 Mon Sep 17 00:00:00 2001 From: Derek Huang Date: Sat, 23 Aug 2025 05:18:40 -0400 Subject: [PATCH 5/5] CMakeLists.txt: ensure CMAKE_BUILD_TYPE defaults to non-empty if unset --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a44abb8..c1dbacd0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,11 @@ cmake_dependent_option(SOCI_LTO "Enable link time optimizations in release build # useful later when printing the SOCI configuration in show_config. get_property(SOCI_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +# Default build type to Release for single-config generators +if(NOT SOCI_IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + # Configure LTO for anything but Debug builds (if enabled in the first place) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ${SOCI_LTO}) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF)