This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
349 lines (287 loc) · 9.84 KB
/
CMakeLists.txt
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
###################################################
# #
# #
# Angelscript SQL CMake build file #
# #
# #
###################################################
cmake_minimum_required( VERSION 3.6 )
# function to collect all the sources from sub-directories
# into a single list
function(add_sources)
get_property(is_defined GLOBAL PROPERTY SRCS_LIST DEFINED)
if(NOT is_defined)
define_property(GLOBAL PROPERTY SRCS_LIST
BRIEF_DOCS "List of source files"
FULL_DOCS "List of source files to be compiled in one library")
endif()
# make absolute paths
set(SRCS)
foreach(s IN LISTS ARGN)
if(NOT IS_ABSOLUTE "${s}")
get_filename_component(s "${s}" ABSOLUTE)
endif()
list(APPEND SRCS "${s}")
endforeach()
# append to global list
set_property(GLOBAL APPEND PROPERTY SRCS_LIST "${SRCS}")
endfunction(add_sources)
# preprocess sources
function( preprocess_sources )
set(PREP_SRCS PARENT_SCOPE)
get_property(SRCS GLOBAL PROPERTY SRCS_LIST)
foreach(s IN LISTS SRCS)
file(RELATIVE_PATH rs "${CMAKE_CURRENT_SOURCE_DIR}" "${s}")
string(REGEX REPLACE "r$" "" o "${CMAKE_CURRENT_BINARY_DIR}/${rs}")
add_custom_command(
OUTPUT "${o}"
COMMAND ${CMAKE_COMMAND} -E copy "${s}" "${o}"
DEPENDS "${s}"
COMMENT "Creating ${o}"
VERBATIM
)
list(APPEND PREP_SRCS "${s}")
endforeach()
set(PREP_SRCS ${PREP_SRCS} PARENT_SCOPE)
endfunction( preprocess_sources )
function( create_source_groups _src_root_path )
get_property(SRCS GLOBAL PROPERTY SRCS_LIST)
foreach(_source IN ITEMS ${SRCS})
get_filename_component(_source_path "${_source}" PATH)
file(RELATIVE_PATH _source_path_rel "${_src_root_path}" "${_source_path}")
string(REPLACE "/" "\\" _group_path "${_source_path_rel}")
source_group("${_group_path}" FILES "${_source}")
endforeach()
endfunction( create_source_groups )
#Function to clear the sources list.
function( clear_sources )
set_property( GLOBAL PROPERTY SRCS_LIST "" )
set( PREP_SRCS PARENT_SCOPE )
endfunction( clear_sources )
# Function to add include files.
function( add_includes )
get_property(is_defined GLOBAL PROPERTY INCLUDES_LIST DEFINED)
if(NOT is_defined)
define_property(GLOBAL PROPERTY INCLUDES_LIST
BRIEF_DOCS "List of include files"
FULL_DOCS "List of include files to be compiled in one library")
endif()
# make absolute paths
set(INCLUDES)
foreach(s IN LISTS ARGN)
if(NOT IS_ABSOLUTE "${s}")
get_filename_component(s "${s}" ABSOLUTE)
endif()
list(APPEND INCLUDES "${s}")
endforeach()
# append to global list
set_property(GLOBAL APPEND PROPERTY INCLUDES_LIST "${INCLUDES}")
endfunction( add_includes )
# Function to install includes.
function( install_includes _include_root_path )
get_property(INCLUDES GLOBAL PROPERTY INCLUDES_LIST)
foreach(_include IN ITEMS ${INCLUDES})
get_filename_component(_include_path "${_include}" PATH)
file(RELATIVE_PATH _include_path_rel "${_include_root_path}" "${_include_path}")
string(REPLACE "/" "\\" _group_path "${_include_path_rel}")
install( FILES "${_include}" DESTINATION "include/${_group_path}" )
endforeach()
set_property( GLOBAL PROPERTY INCLUDES_LIST "" )
endfunction( install_includes )
macro(configure_msvc_runtime)
if(MSVC)
# Default to statically-linked runtime.
if("${MSVC_RUNTIME}" STREQUAL "")
set(MSVC_RUNTIME "static")
endif()
# Set compiler options.
set(variables
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
if(${MSVC_RUNTIME} STREQUAL "static")
message(STATUS
"MSVC -> forcing use of statically-linked runtime."
)
foreach(variable ${variables})
if(${variable} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
endif()
endforeach()
else()
message(STATUS
"MSVC -> forcing use of dynamically-linked runtime."
)
foreach(variable ${variables})
if(${variable} MATCHES "/MT")
string(REGEX REPLACE "/MT" "/MD" ${variable} "${${variable}}")
endif()
endforeach()
endif()
endif()
endmacro()
project( AngelscriptSQL )
#Needs static CRT to avoid alloc issues.
set( MSVC_RUNTIME "static" )
configure_msvc_runtime()
set(variables
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
message(STATUS "Initial build flags:")
foreach(variable ${variables})
message(STATUS " '${variable}': ${${variable}}")
endforeach()
message(STATUS "")
if( UNIX )
set( LINUX_32BIT_FLAG "-m32" )
else()
set( LINUX_32BIT_FLAG "" )
endif()
#Debug builds should have a distinct name.
if( NOT CMAKE_DEBUG_POSTFIX )
set( CMAKE_DEBUG_POSTFIX d )
endif()
#C++14 support
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y" )
set( AS_STRING_OBJNAME "string" CACHE STRING "The name of the object type used to represent strings" )
#Find shared dependencies
find_library( ANGELSCRIPTLIB Angelscript PATHS external/Angelscript/lib/ )
find_library( ANGELSCRIPTUTILS AngelscriptUtils PATHS external/Angelscript/lib/ )
find_library( ANGELSCRIPTLIBD Angelscriptd PATHS external/Angelscript/lib/ )
find_library( ANGELSCRIPTUTILSD AngelscriptUtilsd PATHS external/Angelscript/lib/ )
if( NOT WIN32 )
#This mucking about is needed because CMake can't figure out how to handle libraries not named lib<name>.a
set( ANGELSCRIPTLIB "-l:\"${ANGELSCRIPTLIB}\"" )
set( ANGELSCRIPTUTILS "-l:\"${ANGELSCRIPTUTILS}\"" )
set( ANGELSCRIPTLIBD "-l:\"${ANGELSCRIPTLIBD}\"" )
set( ANGELSCRIPTUTILSD "-l:\"${ANGELSCRIPTUTILSD}\"" )
endif()
if( NOT WIN32 )
#
#Begin SQLite library
#
MESSAGE( STATUS "Adding SQLite3 library" )
add_subdirectory( external/SQLite )
preprocess_sources()
include_directories(
external/SQLite/include
)
add_library( sqlite3 SHARED ${PREP_SRCS} )
set_target_properties( sqlite3 PROPERTIES COMPILE_FLAGS "${LINUX_32BIT_FLAG}" LINK_FLAGS "${SQL_LINK_FLAGS} ${LINUX_32BIT_FLAG}" )
install( TARGETS sqlite3 DESTINATION lib )
install_includes( "${CMAKE_SOURCE_DIR}/src" )
clear_sources()
#
#End SQLite library
#
endif()
#
#Begin SQL library
#
add_subdirectory( src/Angelscript )
preprocess_sources()
include_directories(
src
external/Angelscript/include
external/SQLite/include
external/MariaDB/include
external/CTPL/include
)
add_library( AngelscriptSQL STATIC ${PREP_SRCS} )
target_compile_definitions( AngelscriptSQL PRIVATE
AS_STRING_OBJNAME="${AS_STRING_OBJNAME}"
)
target_compile_definitions( AngelscriptSQL PRIVATE
_CRT_SECURE_NO_WARNINGS
)
if( WIN32 )
find_library( SQLITE3 "sqlite3${CMAKE_STATIC_LIBRARY_SUFFIX}" PATHS external/SQLite/lib )
find_library( MARIADB "mariadbclient${CMAKE_STATIC_LIBRARY_SUFFIX}" PATHS external/MariaDB/lib )
set( PTHREAD "" )
else()
set( SQLITE3 "sqlite3" )
find_library( MARIADB "${CMAKE_SHARED_LIBRARY_PREFIX}mariadb.so.2" PATHS external/MariaDB/lib )
set( PTHREAD "pthread" )
endif()
#Link with SQL dependencies
target_link_libraries( AngelscriptSQL
optimized "${ANGELSCRIPTLIB}"
optimized "${ANGELSCRIPTUTILS}"
debug "${ANGELSCRIPTLIBD}"
debug "${ANGELSCRIPTUTILSD}"
"${SQLITE3}"
"${MARIADB}"
"${PTHREAD}"
)
set_target_properties( AngelscriptSQL PROPERTIES COMPILE_FLAGS "${LINUX_32BIT_FLAG}" LINK_FLAGS "${SQL_LINK_FLAGS} ${LINUX_32BIT_FLAG}" )
#Properly named pdb. By default it always uses the base name.
set_target_properties( AngelscriptSQL PROPERTIES COMPILE_PDB_NAME_DEBUG "AngelscriptSQLd" )
#Match the debug version so its relative position is the same.
set_target_properties( AngelscriptSQL PROPERTIES COMPILE_PDB_NAME_RELWITHDEBINFO "AngelscriptSQL" )
#Create filters
create_source_groups( "${CMAKE_SOURCE_DIR}" )
install( TARGETS AngelscriptSQL DESTINATION lib )
install_includes( "${CMAKE_SOURCE_DIR}/src" )
#Install the pdb files.
if( WIN32 )
install( FILES ${CMAKE_BINARY_DIR}/Debug/AngelscriptSQLd.pdb DESTINATION lib CONFIGURATIONS Debug )
install( FILES ${CMAKE_BINARY_DIR}/RelWithDebInfo/AngelscriptSQL.pdb DESTINATION lib CONFIGURATIONS RelWithDebInfo )
endif()
clear_sources()
#
#End SQL library
#
#
#Test exe
#
add_subdirectory( src/test )
preprocess_sources()
add_executable( AngelscriptSQLTest ${PREP_SRCS} )
target_compile_definitions( AngelscriptSQLTest PRIVATE
_CRT_SECURE_NO_WARNINGS
AS_STRING_OBJNAME="${AS_STRING_OBJNAME}"
)
target_link_libraries( AngelscriptSQLTest
AngelscriptSQL
)
set_target_properties( AngelscriptSQLTest PROPERTIES COMPILE_FLAGS "${LINUX_32BIT_FLAG}" LINK_FLAGS "${TEST_LINK_FLAGS} ${LINUX_32BIT_FLAG}" )
#Create filters
create_source_groups( "${CMAKE_SOURCE_DIR}" )
#Set the startup project to the client
#TODO: does this even work?
set_property( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT AngelscriptSQLTest )
clear_sources()
#Copy the sqlite3 dll so the exe can get to it
add_custom_command( TARGET AngelscriptSQLTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/external/SQLite/lib/sqlite3.dll"
$<TARGET_FILE_DIR:AngelscriptSQLTest>
)
#Copy the mariadb dll so the exe can get to it
add_custom_command( TARGET AngelscriptSQLTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/external/MariaDB/lib/libmariadb.dll"
$<TARGET_FILE_DIR:AngelscriptSQLTest>
)
#Copy the mariadb library so the exe can get to it
add_custom_command( TARGET AngelscriptSQLTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/external/MariaDB/lib/libmariadb.so.2"
$<TARGET_FILE_DIR:AngelscriptSQLTest>
)
#
#End test exe
#