Add new add_source_dependencies command
Consider the following hypothetical sample project
cmake_minimum_required(VERSION 3.14.0)
project(app)
# External CMake code provided by some CMake module
function(compile_java target java_in)
set(java_out "${CMAKE_CURRENT_BINARY_DIR}/app.jar")
add_custom_command(NAME my_custom_command # hypothetical argument
OUTPUT "${java_out}"
COMMAND cmake -E touch "${java_out}"
DEPENDS "${java_in}")
add_custom_target(${target} ALL DEPENDS "${java_out}")
endfunction()
# User project code
set(java_in "${CMAKE_CURRENT_SOURCE_DIR}/in.java")
compile_java(my_target "${java_in}")
# Hypothetical new command
add_source_dependencies(COMMAND my_custom_command "${CMAKE_CURRENT_SOURCE_DIR}/some_timestamp_like_non_java_file.txt")
add_source_dependencies(TARGET my_target "${CMAKE_CURRENT_SOURCE_DIR}/some_timestamp_like_non_java_file.txt")
In this project some external CMake module code creates a custom target with custom command that compiles a java file (yes I know UseJava
exists).
Now the user would like to enforce rebuilding that file in case if some additional file changed.
As far as I know it is currently not possible to add additional file dependencies neither on a custom target nor a custom command.
I guess it's more realistic to do it on a custom target because it has a target name, but a custom command doesn't have any name.
Is it feasible to add something like add_source_dependencies
and NAME
to add_custom_command
within the current CMake implementation / design?
Edited by alcroito