############################################################################### # # This file is CMake configuration for MY_FIRST_UDR_KIT library # ############################################################################### # General settings ############ cmake_minimum_required(VERSION 3.4 FATAL_ERROR) project (MY_FIRST_UDR_KIT) set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build) # This will generate compile_commns.json in the builds dir. set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "") if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() ############################################################################### # CMake standard options ############ option(BUILD_SHARED_LIBS "Build shared library" ON) ############################################################################### # Specific options ############ option(MY_FIRST_UDR_KIT_DISABLE_LIBCXX "Do not use libc++, if available" ON) ############################################################################### # Version ############ find_path(UDR_VERSION VERSION.txt ${CMAKE_SOURCE_DIR}) if(UDR_VERSION) file(STRINGS VERSION.txt MY_FIRST_UDR_KIT_VERSION REGEX "[0-9]+\\.[0-9]+\\.[0-9]+") string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" MY_FIRST_UDR_KIT_VERSION_MAJOR "${MY_FIRST_UDR_KIT_VERSION}") string(REGEX REPLACE "^[0-9]+\\.([0-9])+\\.[0-9]+" "\\1" MY_FIRST_UDR_KIT_VERSION_MINOR "${MY_FIRST_UDR_KIT_VERSION}") string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" MY_FIRST_UDR_KIT_VERSION_PATCH "${MY_FIRST_UDR_KIT_VERSION}") message(STATUS "MyFirstUDRKit version: ${MY_FIRST_UDR_KIT_VERSION}") endif() ############################################################################### # Require and enable C++ 0x/11/14/17 ############ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) message(STATUS "MyFirstUDRKit compile: C++${CMAKE_CXX_STANDARD}") if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wnarrowing -Werror") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s") include(CheckCXXCompilerFlag) if(NOT MY_FIRST_UDR_KIT_DISABLE_LIBCXX) check_cxx_compiler_flag("-stdlib=libc++" CXX_SUPPORTS_STDLIB) if(CXX_SUPPORTS_STDLIB) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libc++") set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -stdlib=libc++") endif() set(MY_FIRST_UDR_KIT_DISABLE_LIBCXX ${MY_FIRST_UDR_KIT_DISABLE_LIBCXX} CACHE BOOL "Do not use libc++, if available." FORCE) endif() message(STATUS "MyFirstUDRKit build: Disable linking libc++ - ${MY_FIRST_UDR_KIT_DISABLE_LIBCXX}") elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel") string(REGEX REPLACE "[/-]W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") if (NOT (CMAKE_VERSION VERSION_LESS 3.6.0)) # Compiler features for Intel in CMake 3.6+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qstd=c++17") endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /QaxCORE-AVX2") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:precise") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O3") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Qipo") elseif(MSVC) string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") if(MSVC_VERSION LESS 1900) message(FATAL_ERROR "MyFirstUDRKit build: Build requires C++17-compliant compiler") endif() endif() if(CMAKE_BUILD_TYPE MATCHES Debug) message(STATUS "MyFirstUDRKit build: compiler flags - ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}") elseif(CMAKE_BUILD_TYPE MATCHES Release) message(STATUS "MyFirstUDRKit build: compiler flags - ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}") endif() #################################################################################### ###### This is an example of including external sources to link ###### Edit as required. ################# #####find_path(HASH_INCLUDE_DIR crc_32.h ${CMAKE_SOURCE_DIR}/hash/include) #####if(NOT HASH_INCLUDE_DIR) #####message(FATAL_ERROR "MyFirstUDRKit build: Location of hash files could not found") #####endif() #####message(STATUS "MyFirstUDRKit link: hash files - ${HASH_INCLUDE_DIR}") ############################################################################### # Firebird libraries to link ############ find_path(FIREBIRD_INCLUDE_DIR ibase.h /usr/include /opt/firebird/include ${CMAKE_SOURCE_DIR}/firebird/include $ENV{ProgramFiles}/Firebird/*/include ) set(FIREBIRD_LIB_NAMES fbclient fbclient_ms) find_library(FIREBIRD_LIB NAMES ${FIREBIRD_LIB_NAMES} PATHS /usr/lib /opt/firebird/lib ${CMAKE_SOURCE_DIR}/firebird/lib $ENV{ProgramFiles}/Firebird/*/lib ) if(NOT FIREBIRD_INCLUDE_DIR OR NOT FIREBIRD_LIB) message(FATAL_ERROR "MyFirstUDRKit build: Location of Firebird library could not found") endif() add_library(firebird SHARED IMPORTED) if(UNIX) set_target_properties(firebird PROPERTIES IMPORTED_LOCATION ${FIREBIRD_LIB} INTERFACE_INCLUDE_DIRECTORIES "${FIREBIRD_INCLUDE_DIR};${FIREBIRD_INCLUDE_DIR}/firebird" ) else() set_target_properties(firebird PROPERTIES IMPORTED_IMPLIB ${FIREBIRD_LIB} INTERFACE_INCLUDE_DIRECTORIES "${FIREBIRD_INCLUDE_DIR};${FIREBIRD_INCLUDE_DIR}/firebird" ) endif() message(STATUS "MyFirstUDRKit link: firebird - ${FIREBIRD_LIB}") ############################################################################### # Target library ############ file(GLOB files "${CMAKE_SOURCE_DIR}/src/*") add_library(MyFirstUDRKit SHARED ${files}) set(DEF_FILE "udr_plugin") if(UNIX) set(DEF_FILE ${DEF_FILE}.vers) set(WL_OPTION "--version-script") set_target_properties(MyFirstUDRKit PROPERTIES LINK_FLAGS -Wl,${WL_OPTION},${CMAKE_SOURCE_DIR}/build/defs/${DEF_FILE} LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/x86_64-linux ) elseif(MSVC OR CMAKE_CXX_COMPILER_ID MATCHES "Intel") set(DEF_FILE ${DEF_FILE}.def) set_target_properties(MyFirstUDRKit PROPERTIES LINK_FLAGS "/DEF:\"${CMAKE_SOURCE_DIR}/build/defs/${DEF_FILE}\"") if(MSVC AND CMAKE_BUILD_TYPE MATCHES Debug) find_path(FIREBIRD_PLUGINS udr_engine.dll $ENV{ProgramFiles}/Firebird/*/plugins ) set_target_properties(MyFirstUDRKit PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${FIREBIRD_PLUGINS}/udr ) elseif(CMAKE_BUILD_TYPE MATCHES Release) set_target_properties(MyFirstUDRKit PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/x86_64-win64 ) endif() endif() if(BUILD_SHARED_LIBS AND MY_FIRST_UDR_KIT_VERSION) set_target_properties(MyFirstUDRKit PROPERTIES VERSION ${MY_FIRST_UDR_KIT_VERSION}) endif() ####Uncomment if using additional libraries - see line "This is an example of including external sources to link" above ####target_include_directories(hash PUBLIC ${HASH_INCLUDE_DIR}) target_link_libraries(MyFirstUDRKit PUBLIC firebird) ######