-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
180 lines (153 loc) · 4.88 KB
/
CMakeLists.txt
File metadata and controls
180 lines (153 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
cmake_minimum_required(VERSION 3.5...3.29)
project(qore-sybase-modules VERSION 1.3)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
include(CheckCXXCompilerFlag)
include(CheckCXXSourceCompiles)
include(CheckCXXSymbolExists)
find_package(Qore 0.9 REQUIRED)
# Check for C++17
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
if(COMPILER_SUPPORTS_CXX17)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++17 support. Please use a different C++ compiler.")
endif()
set(CMAKE_THREAD_PREFER_PTHREAD ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(CMAKE_USE_PTHREADS_INIT)
message(STATUS "Found POSIX Threads: TRUE")
else(CMAKE_USE_PTHREADS_INIT)
message(STATUS "Found POSIX Threads: FALSE")
message(FATAL_ERROR "POSIX threads does not seem to be supported on this platform, aborting")
endif()
# Options for building sybase and freetds modules
option(WITH_SYBASE "Build Sybase OCS module" ON)
option(WITH_FREETDS "Build FreeTDS module" ON)
# Find libraries
if(WITH_SYBASE)
find_package(Sybase)
if(NOT Sybase_FOUND)
message(STATUS "Sybase OCS not found, disabling sybase module")
set(WITH_SYBASE OFF)
endif()
endif()
if(WITH_FREETDS)
find_package(FreeTDS)
if(NOT FreeTDS_FOUND)
message(STATUS "FreeTDS not found, disabling freetds module")
set(WITH_FREETDS OFF)
endif()
endif()
if(NOT WITH_SYBASE AND NOT WITH_FREETDS)
message(FATAL_ERROR "Neither Sybase OCS nor FreeTDS found, cannot build any modules")
endif()
# Check for Qore features
set(CMAKE_REQUIRED_INCLUDES ${QORE_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${QORE_LIBRARY})
check_cxx_source_compiles("
#include <qore/Qore.h>
int main(void){
#if (QORE_MODULE_API_MAJOR == 0 && QORE_MODULE_API_MINOR < 7)
#error
#endif
return 0;
}" QORE_HAS_DATASOURCE_PORT)
check_cxx_source_compiles("
#include <qore/Qore.h>
int main(void){
Datasource *ds = nullptr;
ds->activeTransaction();
return 0;
}" _QORE_HAS_DATASOURCE_ACTIVETRANSACTION)
check_cxx_source_compiles("
#include <qore/DBI.h>
int main(void){
qore_dbi_method_list methods;
methods.add(QDBI_METHOD_EXECRAW, nullptr);
return 0;
}" _QORE_HAS_DBI_EXECRAW)
unset(CMAKE_REQUIRED_INCLUDES)
unset(CMAKE_REQUIRED_LIBRARIES)
check_cxx_compiler_flag(-fvisibility=hidden HAVE_GCC_VISIBILITY)
# Check for FreeTDS locale support
if(WITH_FREETDS)
set(CMAKE_REQUIRED_INCLUDES ${FreeTDS_INCLUDE_DIR})
check_cxx_source_compiles("
#include <cspublic.h>
int main(void){
#ifndef CS_SYB_LANG_CHARSET
#error
#endif
return 0;
}" FREETDS_LOCALE)
unset(CMAKE_REQUIRED_INCLUDES)
endif()
# Platform detection
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(LINUX TRUE)
add_definitions(-D_GNU_SOURCE)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(DARWIN TRUE)
elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
set(SOLARIS TRUE)
elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
set(HPUX TRUE)
endif()
# Determine 32/64-bit
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(MODULE_TARGET_BITS 64)
set(SYB_LP64 TRUE)
else()
set(MODULE_TARGET_BITS 32)
endif()
# Debug/Release mode
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DEBUG TRUE)
else()
set(NDEBUG TRUE)
endif()
configure_file(${CMAKE_SOURCE_DIR}/cmake/config.h.cmake config.h)
# Source files - use single-compilation-unit mode to avoid circular header dependencies
set(CPP_SRC
src/single-compilation-unit.cpp
)
set(QORE_DOX_TMPL_SRC
docs/mainpage.dox.tmpl
)
# Build FreeTDS module
if(WITH_FREETDS)
set(freetds_module_name "freetds")
add_library(${freetds_module_name} MODULE ${CPP_SRC})
target_compile_definitions(${freetds_module_name} PRIVATE FREETDS=1 HAVE_CONFIG_H=1)
target_include_directories(${freetds_module_name} PRIVATE
${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}/src
${FreeTDS_INCLUDE_DIR}
)
if(DEFINED ENV{DOXYGEN_EXECUTABLE})
set(DOXYGEN_EXECUTABLE $ENV{DOXYGEN_EXECUTABLE})
endif()
qore_external_binary_module(${freetds_module_name} ${PROJECT_VERSION} ${FreeTDS_LIBS} Threads::Threads)
endif()
# Build Sybase module
if(WITH_SYBASE)
set(sybase_module_name "sybase")
add_library(${sybase_module_name} MODULE ${CPP_SRC})
target_compile_definitions(${sybase_module_name} PRIVATE SYBASE=1 HAVE_CONFIG_H=1)
target_include_directories(${sybase_module_name} PRIVATE
${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}/src
${Sybase_INCLUDE_DIR}
)
qore_external_binary_module(${sybase_module_name} ${PROJECT_VERSION} ${Sybase_LIBS} Threads::Threads)
endif()
qore_dist(${PROJECT_VERSION})
qore_config_info()
# NOTE: find_package(Doxygen) called in qore_external_binary_module()
if(DOXYGEN_FOUND)
qore_wrap_dox(QORE_DOX_SRC ${QORE_DOX_TMPL_SRC})
add_custom_target(QORE_MOD_DOX_FILES DEPENDS ${QORE_DOX_SRC})
add_dependencies(docs-module QORE_MOD_DOX_FILES)
endif()