ADDITIONAL_CLEAN_FILES does not work on custom targets
Hi there,
I have created a simple CMakeLists.txt
to illustrate that CMake 3.15 does not handle the newly introduced ADDITIONAL_CLEAN_FILES
property on target level in a correct way:
CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
option(ENABLE_DIRECTORY_CLEAN
"Enable ADDITIONAL_CLEAN_FILES on directory level"
OFF
)
project(ExampleCleanFiles LANGUAGES C)
add_library(main)
target_sources(main PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/main.c")
set_target_properties(main
PROPERTIES
ADDITIONAL_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/main.txt"
)
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/main.c"
CONTENT
"int main(void) {\n return 0;\n}\n"
)
add_custom_target(dummy
ALL
COMMAND
${CMAKE_COMMAND} -E echo . > "${CMAKE_CURRENT_BINARY_DIR}/dummy.txt"
COMMAND
${CMAKE_COMMAND} -E echo . > "${CMAKE_CURRENT_BINARY_DIR}/main.txt"
)
if(NOT ENABLE_DIRECTORY_CLEAN)
set_target_properties(dummy
PROPERTIES
ADDITIONAL_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/dummy.txt"
)
else()
set_directory_properties(
PROPERTIES
ADDITIONAL_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/dummy.txt"
)
endif()
The example above works fine if ENABLE_DIRECTORY_CLEAN
is set to ON
. However, the example does not remove the file dummy.txt
if the option is set to OFF
.
The functionality seems to work for targets that are created via add_library
, but it does not seem to be implemented properly for the main usage in custom targets.
The example script has been tested with CMake 3.15.0.
Best regards, Markus