Make Vala builds efficient under make, too

And some further finishing touches.
This commit is contained in:
Přemysl Eric Janouch 2016-10-18 16:31:45 +02:00
parent 6636df643e
commit 377fe478e2
Signed by: p
GPG Key ID: B715679E3A361BE6
1 changed files with 21 additions and 24 deletions

View File

@ -1,7 +1,7 @@
# - Precompilation of Vala/Genie source files into C sources # - Precompilation of Vala/Genie source files into C sources
# Makes use of the parallel build ability introduced in Vala 0.11. # Makes use of the parallel build ability introduced in Vala 0.11.
# Might be a bit oversimplified and inefficient but at least it's short.
# Filenames must be unique within a single compilation unit and that's fine. # Filenames must be unique within a single compilation unit and that's fine.
# Props to other Vala module writers, I had to reengineer it to understand it.
# #
# vala_precompile (source... - .vala, .gs, .vapi # vala_precompile (source... - .vala, .gs, .vapi
# [DIRECTORY dir] - Output directory (binary dir by default) # [DIRECTORY dir] - Output directory (binary dir by default)
@ -30,6 +30,7 @@
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#============================================================================= #=============================================================================
cmake_minimum_required (VERSION 2.8.0)
find_package (Vala 0.11 REQUIRED) find_package (Vala 0.11 REQUIRED)
include (CMakeParseArguments) include (CMakeParseArguments)
@ -43,22 +44,19 @@ endmacro ()
function (_vala_make_fast file) function (_vala_make_fast file)
_vala_parse_source_path () _vala_parse_source_path ()
# See `cmake --help-policy CMP0058` for a rather nice explanation. # See `cmake --help-policy CMP0058` for a rather nice explanation
# TODO: it says we can fix this situation even for non-Ninja set (_stamp "${output_vapi}")
# (rebuilds are forced even when the external API doesn't change), set (_byproducts)
# just make sure to only use BYPRODUCTS when it's supported by CMake if (NOT "${CMAKE_VERSION}" VERSION_LESS "3.0.2")
set (stamp "${output_vapi}") set (_stamp "${output_vapi}.stamp")
set (byproducts) set (_byproducts BYPRODUCTS "${output_vapi}")
if ("${CMAKE_GENERATOR}" STREQUAL Ninja) set (stamp_target ${stamp_target} "${_stamp}" PARENT_SCOPE)
set (stamp "${output_vapi}.stamp")
set (byproducts BYPRODUCTS "${output_vapi}")
set (stamp_target ${stamp_target} "${stamp}" PARENT_SCOPE)
endif () endif ()
add_custom_command (OUTPUT "${stamp}" add_custom_command (OUTPUT "${_stamp}"
${byproducts} ${_byproducts}
COMMAND ${VALA_COMPILER} "${file}" "--fast-vapi=${output_vapi}" COMMAND ${VALA_COMPILER} "${file}" "--fast-vapi=${output_vapi}"
COMMAND ${CMAKE_COMMAND} -E touch "${stamp}" COMMAND ${CMAKE_COMMAND} -E touch "${_stamp}"
DEPENDS "${file}" DEPENDS "${file}"
COMMENT "Generating a fast vapi for ${basename}" VERBATIM) COMMENT "Generating a fast vapi for ${basename}" VERBATIM)
set (fast_vapi_deps ${fast_vapi_deps} "${output_vapi}" PARENT_SCOPE) set (fast_vapi_deps ${fast_vapi_deps} "${output_vapi}" PARENT_SCOPE)
@ -70,11 +68,11 @@ function (_vala_make_c file)
_vala_parse_source_path () _vala_parse_source_path ()
# We need to filter the current file back out or else it creates conflicts # We need to filter the current file back out or else it creates conflicts
set (fast_vapis ${fast_vapi_args}) set (_fast_vapis ${fast_vapi_args})
list (REMOVE_ITEM fast_vapis "--use-fast-vapi=${output_vapi}") list (REMOVE_ITEM _fast_vapis "--use-fast-vapi=${output_vapi}")
add_custom_command (OUTPUT "${output_c}" add_custom_command (OUTPUT "${output_c}"
COMMAND ${VALA_COMPILER} "${file}" -C ${compiler_args} ${fast_vapis} COMMAND ${VALA_COMPILER} "${file}" -C ${compiler_args} ${_fast_vapis}
COMMAND ${CMAKE_COMMAND} -E touch "${output_c}" COMMAND ${CMAKE_COMMAND} -E touch "${output_c}"
DEPENDS "${file}" ${fast_vapi_deps} ${vapis} ${stamp_target} DEPENDS "${file}" ${fast_vapi_deps} ${vapis} ${stamp_target}
WORKING_DIRECTORY "${directory}" WORKING_DIRECTORY "${directory}"
@ -121,6 +119,8 @@ function (vala_precompile)
foreach (_source ${sources}) foreach (_source ${sources})
_vala_make_fast ("${_source}") _vala_make_fast ("${_source}")
endforeach () endforeach ()
# The target is actually required, or else it may trigger CMP0058
if (stamp_target) if (stamp_target)
add_custom_target ("vala_fast_vapis_${counter}" DEPENDS ${stamp_target}) add_custom_target ("vala_fast_vapis_${counter}" DEPENDS ${stamp_target})
set (stamp_target "vala_fast_vapis_${counter}") set (stamp_target "vala_fast_vapis_${counter}")
@ -143,14 +143,12 @@ function (vala_precompile)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
set (extra_outputs) set (extra_outputs)
set (export_args)
if (arg_VAPI) if (arg_VAPI)
if (NOT IS_ABSOLUTE "${arg_VAPI}") if (NOT IS_ABSOLUTE "${arg_VAPI}")
set (arg_VAPI "${directory}/${arg_VAPI}") set (arg_VAPI "${directory}/${arg_VAPI}")
endif () endif ()
list (APPEND extra_outputs "${arg_VAPI}") list (APPEND extra_outputs "${arg_VAPI}")
list (APPEND export_args "--internal-vapi=${arg_VAPI}") list (APPEND compiler_args "--internal-vapi=${arg_VAPI}")
if (NOT arg_HEADER) if (NOT arg_HEADER)
message (FATAL_ERROR "HEADER generation required for vapi") message (FATAL_ERROR "HEADER generation required for vapi")
endif () endif ()
@ -160,7 +158,7 @@ function (vala_precompile)
set (arg_SYMBOLS "${directory}/${arg_SYMBOLS}") set (arg_SYMBOLS "${directory}/${arg_SYMBOLS}")
endif () endif ()
list (APPEND extra_outputs "${arg_SYMBOLS}") list (APPEND extra_outputs "${arg_SYMBOLS}")
list (APPEND export_args "--symbols=${arg_SYMBOLS}") list (APPEND compiler_args "--symbols=${arg_SYMBOLS}")
if (NOT arg_HEADER) if (NOT arg_HEADER)
message (FATAL_ERROR "HEADER generation required for symbols") message (FATAL_ERROR "HEADER generation required for symbols")
endif () endif ()
@ -177,14 +175,13 @@ function (vala_precompile)
list (APPEND extra_outputs list (APPEND extra_outputs
"${header_base}${header_ext}" "${header_base}${header_ext}"
"${header_base}_internal${header_ext}") "${header_base}_internal${header_ext}")
list (APPEND export_args list (APPEND compiler_args
"--header=${header_base}${header_ext}" "--header=${header_base}${header_ext}"
"--internal-header=${header_base}_internal${header_ext}") "--internal-header=${header_base}_internal${header_ext}")
endif () endif ()
if (extra_outputs) if (extra_outputs)
add_custom_command (OUTPUT ${extra_outputs} add_custom_command (OUTPUT ${extra_outputs}
COMMAND ${VALA_COMPILER} COMMAND ${VALA_COMPILER} -C ${compiler_args} ${fast_vapi_args}
-C ${compiler_args} ${export_args} ${fast_vapi_args}
DEPENDS ${fast_vapi_deps} ${vapis} DEPENDS ${fast_vapi_deps} ${vapis}
COMMENT "Generating vapi/headers/symbols" VERBATIM) COMMENT "Generating vapi/headers/symbols" VERBATIM)
endif () endif ()