From 25fd28f60477569a0ec92bf9a090a8c7d8e37427 Mon Sep 17 00:00:00 2001 From: egorpugin Date: Fri, 6 Feb 2015 12:58:17 +0000 Subject: [PATCH] [build] [cmake] Call custom commands via scripts. --- CMakeLists.txt | 9 +++ builds/cmake/BuildFunctions.cmake | 96 ++++++++++++++++++++++++++++--- examples/CMakeLists.txt | 7 +-- src/CMakeLists.txt | 42 +++++++------- 4 files changed, 120 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bceb99580e..afcc11f606 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,12 +75,14 @@ endif() ######################################## set(output_dir ${CMAKE_BINARY_DIR}/${PROJECT_NAME}) +set(boot_dir ${CMAKE_BINARY_DIR}/src) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${output_dir}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${output_dir}) if (MSVC OR XCODE) set(output_dir ${output_dir}/$) + set(boot_dir ${boot_dir}/$) endif() if (MSVC AND DEFAULT_CONFIGURATION) @@ -278,6 +280,13 @@ endif() include(BuildFunctions) +if (NOT CMAKE_CROSSCOMPILING) + +create_boot_commands() +create_master_commands() + +endif() # if (NOT CMAKE_CROSSCOMPILING) + crosscompile_prebuild_steps() include_directories("extern/libtommath") diff --git a/builds/cmake/BuildFunctions.cmake b/builds/cmake/BuildFunctions.cmake index 4d803bd4c1..d15a7ae031 100644 --- a/builds/cmake/BuildFunctions.cmake +++ b/builds/cmake/BuildFunctions.cmake @@ -90,7 +90,10 @@ function(epp_process type files) set(out ${CMAKE_CURRENT_BINARY_DIR}/${F}${epp_suffix}) get_filename_component(dir ${out} PATH) - + if (MSVC OR XCODE) + set(dir ${dir}/$) + endif() + if ("${type}" STREQUAL "boot") add_custom_command( OUTPUT ${out} @@ -253,14 +256,89 @@ function(crosscompile_prebuild_steps) endfunction(crosscompile_prebuild_steps) ####################################### -# FUNCTION wrap_command_with_path +# FUNCTION create_command ####################################### -function(wrap_command_with_path command) - set(cmd ${ARGN}) - set_win32(cmd set PATH=%PATH%\\\\;${output_dir} COMMAND ${cmd}) - set_unix (cmd PATH=${output_dir}/bin ${cmd}) - set_apple(cmd DYLD_LIBRARY_PATH=${output_dir}/plugins:${output_dir}/lib ${cmd}) - set(${command} "${cmd}" PARENT_SCOPE) -endfunction(wrap_command_with_path) +function(create_command command type out) + set(dir ${output_dir}) + if ("${type}" STREQUAL "boot") + set(dir ${boot_dir}) + endif() + + set_win32(env "PATH=%PATH%\;${dir}") + set_unix (env "PATH=$PATH:${dir}/bin") + set(env "${env}" + FIREBIRD=${dir} + ) + + set(cmd_name ${command}) + if (MSVC OR XCODE) + set(conf _$) + 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 $) + 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_msg + codes + 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) ############################################################################### diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 0d84d2ae50..324a69a8b9 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -18,7 +18,7 @@ add_custom_command( isql ${CMAKE_CURRENT_SOURCE_DIR}/empbuild/empbld.sql COMMAND ${CMAKE_COMMAND} -E remove empbuild.fdb - COMMAND isql -q -i ${CMAKE_CURRENT_SOURCE_DIR}/empbuild/empbld.sql + COMMAND ${ISQL_CMD} -q -i ${CMAKE_CURRENT_SOURCE_DIR}/empbuild/empbld.sql COMMAND ${CMAKE_COMMAND} -E copy_if_different empbuild.fdb empbuild_.fdb COMMAND ${CMAKE_COMMAND} -E remove empbuild.fdb COMMAND ${CMAKE_COMMAND} -E copy_if_different empbuild_.fdb empbuild.fdb @@ -30,7 +30,7 @@ add_custom_command( ${CMAKE_CURRENT_SOURCE_DIR}/empbuild/empbuild.e empbuild.fdb COMMENT "Calling GPRE for empbuild.e" - COMMAND gpre -r -m -n -z ${CMAKE_CURRENT_SOURCE_DIR}/empbuild/empbuild.e empbuild.c + COMMAND ${GPRE_CMD} -r -m -n ${CMAKE_CURRENT_SOURCE_DIR}/empbuild/empbuild.e empbuild.c ) add_executable (empbuild empbuild.c empbuild.fdb ${CMAKE_CURRENT_SOURCE_DIR}/empbuild/empbuild.e) @@ -54,7 +54,6 @@ endforeach() # BUILD STEP employee_db ######################################## -wrap_command_with_path(EMPBUILD_CMD $ employe2_.fdb) add_custom_command( OUTPUT employe2.fdb DEPENDS @@ -63,7 +62,7 @@ add_custom_command( ${files} COMMAND ${CMAKE_COMMAND} -E remove employe2.fdb COMMAND ${CMAKE_COMMAND} -E remove employe2_.fdb - COMMAND ${EMPBUILD_CMD} + COMMAND ${EMPBUILD_CMD} employe2_.fdb COMMAND ${CMAKE_COMMAND} -E copy_if_different employe2_.fdb employe2.fdb ) add_custom_target (employee_db ALL DEPENDS employe2.fdb SOURCES ${files}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6505c9d707..1b93317df7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -70,16 +70,16 @@ set(epp_master_files if (NOT CMAKE_CROSSCOMPILING) -epp_process(boot epp_boot_internal_files gpre_boot -lang_internal -n -m) -epp_process(boot epp_boot_ocxx_files gpre_boot -lang_internal -n -ids -ocxx) -epp_process(boot epp_boot_files gpre_boot -n -m) -epp_process(boot epp_boot_gds_files gpre_boot -n -ids -gds_cxx) +epp_process(boot epp_boot_internal_files ${GPRE_BOOT_CMD} -lang_internal -n -m) +epp_process(boot epp_boot_ocxx_files ${GPRE_BOOT_CMD} -lang_internal -n -ids -ocxx) +epp_process(boot epp_boot_files ${GPRE_BOOT_CMD} -n -m) +epp_process(boot epp_boot_gds_files ${GPRE_BOOT_CMD} -n -ids -gds_cxx) -epp_process(master epp_boot_internal_files boot_gpre -n -m) -epp_process(master epp_boot_ocxx_files boot_gpre -n -ids -ocxx) -epp_process(master epp_boot_files boot_gpre -n -m) -epp_process(master epp_boot_gds_files boot_gpre -n -ids -gds_cxx) -epp_process(master epp_master_files boot_gpre -n -m) +epp_process(master epp_boot_internal_files ${BOOT_GPRE_CMD} -n -m) +epp_process(master epp_boot_ocxx_files ${BOOT_GPRE_CMD} -n -ids -ocxx) +epp_process(master epp_boot_files ${BOOT_GPRE_CMD} -n -m) +epp_process(master epp_boot_gds_files ${BOOT_GPRE_CMD} -n -ids -gds_cxx) +epp_process(master epp_master_files ${BOOT_GPRE_CMD} -n -m) ################################################################################ @@ -118,11 +118,11 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E remove security.fdb COMMAND ${CMAKE_COMMAND} -E remove security_.fdb COMMAND ${CMAKE_COMMAND} -E echo "create database 'security_.fdb';" > create_db_security.sql - COMMAND boot_isql -q -i create_db_security.sql - COMMAND boot_gfix -write async security_.fdb - COMMAND boot_isql -q security_.fdb -i ${CMAKE_CURRENT_SOURCE_DIR}/dbs/security.sql + COMMAND ${BOOT_ISQL_CMD} -q -i create_db_security.sql + COMMAND ${BOOT_GFIX_CMD} -write async security_.fdb + COMMAND ${BOOT_ISQL_CMD} -q security_.fdb -i ${CMAKE_CURRENT_SOURCE_DIR}/dbs/security.sql COMMAND ${CMAKE_COMMAND} -E copy_if_different security_.fdb security.fdb - COMMAND boot_gfix -write sync security.fdb + COMMAND ${BOOT_GFIX_CMD} -write sync security.fdb ) add_custom_command( OUTPUT metadata.fdb @@ -132,7 +132,7 @@ add_custom_command( # COMMAND ${CMAKE_COMMAND} -E remove metadata.fdb COMMAND ${CMAKE_COMMAND} -E remove metadata_.fdb - COMMAND boot_gbak -r ${CMAKE_SOURCE_DIR}/builds/misc/metadata.gbak metadata_.fdb + COMMAND ${BOOT_GBAK_CMD} -r ${CMAKE_SOURCE_DIR}/builds/misc/metadata.gbak metadata_.fdb COMMAND ${CMAKE_COMMAND} -E copy_if_different metadata_.fdb metadata.fdb ) add_custom_command( @@ -144,7 +144,7 @@ add_custom_command( # COMMAND ${CMAKE_COMMAND} -E remove help.fdb COMMAND ${CMAKE_COMMAND} -E remove help_.fdb - COMMAND boot_gbak -r ${CMAKE_SOURCE_DIR}/builds/misc/help.gbak help_.fdb + COMMAND ${BOOT_GBAK_CMD} -r ${CMAKE_SOURCE_DIR}/builds/misc/help.gbak help_.fdb COMMAND ${CMAKE_COMMAND} -E copy_if_different help_.fdb help.fdb ) add_custom_target(databases @@ -171,8 +171,8 @@ add_custom_command( msg_fdb # COMMAND ${CMAKE_COMMAND} -E remove firebird.msg - COMMAND build_msg -D msg.fdb -P ${CMAKE_CURRENT_BINARY_DIR}/ -F firebird.msg -L all - COMMAND build_msg -D msg.fdb -P ${CMAKE_CURRENT_BINARY_DIR}/ -F firebird.msg + COMMAND ${BUILD_MSG_CMD} -D msg.fdb -P ${CMAKE_CURRENT_BINARY_DIR}/ -F firebird.msg -L all + COMMAND ${BUILD_MSG_CMD} -D msg.fdb -P ${CMAKE_CURRENT_BINARY_DIR}/ -F firebird.msg COMMAND ${CMAKE_COMMAND} -E copy_if_different firebird.msg ${output_dir}/firebird.msg ) add_custom_command( @@ -184,7 +184,7 @@ add_custom_command( # COMMAND ${CMAKE_COMMAND} -E echo "" > codes_headers.dummy COMMAND ${CMAKE_COMMAND} -E echo Building codes header... - COMMAND codes ${CMAKE_CURRENT_SOURCE_DIR}/include/gen ${CMAKE_SOURCE_DIR}/lang_helpers + COMMAND ${CODES_CMD} ${CMAKE_CURRENT_SOURCE_DIR}/include/gen ${CMAKE_SOURCE_DIR}/lang_helpers ) add_custom_target(messages ALL DEPENDS firebird.msg codes_headers.dummy) project_group(messages "Boot/Custom build steps") @@ -194,7 +194,7 @@ project_group(messages "Boot/Custom build steps") # BUILD STEP msg_fdb ######################################## -set(isql_exec_msg boot_isql -q msg_.fdb -i ${CMAKE_CURRENT_SOURCE_DIR}/msgs) +set(isql_exec_msg ${BOOT_ISQL_CMD} -q msg_.fdb -i ${CMAKE_CURRENT_SOURCE_DIR}/msgs) add_custom_command( OUTPUT msg.fdb @@ -206,8 +206,8 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E remove msg.fdb COMMAND ${CMAKE_COMMAND} -E remove msg_.fdb COMMAND ${CMAKE_COMMAND} -E echo "create database 'msg_.fdb';" > create_db_msg.sql - COMMAND boot_isql -q -i create_db_msg.sql - COMMAND boot_gfix -write async msg_.fdb + COMMAND ${BOOT_ISQL_CMD} -q -i create_db_msg.sql + COMMAND ${BOOT_GFIX_CMD} -write async msg_.fdb COMMAND ${isql_exec_msg}/msg.sql # COMMAND echo loading facilities