2023-01-20 16:18:04 +01:00
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# 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)
|
2023-01-24 15:58:08 +01:00
|
|
|
set(CMAKE_BUILD_TYPE Release)
|
2023-01-20 16:18:04 +01:00
|
|
|
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)
|
2023-01-24 15:58:08 +01:00
|
|
|
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}")
|
2023-01-20 16:18:04 +01:00
|
|
|
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)
|
2023-01-24 15:58:08 +01:00
|
|
|
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}")
|
2023-01-20 16:18:04 +01:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
|
2023-01-24 15:58:08 +01:00
|
|
|
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")
|
2023-01-20 16:18:04 +01:00
|
|
|
elseif(MSVC)
|
2023-01-24 15:58:08 +01:00
|
|
|
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()
|
2023-01-20 16:18:04 +01:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_BUILD_TYPE MATCHES Debug)
|
2023-01-24 15:58:08 +01:00
|
|
|
message(STATUS "MyFirstUDRKit build: compiler flags - ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
|
2023-01-20 16:18:04 +01:00
|
|
|
elseif(CMAKE_BUILD_TYPE MATCHES Release)
|
2023-01-24 15:58:08 +01:00
|
|
|
message(STATUS "MyFirstUDRKit build: compiler flags - ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
|
2023-01-20 16:18:04 +01:00
|
|
|
endif()
|
|
|
|
|
|
|
|
####################################################################################
|
|
|
|
###### This is an example of including external sources to link
|
|
|
|
###### Edit as required.
|
|
|
|
#################
|
|
|
|
|
2023-01-24 15:57:52 +01:00
|
|
|
#####find_path(OTHER_LIB_INCLUDE_DIR crc_32.h ${CMAKE_SOURCE_DIR}/other_lib/include)
|
2023-01-20 16:18:04 +01:00
|
|
|
|
2023-01-24 15:57:52 +01:00
|
|
|
#####if(NOT OTHER_LIB_INCLUDE_DIR)
|
|
|
|
#####message(FATAL_ERROR "MyFirstUDRKit build: Location of other_lib files could not found")
|
2023-01-20 16:18:04 +01:00
|
|
|
#####endif()
|
|
|
|
|
2023-01-24 15:57:52 +01:00
|
|
|
#####message(STATUS "MyFirstUDRKit link: other_lib files - ${OTHER_LIB_INCLUDE_DIR}")
|
2023-01-20 16:18:04 +01:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# Firebird libraries to link
|
|
|
|
############
|
|
|
|
|
|
|
|
find_path(FIREBIRD_INCLUDE_DIR ibase.h
|
2023-01-24 15:58:08 +01:00
|
|
|
/usr/include
|
|
|
|
/opt/firebird/include
|
|
|
|
${CMAKE_SOURCE_DIR}/firebird/include
|
|
|
|
$ENV{ProgramFiles}/Firebird/*/include
|
2023-01-20 16:18:04 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
set(FIREBIRD_LIB_NAMES fbclient fbclient_ms)
|
2023-01-24 15:58:08 +01:00
|
|
|
find_library(FIREBIRD_LIB_DIR
|
|
|
|
NAMES
|
|
|
|
${FIREBIRD_LIB_NAMES}
|
|
|
|
PATHS
|
|
|
|
/usr/lib
|
|
|
|
/opt/firebird/lib
|
|
|
|
${CMAKE_SOURCE_DIR}/firebird/lib
|
|
|
|
$ENV{ProgramFiles}/Firebird/*/lib
|
2023-01-20 16:18:04 +01:00
|
|
|
)
|
|
|
|
|
2023-01-24 15:58:08 +01:00
|
|
|
if(NOT FIREBIRD_INCLUDE_DIR OR NOT FIREBIRD_LIB_DIR)
|
|
|
|
message(FATAL_ERROR "MyFirstUDRKit build: Location of Firebird library could not be found")
|
2023-01-20 16:18:04 +01:00
|
|
|
endif()
|
|
|
|
|
|
|
|
add_library(firebird SHARED IMPORTED)
|
|
|
|
if(UNIX)
|
2023-01-24 15:58:08 +01:00
|
|
|
set_target_properties(firebird
|
|
|
|
PROPERTIES
|
|
|
|
IMPORTED_LOCATION ${FIREBIRD_LIB_DIR}
|
|
|
|
INTERFACE_INCLUDE_DIRECTORIES "${FIREBIRD_INCLUDE_DIR};${FIREBIRD_INCLUDE_DIR}/firebird"
|
|
|
|
)
|
2023-01-20 16:18:04 +01:00
|
|
|
else()
|
2023-01-24 15:58:08 +01:00
|
|
|
set_target_properties(firebird
|
|
|
|
PROPERTIES
|
|
|
|
IMPORTED_IMPLIB ${FIREBIRD_LIB_DIR}
|
|
|
|
INTERFACE_INCLUDE_DIRECTORIES "${FIREBIRD_INCLUDE_DIR};${FIREBIRD_INCLUDE_DIR}/firebird"
|
2023-01-20 16:18:04 +01:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2023-01-24 15:58:08 +01:00
|
|
|
message(STATUS "MyFirstUDRKit link: firebird - ${FIREBIRD_LIB_DIR}")
|
2023-01-20 16:18:04 +01:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# Target library
|
|
|
|
############
|
|
|
|
|
|
|
|
file(GLOB files "${CMAKE_SOURCE_DIR}/src/*")
|
|
|
|
|
|
|
|
add_library(MyFirstUDRKit SHARED ${files})
|
|
|
|
|
|
|
|
set(DEF_FILE "udr_plugin")
|
|
|
|
|
|
|
|
if(UNIX)
|
2023-01-24 15:58:08 +01:00
|
|
|
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
|
|
|
|
)
|
2023-01-20 16:18:04 +01:00
|
|
|
elseif(MSVC OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
|
2023-01-24 15:58:08 +01:00
|
|
|
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()
|
2023-01-20 16:18:04 +01:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(BUILD_SHARED_LIBS AND MY_FIRST_UDR_KIT_VERSION)
|
2023-01-24 15:58:08 +01:00
|
|
|
set_target_properties(MyFirstUDRKit PROPERTIES VERSION ${MY_FIRST_UDR_KIT_VERSION})
|
2023-01-20 16:18:04 +01:00
|
|
|
endif()
|
|
|
|
|
|
|
|
####Uncomment if using additional libraries - see line "This is an example of including external sources to link" above
|
2023-01-24 15:57:52 +01:00
|
|
|
####target_include_directories(other_lib PUBLIC ${OTHER_LIB_INCLUDE_DIR})
|
2023-01-20 16:18:04 +01:00
|
|
|
|
|
|
|
target_link_libraries(MyFirstUDRKit PUBLIC firebird)
|
|
|
|
|
|
|
|
######
|
|
|
|
|