Make Vala builds efficient with Ninja
This commit is contained in:
		@@ -40,18 +40,25 @@ macro (_vala_parse_source_path)
 | 
			
		||||
	set (output_c    "${directory}/${without_extension}.c")
 | 
			
		||||
endmacro ()
 | 
			
		||||
 | 
			
		||||
# XXX: it would be best to have it working without touching the vapi (which
 | 
			
		||||
#   forces rebuilds even if the API doesn't change) but it appears this cannot
 | 
			
		||||
#   be done in CMake (at least with make, with ninja it seems to be possible
 | 
			
		||||
#   via stamps and BYPRODUCTS)
 | 
			
		||||
# TODO: check ${CMAKE_GENERATOR} and try to do better -> OUTPUT and "touch"
 | 
			
		||||
#   a stamp, use BYPRODUCTS instead, ... maybe make a target for all stamps,
 | 
			
		||||
#   then DEPEND on that target when precompiling.  This should be enough.
 | 
			
		||||
function (_vala_make_fast file)
 | 
			
		||||
	_vala_parse_source_path ()
 | 
			
		||||
	add_custom_command (OUTPUT "${output_vapi}"
 | 
			
		||||
 | 
			
		||||
	# See `cmake --help-policy CMP0058` for a rather nice explanation.
 | 
			
		||||
	# TODO: it says we can fix this situation even for non-Ninja
 | 
			
		||||
	#   (rebuilds are forced even when the external API doesn't change),
 | 
			
		||||
	#   just make sure to only use BYPRODUCTS when it's supported by CMake
 | 
			
		||||
	set (stamp "${output_vapi}")
 | 
			
		||||
	set (byproducts)
 | 
			
		||||
	if ("${CMAKE_GENERATOR}" STREQUAL Ninja)
 | 
			
		||||
		set (stamp "${output_vapi}.stamp")
 | 
			
		||||
		set (byproducts BYPRODUCTS "${output_vapi}")
 | 
			
		||||
		set (stamp_target ${stamp_target} "${stamp}" PARENT_SCOPE)
 | 
			
		||||
	endif ()
 | 
			
		||||
 | 
			
		||||
	add_custom_command (OUTPUT "${stamp}"
 | 
			
		||||
		${byproducts}
 | 
			
		||||
		COMMAND ${VALA_COMPILER} "${file}" "--fast-vapi=${output_vapi}"
 | 
			
		||||
		COMMAND ${CMAKE_COMMAND} -E touch "${output_vapi}"
 | 
			
		||||
		COMMAND ${CMAKE_COMMAND} -E touch "${stamp}"
 | 
			
		||||
		DEPENDS "${file}"
 | 
			
		||||
		COMMENT "Generating a fast vapi for ${basename}" VERBATIM)
 | 
			
		||||
	set (fast_vapi_deps ${fast_vapi_deps} "${output_vapi}" PARENT_SCOPE)
 | 
			
		||||
@@ -69,13 +76,18 @@ function (_vala_make_c file)
 | 
			
		||||
	add_custom_command (OUTPUT "${output_c}"
 | 
			
		||||
		COMMAND ${VALA_COMPILER} "${file}" -C ${compiler_args} ${fast_vapis}
 | 
			
		||||
		COMMAND ${CMAKE_COMMAND} -E touch "${output_c}"
 | 
			
		||||
		DEPENDS "${file}" ${fast_vapi_deps} ${vapis}
 | 
			
		||||
		DEPENDS "${file}" ${fast_vapi_deps} ${vapis} ${stamp_target}
 | 
			
		||||
		WORKING_DIRECTORY "${directory}"
 | 
			
		||||
		COMMENT "Precompiling ${basename}" VERBATIM)
 | 
			
		||||
	set (c_outputs ${c_outputs} "${output_c}" PARENT_SCOPE)
 | 
			
		||||
endfunction ()
 | 
			
		||||
 | 
			
		||||
set (_vala_counter 0)
 | 
			
		||||
function (vala_precompile)
 | 
			
		||||
	# So that the user doesn't need to name any targets, we can do it ourselves
 | 
			
		||||
	math (EXPR counter "${_vala_counter} + 1")
 | 
			
		||||
	set (_vala_counter "${counter}" PARENT_SCOPE)
 | 
			
		||||
 | 
			
		||||
	set (_single_value DIRECTORY OUTPUTS HEADER VAPI SYMBOLS)
 | 
			
		||||
	set (_multi_value PACKAGES OPTIONS)
 | 
			
		||||
	cmake_parse_arguments (arg "" "${_single_value}" "${_multi_value}" ${ARGN})
 | 
			
		||||
@@ -105,9 +117,14 @@ function (vala_precompile)
 | 
			
		||||
 | 
			
		||||
	set (fast_vapi_deps)
 | 
			
		||||
	set (fast_vapi_args)
 | 
			
		||||
	set (stamp_target)
 | 
			
		||||
	foreach (_source ${sources})
 | 
			
		||||
		_vala_make_fast ("${_source}")
 | 
			
		||||
	endforeach ()
 | 
			
		||||
	if (stamp_target)
 | 
			
		||||
		add_custom_target ("vala_fast_vapis_${counter}" DEPENDS ${stamp_target})
 | 
			
		||||
		set (stamp_target "vala_fast_vapis_${counter}")
 | 
			
		||||
	endif ()
 | 
			
		||||
 | 
			
		||||
	set (compiler_args)
 | 
			
		||||
	foreach (_pkg ${arg_PACKAGES})
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user