Warning, /sdk/codevis/thirdparty/soci/CMakeLists.txt is written in an unsupported language. File is not indexed.

0001 ###############################################################################
0002 #
0003 # This file is part of CMake configuration for SOCI library
0004 #
0005 # Copyright (C) 2009-2013 Mateusz Loskot <mateusz@loskot.net>
0006 # Distributed under the Boost Software License, Version 1.0.
0007 # (See accompanying file LICENSE_1_0.txt or copy at
0008 # http://www.boost.org/LICENSE_1_0.txt)
0009 #
0010 ###############################################################################
0011 # General settings
0012 ###############################################################################
0013 cmake_minimum_required(VERSION 2.8...3.20 FATAL_ERROR)
0014 
0015 project(SOCI)
0016 
0017 if(NOT DEFINED CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 14)
0018   set(CMAKE_CXX_STANDARD 14)
0019 endif()
0020 set(CMAKE_CXX_STANDARD_REQUIRED ON)
0021 
0022 ###############################################################################
0023 # Build features and variants
0024 ##############################################################################
0025 
0026 option(SOCI_SHARED "Enable build of shared libraries" ON)
0027 option(SOCI_STATIC "Enable build of static libraries" ON)
0028 option(SOCI_TESTS "Enable build of collection of SOCI tests" ON)
0029 option(SOCI_ASAN "Enable address sanitizer on GCC v4.8+/Clang v 3.1+" OFF)
0030 option(SOCI_LTO "Enable link time optimization" OFF)
0031 option(SOCI_VISIBILITY "Enable hiding private symbol using ELF visibility if supported by the platform" ON)
0032 
0033 if (SOCI_LTO)
0034     cmake_minimum_required(VERSION 3.9)
0035 
0036     # Check and enable lto support
0037     include(CheckIPOSupported)
0038     check_ipo_supported(RESULT supported)
0039 
0040     if (NOT supported)
0041         message(STATUS "IPO / LTO not supported")
0042     endif()
0043 
0044     if (supported AND NOT SOCI_ASAN)
0045         message(STATUS "IPO / LTO enabled")
0046         set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
0047 
0048         if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
0049             # Check for lld as clang lto works best with its own linker
0050             include(CheckCXXCompilerFlag)
0051             check_cxx_compiler_flag("-fuse-ld=lld" HAS_LLD)
0052             if (HAS_LLD)
0053                 SET(CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
0054                 SET(CMAKE_SHARED_LINKER_FLAGS  "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")
0055                 SET(CMAKE_MODULE_LINKER_FLAGS  "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=lld")
0056             endif()
0057         endif()
0058     elseif(supported)
0059         message(STATUS "IPO / LTO is supported but conflicts with ASAN and not enabled")
0060     endif()
0061 endif()
0062 
0063 if (SOCI_VISIBILITY)
0064     # Test whether visibility is supported
0065     include(CheckCSourceCompiles)
0066     check_c_source_compiles(
0067         "
0068             __attribute__ (( visibility(\"default\") )) int f1() { return 0; }
0069             __attribute__ (( visibility(\"hidden\") ))  int f2() { return 1; }
0070 
0071             int main(int argc, char* argv[]) { f1(); f2(); return 0; }
0072         "
0073         SOCI_HAVE_VISIBILITY_SUPPORT
0074     )
0075 
0076     if (SOCI_HAVE_VISIBILITY_SUPPORT)
0077         message(STATUS "gcc / clang visibility enabled")
0078         set(CMAKE_CXX_VISIBILITY_PRESET hidden)
0079         cmake_policy(SET CMP0063 NEW)
0080     endif()
0081 else()
0082     set(SOCI_HAVE_VISIBILITY_SUPPORT off)
0083 endif()
0084 
0085 ###############################################################################
0086 # SOCI CMake modules
0087 ###############################################################################
0088 
0089 # Path to additional CMake modules
0090 set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
0091 set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
0092 
0093 include(SociUtilities)
0094 include(SociConfig)
0095 
0096 colormsg(_HIBLUE_ "Configuring SOCI:")
0097 
0098 ###############################################################################
0099 # SOCI version information
0100 ###############################################################################
0101 include(SociVersion)
0102 
0103 soci_version()
0104 
0105 ###############################################################################
0106 # Build features and variants
0107 ##############################################################################
0108 
0109 boost_report_value(SOCI_SHARED)
0110 boost_report_value(SOCI_STATIC)
0111 boost_report_value(SOCI_TESTS)
0112 boost_report_value(SOCI_ASAN)
0113 
0114 # from SociConfig.cmake
0115 boost_report_value(LIB_SUFFIX)
0116 
0117 # Put the libaries and binaries that get built into directories at the
0118 # top of the build tree rather than in hard-to-find leaf
0119 # directories. This simplifies manual testing and the use of the build
0120 # tree rather than installed Boost libraries.
0121 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
0122 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
0123 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
0124 
0125 ###############################################################################
0126 # Find SOCI dependencies
0127 ###############################################################################
0128 
0129 set(SOCI_CORE_TARGET)
0130 set(SOCI_CORE_TARGET_STATIC)
0131 set(SOCI_CORE_DEPS_LIBS)
0132 
0133 include(SociDependencies)
0134 
0135 get_property(SOCI_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
0136   PROPERTY INCLUDE_DIRECTORIES)
0137 
0138 if(Threads_FOUND)
0139   list(APPEND SOCI_CORE_DEPS_LIBS ${CMAKE_THREAD_LIBS_INIT})
0140 else()
0141   message(FATAL_ERROR "No thread library found")
0142 endif()
0143 
0144 if(NOT MSVC)
0145   set(DL_FIND_QUIETLY TRUE)
0146   find_package(DL)
0147   if(DL_FOUND)
0148     list(APPEND SOCI_CORE_DEPS_LIBS ${DL_LIBRARY})
0149     set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES ${DL_INCLUDE_DIR})
0150     add_definitions(-DHAVE_DL=1)
0151   endif()
0152 endif()
0153 
0154 # Do not try to use Boost on FreeBSD, it's too old.'
0155 set(SOCI_HAVE_BOOST OFF)
0156 set(SOCI_HAVE_BOOST_DATE_TIME OFF)
0157 
0158 set(SOCI_HAVE_BOOST ${SOCI_HAVE_BOOST} CACHE INTERNAL "Boost library")
0159 set(SOCI_HAVE_BOOST_DATE_TIME ${SOCI_HAVE_BOOST_DATE_TIME} CACHE INTERNAL "Boost date_time library")
0160 
0161 list(APPEND SOCI_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR})
0162 
0163 set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
0164   PROPERTY
0165   INCLUDE_DIRECTORIES ${SOCI_INCLUDE_DIRS})
0166 
0167 ###############################################################################
0168 # Installation
0169 ###############################################################################
0170 
0171 include(GNUInstallDirs)
0172 
0173 ###############################################################################
0174 # Configuration files
0175 ###############################################################################
0176 set(CONFIG_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
0177 install(DIRECTORY ${CONFIG_INCLUDE_DIR}/soci DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
0178 set(CONFIG_FILE_IN "include/soci/soci-config.h.in")
0179 set(CONFIG_FILE_OUT "${CONFIG_INCLUDE_DIR}/soci/soci-config.h")
0180 
0181 
0182 
0183 ###############################################################################
0184 # Build configured components
0185 ###############################################################################
0186 include(SociBackend)
0187 
0188 include_directories(${SOCI_SOURCE_DIR}/include ${CONFIG_INCLUDE_DIR})
0189 add_subdirectory(src)
0190 
0191 if(SOCI_TESTS)
0192   ###############################################################################
0193   # Enable tests
0194   ###############################################################################
0195   enable_testing()
0196 
0197   file(TO_NATIVE_PATH ${PROJECT_SOURCE_DIR} TEST_ACCESS_PATH)
0198   configure_file(${PROJECT_SOURCE_DIR}/cmake/configs/test-access.cmake ${PROJECT_SOURCE_DIR}/tests/odbc/test-access.dsn @ONLY)
0199 
0200   set(MYSQL_DRIVER_NAME "MySQL")
0201   if(WIN32)
0202     set(MYSQL_DRIVER_NAME "MySQL ODBC 5.3 ANSI Driver")
0203   endif()
0204   configure_file(${PROJECT_SOURCE_DIR}/cmake/configs/test-mysql.cmake ${PROJECT_SOURCE_DIR}/tests/odbc/test-mysql.dsn @ONLY)
0205 
0206   # Define "make check" as alias for "make test"
0207   add_custom_target(check COMMAND ctest)
0208   add_subdirectory(tests)
0209 endif()
0210 
0211 ###############################################################################
0212 # build config file
0213 ###############################################################################
0214 
0215 get_cmake_property(ALL_VARIABLES CACHE_VARIABLES)
0216 set(CONFIGURED_VARIABLES)
0217 foreach(v ${ALL_VARIABLES})
0218     if (v MATCHES "^SOCI_HAVE.*")
0219         get_property(CACHE_HELPSTRING CACHE ${v} PROPERTY HELPSTRING)
0220                 set(CONFIGURED_VARIABLES "${CONFIGURED_VARIABLES}\n// ${CACHE_HELPSTRING}\n")
0221         if (${${v}})
0222             set(CONFIGURED_VARIABLES "${CONFIGURED_VARIABLES}#define ${v}\n")
0223         else()
0224             set(CONFIGURED_VARIABLES "${CONFIGURED_VARIABLES}/* #undef ${v} */\n")
0225         endif()
0226     endif()
0227 endforeach()
0228 configure_file("${CONFIG_FILE_IN}" "${CONFIG_FILE_OUT}")
0229 
0230 message(STATUS "")