Source file property setters do not de-duplicate directory options
If a directory ends up being listed more than once after resolving DIRECTORY and TARGET_DIRECTORY options to set_property(SOURCE)
or set_source_files_properties()
and either APPEND
or APPEND_STRING
is used, the property will be appended once for each time the directory appears. The commands should de-duplicate the directories to ensure the value is only appended once. Minimal example that demonstrates the problem:
cmake_minimum_required(VERSION 3.18)
project(proptest)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp "int main() {}")
add_executable(main ${CMAKE_CURRENT_BINARY_DIR}/main.cpp)
set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
DIRECTORY .
TARGET_DIRECTORY main
APPEND
PROPERTY MY_CUSTOM_PROP YES
)
get_source_file_property(result ${CMAKE_CURRENT_BINARY_DIR}/main.cpp MY_CUSTOM_PROP)
message("result = ${result}")
Expected output:
result = YES
Actual output:
result = YES;YES
Note that there will be other variations of the above. One might be using only one of DIRECTORY
or TARGET_DIRECTORY
but the contents given to the option might still resolve with duplicates. It is the final set of directories after combining the resolved directories from both that needs to be de-duplicated. A further complication is whether those directories involve symlinks or other ways that the same path can be resolved with different values. Therefore the paths would need to be canonicalised somehow before de-duplication.