mirror of
https://github.com/allankoechke/soci.git
synced 2026-11-30 10:58:24 +00:00
Merge branch 'cmake-windows-fixes' of github.com:phetdam/soci
CMake config Windows fixes. See #1302.
This commit is contained in:
@@ -45,6 +45,14 @@ 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)
|
||||
|
||||
# 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})
|
||||
@@ -159,10 +167,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: $<IF:${SOCI_IS_MULTI_CONFIG},${CMAKE_CONFIGURATION_TYPES},${CMAKE_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
|
||||
|
||||
@@ -57,18 +57,18 @@ 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. 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.
|
||||
#
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user