mirror of
https://github.com/SOCI/soci.git
synced 2026-01-08 14:10:47 -06:00
Move compiler flag options + handling to dedicated file
This commit is contained in:
@@ -28,7 +28,6 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
include(CMakeDependentOption)
|
||||
include(CheckIPOSupported)
|
||||
include(CheckCXXCompilerFlag)
|
||||
|
||||
check_ipo_supported(RESULT LTO_AVAILABLE)
|
||||
|
||||
@@ -40,11 +39,8 @@ endif()
|
||||
|
||||
option(SOCI_SHARED "Enable building SOCI as a shared library" ${SHARED_DEFAULT})
|
||||
option(SOCI_TESTS "Enable building SOCI test cases" ${PROJECT_IS_TOP_LEVEL})
|
||||
option(SOCI_ASAN "Enable building SOCI with enabled address sanitizers" OFF)
|
||||
option(SOCI_UBSAN "Enable undefined behaviour sanitizer" OFF)
|
||||
cmake_dependent_option(SOCI_LTO "Enable link time optimizations in release builds" ON "LTO_AVAILABLE" OFF)
|
||||
option(SOCI_VISIBILITY "Make all functions hidden by default - this exposes only explicitly exported functions" ON)
|
||||
set(SOCI_LD "" CACHE STRING "Specify a non-default linker")
|
||||
|
||||
|
||||
# Configure LTO for anything but Debug builds (if enabled in the first place)
|
||||
@@ -65,16 +61,6 @@ if (NOT APPLE)
|
||||
set(CMAKE_INSTALL_RPATH "$ORIGIN")
|
||||
endif()
|
||||
|
||||
if (SOCI_LD)
|
||||
# CMake asks the compiler to do the linking so we have to pass the desired linker to the compiler
|
||||
set(USE_LD_FLAG "-fuse-ld=${SOCI_LD}")
|
||||
check_cxx_compiler_flag("${USE_LD_FLAG}" CAN_USE_CUSTOM_LD)
|
||||
if (NOT CAN_USE_CUSTOM_LD)
|
||||
message(FATAL_ERROR "Can't use custom linker '${SOCI_LD}' - compiler doesn't accept flag '${USE_LD_FLAG}'")
|
||||
endif()
|
||||
add_link_options("${USE_LD_FLAG}")
|
||||
endif()
|
||||
|
||||
if (NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
|
||||
# Ensure that build artifacts are easy to find. And on Windows this
|
||||
# guarantees that the built DLLs end up next to applications
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
include(CheckCXXCompilerFlag)
|
||||
|
||||
|
||||
add_library(soci_compiler_interface INTERFACE)
|
||||
@@ -7,6 +8,10 @@ add_library(soci_compiler_interface INTERFACE)
|
||||
#
|
||||
|
||||
option(SOCI_ENABLE_WERROR "Enables turning compiler warnings into errors" OFF)
|
||||
option(SOCI_ASAN "Enable building SOCI with enabled address sanitizers" OFF)
|
||||
option(SOCI_UBSAN "Enable undefined behaviour sanitizer" OFF)
|
||||
set(SOCI_LD "" CACHE STRING "Specify a non-default linker")
|
||||
|
||||
|
||||
if (WIN32)
|
||||
target_compile_definitions(soci_compiler_interface
|
||||
@@ -38,6 +43,10 @@ if (MSVC)
|
||||
target_compile_options(soci_compiler_interface INTERFACE "/WX")
|
||||
endif()
|
||||
|
||||
if (SOCI_LD)
|
||||
message(FATAL_ERROR "Using a non-default linker is not supported when using MSVC")
|
||||
endif()
|
||||
|
||||
target_compile_options(soci_compiler_interface INTERFACE "/bigobj" "/utf-8")
|
||||
else()
|
||||
|
||||
@@ -50,6 +59,16 @@ else()
|
||||
target_link_options(soci_compiler_interface INTERFACE "-fsanitize=undefined")
|
||||
endif()
|
||||
|
||||
if (SOCI_LD)
|
||||
# CMake asks the compiler to do the linking so we have to pass the desired linker to the compiler
|
||||
set(USE_LD_FLAG "-fuse-ld=${SOCI_LD}")
|
||||
check_cxx_compiler_flag("${USE_LD_FLAG}" CAN_USE_CUSTOM_LD)
|
||||
if (NOT CAN_USE_CUSTOM_LD)
|
||||
message(FATAL_ERROR "Can't use custom linker '${SOCI_LD}' - compiler doesn't accept flag '${USE_LD_FLAG}'")
|
||||
endif()
|
||||
target_link_options(soci_compiler_options INTERFACE "${USE_LD_FLAG}")
|
||||
endif()
|
||||
|
||||
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER}" MATCHES "clang")
|
||||
if(SOCI_ASAN AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 3.1)
|
||||
|
||||
Reference in New Issue
Block a user