-
-
Notifications
You must be signed in to change notification settings - Fork 268
Expand file tree
/
Copy pathBuildFunctions.cmake
More file actions
341 lines (307 loc) · 10.8 KB
/
BuildFunctions.cmake
File metadata and controls
341 lines (307 loc) · 10.8 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
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
################################################################################
#
# macros and functions
#
################################################################################
########################################
# FUNCTION set_output_directory
########################################
function(set_output_directory target dir)
set(out ${output_dir})
if (MSVC OR XCODE) # multiconfiguration builds
set(out ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif()
if ("${ARGV2}" STREQUAL "CURRENT_DIR")
set(out .)
if (UNIX AND "${dir}" STREQUAL ".")
set(dir bin)
endif()
endif()
if (MSVC OR XCODE)
foreach(conf ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${conf} conf2)
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${conf2} ${out}/${conf}/${dir})
set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${conf2} ${out}/${conf}/${dir})
endforeach()
else() # single configuration
add_custom_command(TARGET ${target} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory ${out}/${dir})
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${out}/${dir})
set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${out}/${dir})
endif()
endfunction(set_output_directory)
########################################
# FUNCTION set_output_directory_unix
########################################
function(set_output_directory_unix target dir)
if (UNIX)
set_output_directory(${target} ${dir} ${ARGN})
endif()
endfunction(set_output_directory_unix)
########################################
# FUNCTION set_exported_symbols
########################################
if (WIN32)
function(set_exported_symbols target filename)
set(def_file ${filename}.def)
if ("${filename}" STREQUAL "empty")
set(def_file)
elseif("${filename}" STREQUAL "fbplugin")
set(def_file "plugin.def")
endif()
if (NOT "${def_file}" STREQUAL "")
if (MSVC)
set_target_properties(${target} PROPERTIES LINK_FLAGS "/DEF:\"${CMAKE_SOURCE_DIR}/builds/win32/defs/${def_file}\"")
endif()
if (MINGW)
#set_target_properties(${target} PROPERTIES LINK_FLAGS "-Wl,${CMAKE_SOURCE_DIR}/builds/win32/defs/${def_file}")
endif()
endif()
endfunction(set_exported_symbols)
endif()
if (UNIX)
function(set_exported_symbols target filename)
set(def_file ${filename}.vers)
if ("${filename}" STREQUAL "ib_udf")
set(def_file)
endif()
if (NOT "${def_file}" STREQUAL "")
set(wl_option "--version-script")
if (APPLE)
set(wl_option "-exported_symbols_list")
endif()
set_target_properties(${target} PROPERTIES LINK_FLAGS -Wl,${wl_option},${CMAKE_BINARY_DIR}/builds/posix/${def_file})
endif()
endfunction(set_exported_symbols)
endif(UNIX)
########################################
# FUNCTION epp_process
########################################
function(epp_process type files)
set(epp_suffix ".${type}.cpp")
foreach(F ${${files}})
set(in ${CMAKE_CURRENT_SOURCE_DIR}/${F})
set(out ${CMAKE_CURRENT_BINARY_DIR}/${F}${epp_suffix})
get_filename_component(dir ${out} PATH)
if (MSVC OR XCODE)
set(dir ${dir}/$<CONFIG>)
endif()
if ("${type}" STREQUAL "boot")
add_custom_command(
OUTPUT ${out}
DEPENDS gpre_boot ${in}
COMMENT "Calling GPRE boot for ${F}"
#
COMMAND ${CMAKE_COMMAND} -E make_directory ${dir}
COMMAND ${ARGN} ${in} ${out}
)
elseif ("${type}" STREQUAL "master")
get_filename_component(file ${out} NAME)
set(dir ${dir}/${file}.d)
add_custom_command(
OUTPUT ${out}
DEPENDS databases boot_gpre ${in}
COMMENT "Calling GPRE master for ${F}"
#
COMMAND ${CMAKE_COMMAND} -E make_directory ${dir}
COMMAND ${CMAKE_COMMAND} -E copy_if_different metadata.fdb ${dir}/yachts.lnk
COMMAND ${CMAKE_COMMAND} -E copy_if_different security.fdb ${dir}/security.fdb
COMMAND ${ARGN} -b ${dir}/ ${in} ${out}
)
endif()
endforeach()
endfunction(epp_process)
########################################
# FUNCTION add_epp_suffix
########################################
function(add_epp_suffix files suffix)
foreach(F ${${files}})
list(APPEND ${files}_${suffix} ${CMAKE_CURRENT_SOURCE_DIR}/${F})
list(APPEND ${files}_${suffix} ${GENERATED_DIR}/${F}.${suffix}.cpp)
endforeach()
set_source_files_properties(${${files}_${suffix}} PROPERTIES GENERATED TRUE)
set(${files}_${suffix} ${${files}_${suffix}} PARENT_SCOPE)
endfunction(add_epp_suffix)
########################################
# FUNCTION set_win32
########################################
function(set_win32 var)
if (WIN32)
set(${var} "${ARGN}" PARENT_SCOPE)
endif()
endfunction(set_win32)
########################################
# FUNCTION set_unix
########################################
function(set_unix var)
if (UNIX)
set(${var} "${ARGN}" PARENT_SCOPE)
endif()
endfunction(set_unix)
########################################
# FUNCTION set_apple
########################################
function(set_apple var)
if (APPLE)
set(${var} "${ARGN}" PARENT_SCOPE)
endif()
endfunction(set_apple)
########################################
# FUNCTION add_src_win32
########################################
function(add_src_win32 var)
if (WIN32)
set(${var} ${${var}} ${ARGN} PARENT_SCOPE)
endif()
endfunction(add_src_win32)
########################################
# FUNCTION add_src_unix
########################################
function(add_src_unix var)
if (UNIX)
set(${var} ${${var}} ${ARGN} PARENT_SCOPE)
endif()
endfunction(add_src_unix)
########################################
# FUNCTION add_src_unix_not_apple
########################################
function(add_src_unix_not_apple var)
if (UNIX AND NOT APPLE)
set(${var} ${${var}} ${ARGN} PARENT_SCOPE)
endif()
endfunction(add_src_unix_not_apple)
########################################
# FUNCTION add_src_apple
########################################
function(add_src_apple var)
if (APPLE)
set(${var} ${${var}} ${ARGN} PARENT_SCOPE)
endif()
endfunction(add_src_apple)
########################################
# FUNCTION copy_and_rename_lib
########################################
function(copy_and_rename_lib target name)
set(name2 $<TARGET_FILE_DIR:${target}>/${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX})
add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${target}> ${name2}
)
endfunction(copy_and_rename_lib)
########################################
# FUNCTION project_group
########################################
function(project_group target name)
set_target_properties(${target} PROPERTIES FOLDER ${name})
endfunction(project_group)
########################################
# FUNCTION set_generated_directory
########################################
function(set_generated_directory)
if (NOT CMAKE_CROSSCOMPILING)
set(GENERATED_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
else()
string(REPLACE "${CMAKE_BINARY_DIR}" "${NATIVE_BUILD_DIR}" GENERATED_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(GENERATED_DIR ${GENERATED_DIR} PARENT_SCOPE)
endif()
endfunction(set_generated_directory)
########################################
# FUNCTION add_dependencies_cc (cross compile)
########################################
function(add_dependencies_cc target)
if (NOT CMAKE_CROSSCOMPILING)
add_dependencies(${target} ${ARGN})
endif()
endfunction(add_dependencies_cc)
########################################
# FUNCTION add_dependencies_unix_cc (cross compile)
########################################
function(add_dependencies_unix_cc target)
if (UNIX)
add_dependencies_cc(${target} ${ARGN})
endif()
endfunction(add_dependencies_unix_cc)
########################################
# FUNCTION crosscompile_prebuild_steps
########################################
function(crosscompile_prebuild_steps)
if (CMAKE_CROSSCOMPILING)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NATIVE_BUILD_DIR}/src/include/gen/parse.h ${CMAKE_BINARY_DIR}/src/include/gen/parse.h)
endif()
endfunction(crosscompile_prebuild_steps)
########################################
# FUNCTION create_command
########################################
function(create_command command type out)
set(dir ${output_dir})
if ("${type}" STREQUAL "boot")
set(dir ${boot_dir})
endif()
set_win32(env "PATH=${dir}\;%PATH%")
set_unix (env "PATH=${dir}/bin:$PATH")
set(env "${env}"
FIREBIRD=${dir}
)
set(cmd_name ${command})
if (MSVC OR XCODE)
set(conf _$<CONFIG>)
endif()
set(pre_cmd)
set(ext .sh)
set(export export)
set(options $*)
set(perm)
if (WIN32)
set(pre_cmd @)
set(ext .bat)
set(export set)
set(options %*)
endif()
set(cmd_name ${cmd_name}${conf}${ext})
set(cmd_name ${CMAKE_BINARY_DIR}/src/${cmd_name})
set(content)
foreach(e ${env})
set(content "${content}${pre_cmd}${export} ${e}\n")
endforeach()
set(cmd $<TARGET_FILE:${cmd}>)
set(content "${content}${pre_cmd}${cmd} ${options}")
file(GENERATE OUTPUT ${cmd_name} CONTENT "${content}")
if (UNIX)
set(cmd_name chmod u+x ${cmd_name} COMMAND ${cmd_name})
endif()
string(TOUPPER ${command} CMD)
set(${CMD}_CMD ${cmd_name} PARENT_SCOPE)
set(${out} ${CMD}_CMD PARENT_SCOPE)
endfunction(create_command)
########################################
# FUNCTION create_boot_commands
########################################
function(create_boot_commands)
set(cmd_list
boot_isql
boot_gpre
boot_gbak
boot_gfix
build_file
gpre_boot
)
foreach(cmd ${cmd_list})
create_command(${cmd} boot out)
set(${out} ${${out}} PARENT_SCOPE)
endforeach()
endfunction(create_boot_commands)
########################################
# FUNCTION create_master_commands
########################################
function(create_master_commands)
set(cmd_list
isql
gpre
empbuild
)
foreach(cmd ${cmd_list})
create_command(${cmd} master out)
set(${out} ${${out}} PARENT_SCOPE)
endforeach()
endfunction(create_master_commands)
################################################################################