From 624de849de39c7fb4f8e18a68e8c5f13ec4b1316 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 6 Apr 2024 15:40:23 +0200 Subject: build: add function add_target It's a combination of add_custom_target and add_custom_command that does what most users probably expect should happen. This also fixes `make clean` removing files tracked by git. --- cmake/Util.cmake | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'cmake') diff --git a/cmake/Util.cmake b/cmake/Util.cmake index 80f81fd0b4..f09de78668 100644 --- a/cmake/Util.cmake +++ b/cmake/Util.cmake @@ -148,6 +148,33 @@ function(add_glob_target) add_custom_target(${ARG_TARGET} DEPENDS ${touch_list}) endfunction() +# A wrapper function that combines add_custom_command and add_custom_target. It +# essentially models the "make" dependency where a target is only rebuilt if +# any dependencies have been changed. +# +# Important to note is that `DEPENDS` is a bit misleading; it should not only +# specify dependencies but also the files that are being generated/output +# files in order to work correctly. +function(add_target) + cmake_parse_arguments(ARG + "" + "" + "COMMAND;DEPENDS;CUSTOM_COMMAND_ARGS" + ${ARGN} + ) + set(target ${ARGV0}) + + set(touch_file ${TOUCHES_DIR}/${target}) + add_custom_command( + OUTPUT ${touch_file} + COMMAND ${CMAKE_COMMAND} -E touch ${touch_file} + COMMAND ${CMAKE_COMMAND} -E env "VIMRUNTIME=${NVIM_RUNTIME_DIR}" ${ARG_COMMAND} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + DEPENDS ${ARG_DEPENDS} + ${ARG_CUSTOM_COMMAND_ARGS}) + add_custom_target(${target} DEPENDS ${touch_file}) +endfunction() + # Set default build type to BUILD_TYPE. Also limit the list of allowable build # types to the ones defined in variable allowableBuildTypes. # -- cgit