diff options
author | dundargoc <gocdundar@gmail.com> | 2024-04-06 15:40:23 +0200 |
---|---|---|
committer | dundargoc <33953936+dundargoc@users.noreply.github.com> | 2024-04-08 10:52:53 +0200 |
commit | 624de849de39c7fb4f8e18a68e8c5f13ec4b1316 (patch) | |
tree | 1f9e6afaeffcf9beac8421065ba7a2fd1d20a477 /cmake | |
parent | be2a4b52b9853a9075a1bc69768625428aa7ffb3 (diff) | |
download | rneovim-624de849de39c7fb4f8e18a68e8c5f13ec4b1316.tar.gz rneovim-624de849de39c7fb4f8e18a68e8c5f13ec4b1316.tar.bz2 rneovim-624de849de39c7fb4f8e18a68e8c5f13ec4b1316.zip |
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.
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/Util.cmake | 27 |
1 files changed, 27 insertions, 0 deletions
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. # |