| 1 |
################################################################################ |
| 2 |
# |
| 3 |
# macros and functions |
| 4 |
# |
| 5 |
################################################################################ |
| 6 |
|
| 7 |
######################################## |
| 8 |
# FUNCTION set_output_directory |
| 9 |
######################################## |
| 10 |
function(set_output_directory target dir) |
| 11 |
set(out ${output_dir}) |
| 12 |
if (MSVC OR XCODE) # multiconfiguration builds |
| 13 |
set(out ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) |
| 14 |
endif() |
| 15 |
if ("${ARGV2}" STREQUAL "CURRENT_DIR") |
| 16 |
set(out .) |
| 17 |
if (UNIX AND "${dir}" STREQUAL ".") |
| 18 |
set(dir bin) |
| 19 |
endif() |
| 20 |
endif() |
| 21 |
if (MSVC OR XCODE) |
| 22 |
foreach(conf ${CMAKE_CONFIGURATION_TYPES}) |
| 23 |
string(TOUPPER ${conf} conf2) |
| 24 |
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${conf2} ${out}/${conf}/${dir}) |
| 25 |
set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${conf2} ${out}/${conf}/${dir}) |
| 26 |
endforeach() |
| 27 |
else() # single configuration |
| 28 |
add_custom_command(TARGET ${target} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory ${out}/${dir}) |
| 29 |
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${out}/${dir}) |
| 30 |
set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${out}/${dir}) |
| 31 |
endif() |
| 32 |
endfunction(set_output_directory) |
| 33 |
|
| 34 |
######################################## |
| 35 |
# FUNCTION set_output_directory_unix |
| 36 |
######################################## |
| 37 |
function(set_output_directory_unix target dir) |
| 38 |
if (UNIX) |
| 39 |
set_output_directory(${target} ${dir} ${ARGN}) |
| 40 |
endif() |
| 41 |
endfunction(set_output_directory_unix) |
| 42 |
|
| 43 |
######################################## |
| 44 |
# FUNCTION set_exported_symbols |
| 45 |
######################################## |
| 46 |
if (WIN32) |
| 47 |
function(set_exported_symbols target filename) |
| 48 |
set(def_file ${filename}.def) |
| 49 |
if ("${filename}" STREQUAL "empty") |
| 50 |
set(def_file) |
| 51 |
elseif("${filename}" STREQUAL "fbplugin") |
| 52 |
set(def_file "plugin.def") |
| 53 |
endif() |
| 54 |
if (NOT "${def_file}" STREQUAL "") |
| 55 |
if (MSVC) |
| 56 |
set_target_properties(${target} PROPERTIES LINK_FLAGS "/DEF:\"${CMAKE_SOURCE_DIR}/builds/win32/defs/${def_file}\"") |
| 57 |
endif() |
| 58 |
if (MINGW) |
| 59 |
#set_target_properties(${target} PROPERTIES LINK_FLAGS "-Wl,${CMAKE_SOURCE_DIR}/builds/win32/defs/${def_file}") |
| 60 |
endif() |
| 61 |
endif() |
| 62 |
endfunction(set_exported_symbols) |
| 63 |
endif() |
| 64 |
|
| 65 |
if (UNIX) |
| 66 |
function(set_exported_symbols target filename) |
| 67 |
set(def_file ${filename}.vers) |
| 68 |
if ("${filename}" STREQUAL "ib_udf") |
| 69 |
set(def_file) |
| 70 |
endif() |
| 71 |
if (NOT "${def_file}" STREQUAL "") |
| 72 |
set(wl_option "--version-script") |
| 73 |
if (APPLE) |
| 74 |
set(wl_option "-exported_symbols_list") |
| 75 |
endif() |
| 76 |
set_target_properties(${target} PROPERTIES LINK_FLAGS -Wl,${wl_option},${CMAKE_BINARY_DIR}/builds/posix/${def_file}) |
| 77 |
endif() |
| 78 |
endfunction(set_exported_symbols) |
| 79 |
endif(UNIX) |
| 80 |
|
| 81 |
|
| 82 |
######################################## |
| 83 |
# FUNCTION epp_process |
| 84 |
######################################## |
| 85 |
function(epp_process type files) |
| 86 |
set(epp_suffix ".${type}.cpp") |
| 87 |
|
| 88 |
foreach(F ${${files}}) |
| 89 |
set(in ${CMAKE_CURRENT_SOURCE_DIR}/${F}) |
| 90 |
set(out ${CMAKE_CURRENT_BINARY_DIR}/${F}${epp_suffix}) |
| 91 |
|
| 92 |
get_filename_component(dir ${out} PATH) |
| 93 |
if (MSVC OR XCODE) |
| 94 |
set(dir ${dir}/$<CONFIG>) |
| 95 |
endif() |
| 96 |
|
| 97 |
if ("${type}" STREQUAL "boot") |
| 98 |
add_custom_command( |
| 99 |
OUTPUT ${out} |
| 100 |
DEPENDS gpre_boot ${in} |
| 101 |
COMMENT "Calling GPRE boot for ${F}" |
| 102 |
# |
| 103 |
COMMAND ${CMAKE_COMMAND} -E make_directory ${dir} |
| 104 |
COMMAND ${ARGN} ${in} ${out} |
| 105 |
) |
| 106 |
elseif ("${type}" STREQUAL "master") |
| 107 |
get_filename_component(file ${out} NAME) |
| 108 |
set(dir ${dir}/${file}.d) |
| 109 |
add_custom_command( |
| 110 |
OUTPUT ${out} |
| 111 |
DEPENDS databases boot_gpre ${in} |
| 112 |
COMMENT "Calling GPRE master for ${F}" |
| 113 |
# |
| 114 |
COMMAND ${CMAKE_COMMAND} -E make_directory ${dir} |
| 115 |
COMMAND ${CMAKE_COMMAND} -E copy_if_different metadata.fdb ${dir}/yachts.lnk |
| 116 |
COMMAND ${CMAKE_COMMAND} -E copy_if_different security.fdb ${dir}/security.fdb |
| 117 |
COMMAND ${CMAKE_COMMAND} -E copy_if_different msg.fdb ${dir}/msg.fdb |
| 118 |
COMMAND ${CMAKE_COMMAND} -E copy_if_different help.fdb ${dir}/help.fdb |
| 119 |
COMMAND ${ARGN} -b ${dir}/ ${in} ${out} |
| 120 |
) |
| 121 |
endif() |
| 122 |
endforeach() |
| 123 |
endfunction(epp_process) |
| 124 |
|
| 125 |
######################################## |
| 126 |
# FUNCTION add_epp_suffix |
| 127 |
######################################## |
| 128 |
function(add_epp_suffix files suffix) |
| 129 |
foreach(F ${${files}}) |
| 130 |
list(APPEND ${files}_${suffix} ${CMAKE_CURRENT_SOURCE_DIR}/${F}) |
| 131 |
list(APPEND ${files}_${suffix} ${GENERATED_DIR}/${F}.${suffix}.cpp) |
| 132 |
endforeach() |
| 133 |
set_source_files_properties(${${files}_${suffix}} PROPERTIES GENERATED TRUE) |
| 134 |
set(${files}_${suffix} ${${files}_${suffix}} PARENT_SCOPE) |
| 135 |
endfunction(add_epp_suffix) |
| 136 |
|
| 137 |
######################################## |
| 138 |
# FUNCTION set_win32 |
| 139 |
######################################## |
| 140 |
function(set_win32 var) |
| 141 |
if (WIN32) |
| 142 |
set(${var} "${ARGN}" PARENT_SCOPE) |
| 143 |
endif() |
| 144 |
endfunction(set_win32) |
| 145 |
|
| 146 |
######################################## |
| 147 |
# FUNCTION set_unix |
| 148 |
######################################## |
| 149 |
function(set_unix var) |
| 150 |
if (UNIX) |
| 151 |
set(${var} "${ARGN}" PARENT_SCOPE) |
| 152 |
endif() |
| 153 |
endfunction(set_unix) |
| 154 |
|
| 155 |
######################################## |
| 156 |
# FUNCTION set_apple |
| 157 |
######################################## |
| 158 |
function(set_apple var) |
| 159 |
if (APPLE) |
| 160 |
set(${var} "${ARGN}" PARENT_SCOPE) |
| 161 |
endif() |
| 162 |
endfunction(set_apple) |
| 163 |
|
| 164 |
######################################## |
| 165 |
# FUNCTION add_src_win32 |
| 166 |
######################################## |
| 167 |
function(add_src_win32 var) |
| 168 |
if (WIN32) |
| 169 |
set(${var} ${${var}} ${ARGN} PARENT_SCOPE) |
| 170 |
endif() |
| 171 |
endfunction(add_src_win32) |
| 172 |
|
| 173 |
######################################## |
| 174 |
# FUNCTION add_src_unix |
| 175 |
######################################## |
| 176 |
function(add_src_unix var) |
| 177 |
if (UNIX) |
| 178 |
set(${var} ${${var}} ${ARGN} PARENT_SCOPE) |
| 179 |
endif() |
| 180 |
endfunction(add_src_unix) |
| 181 |
|
| 182 |
######################################## |
| 183 |
# FUNCTION add_src_unix_not_apple |
| 184 |
######################################## |
| 185 |
function(add_src_unix_not_apple var) |
| 186 |
if (UNIX AND NOT APPLE) |
| 187 |
set(${var} ${${var}} ${ARGN} PARENT_SCOPE) |
| 188 |
endif() |
| 189 |
endfunction(add_src_unix_not_apple) |
| 190 |
|
| 191 |
######################################## |
| 192 |
# FUNCTION add_src_apple |
| 193 |
######################################## |
| 194 |
function(add_src_apple var) |
| 195 |
if (APPLE) |
| 196 |
set(${var} ${${var}} ${ARGN} PARENT_SCOPE) |
| 197 |
endif() |
| 198 |
endfunction(add_src_apple) |
| 199 |
|
| 200 |
######################################## |
| 201 |
# FUNCTION copy_and_rename_lib |
| 202 |
######################################## |
| 203 |
function(copy_and_rename_lib target name) |
| 204 |
set(name2 $<TARGET_FILE_DIR:${target}>/${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX}) |
| 205 |
add_custom_command( |
| 206 |
TARGET ${target} |
| 207 |
POST_BUILD |
| 208 |
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${target}> ${name2} |
| 209 |
) |
| 210 |
endfunction(copy_and_rename_lib) |
| 211 |
|
| 212 |
######################################## |
| 213 |
# FUNCTION project_group |
| 214 |
######################################## |
| 215 |
function(project_group target name) |
| 216 |
set_target_properties(${target} PROPERTIES FOLDER ${name}) |
| 217 |
endfunction(project_group) |
| 218 |
|
| 219 |
######################################## |
| 220 |
# FUNCTION set_generated_directory |
| 221 |
######################################## |
| 222 |
function(set_generated_directory) |
| 223 |
if (NOT CMAKE_CROSSCOMPILING) |
| 224 |
set(GENERATED_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE) |
| 225 |
else() |
| 226 |
string(REPLACE "${CMAKE_BINARY_DIR}" "${NATIVE_BUILD_DIR}" GENERATED_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 227 |
set(GENERATED_DIR ${GENERATED_DIR} PARENT_SCOPE) |
| 228 |
endif() |
| 229 |
endfunction(set_generated_directory) |
| 230 |
|
| 231 |
######################################## |
| 232 |
# FUNCTION add_dependencies_cc (cross compile) |
| 233 |
######################################## |
| 234 |
function(add_dependencies_cc target) |
| 235 |
if (NOT CMAKE_CROSSCOMPILING) |
| 236 |
add_dependencies(${target} ${ARGN}) |
| 237 |
endif() |
| 238 |
endfunction(add_dependencies_cc) |
| 239 |
|
| 240 |
######################################## |
| 241 |
# FUNCTION add_dependencies_unix_cc (cross compile) |
| 242 |
######################################## |
| 243 |
function(add_dependencies_unix_cc target) |
| 244 |
if (UNIX) |
| 245 |
add_dependencies_cc(${target} ${ARGN}) |
| 246 |
endif() |
| 247 |
endfunction(add_dependencies_unix_cc) |
| 248 |
|
| 249 |
######################################## |
| 250 |
# FUNCTION crosscompile_prebuild_steps |
| 251 |
######################################## |
| 252 |
function(crosscompile_prebuild_steps) |
| 253 |
if (CMAKE_CROSSCOMPILING) |
| 254 |
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) |
| 255 |
endif() |
| 256 |
endfunction(crosscompile_prebuild_steps) |
| 257 |
|
| 258 |
######################################## |
| 259 |
# FUNCTION create_command |
| 260 |
######################################## |
| 261 |
function(create_command command type out) |
| 262 |
set(dir ${output_dir}) |
| 263 |
if ("${type}" STREQUAL "boot") |
| 264 |
set(dir ${boot_dir}) |
| 265 |
endif() |
| 266 |
|
| 267 |
set_win32(env "PATH=${dir}\;%PATH%") |
| 268 |
set_unix (env "PATH=${dir}/bin:$PATH") |
| 269 |
set(env "${env}" |
| 270 |
FIREBIRD=${dir} |
| 271 |
) |
| 272 |
|
| 273 |
set(cmd_name ${command}) |
| 274 |
if (MSVC OR XCODE) |
| 275 |
set(conf _$<CONFIG>) |
| 276 |
endif() |
| 277 |
|
| 278 |
set(pre_cmd) |
| 279 |
set(ext .sh) |
| 280 |
set(export export) |
| 281 |
set(options $*) |
| 282 |
set(perm) |
| 283 |
if (WIN32) |
| 284 |
set(pre_cmd @) |
| 285 |
set(ext .bat) |
| 286 |
set(export set) |
| 287 |
set(options %*) |
| 288 |
endif() |
| 289 |
set(cmd_name ${cmd_name}${conf}${ext}) |
| 290 |
set(cmd_name ${CMAKE_BINARY_DIR}/src/${cmd_name}) |
| 291 |
|
| 292 |
set(content) |
| 293 |
foreach(e ${env}) |
| 294 |
set(content "${content}${pre_cmd}${export} ${e}\n") |
| 295 |
endforeach() |
| 296 |
|
| 297 |
set(cmd $<TARGET_FILE:${cmd}>) |
| 298 |
set(content "${content}${pre_cmd}${cmd} ${options}") |
| 299 |
file(GENERATE OUTPUT ${cmd_name} CONTENT "${content}") |
| 300 |
|
| 301 |
if (UNIX) |
| 302 |
set(cmd_name chmod u+x ${cmd_name} COMMAND ${cmd_name}) |
| 303 |
endif() |
| 304 |
|
| 305 |
string(TOUPPER ${command} CMD) |
| 306 |
set(${CMD}_CMD ${cmd_name} PARENT_SCOPE) |
| 307 |
set(${out} ${CMD}_CMD PARENT_SCOPE) |
| 308 |
endfunction(create_command) |
| 309 |
|
| 310 |
######################################## |
| 311 |
# FUNCTION create_boot_commands |
| 312 |
######################################## |
| 313 |
function(create_boot_commands) |
| 314 |
set(cmd_list |
| 315 |
boot_isql |
| 316 |
boot_gpre |
| 317 |
boot_gbak |
| 318 |
boot_gfix |
| 319 |
build_msg |
| 320 |
codes |
| 321 |
gpre_boot |
| 322 |
) |
| 323 |
foreach(cmd ${cmd_list}) |
| 324 |
create_command(${cmd} boot out) |
| 325 |
set(${out} ${${out}} PARENT_SCOPE) |
| 326 |
endforeach() |
| 327 |
endfunction(create_boot_commands) |
| 328 |
|
| 329 |
######################################## |
| 330 |
# FUNCTION create_master_commands |
| 331 |
######################################## |
| 332 |
function(create_master_commands) |
| 333 |
set(cmd_list |
| 334 |
isql |
| 335 |
gpre |
| 336 |
empbuild |
| 337 |
) |
| 338 |
foreach(cmd ${cmd_list}) |
| 339 |
create_command(${cmd} master out) |
| 340 |
set(${out} ${${out}} PARENT_SCOPE) |
| 341 |
endforeach() |
| 342 |
endfunction(create_master_commands) |
| 343 |
|
| 344 |
################################################################################ |