From b0f8890ba5da2afb384b793259b8884eefcb37b8 Mon Sep 17 00:00:00 2001 From: glx22 Date: Mon, 14 Aug 2023 19:26:43 +0200 Subject: [PATCH] Codechange: [CMake] detect source files with duplicate names --- cmake/SourceList.cmake | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmake/SourceList.cmake b/cmake/SourceList.cmake index 7be406050e..f01f5db86b 100644 --- a/cmake/SourceList.cmake +++ b/cmake/SourceList.cmake @@ -9,7 +9,17 @@ function(_add_files_tgt tgt) endif() foreach(FILE IN LISTS PARAM_FILES) - target_sources(openttd_lib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}) + # Some IDEs are not happy with duplicated filenames, so we detect that before adding the file. + get_target_property(${tgt}_FILES ${tgt} SOURCES) + if(${tgt}_FILES MATCHES "/${FILE}(;|$)") + string(REGEX REPLACE "(^|.+;)([^;]+/${FILE})(;.+|$)" "\\2" RES "${${tgt}_FILES}") + # Ignore header files duplicates in 3rdparty. + if(NOT (${FILE} MATCHES "\.h" AND (${RES} MATCHES "3rdparty" OR ${CMAKE_CURRENT_SOURCE_DIR} MATCHES "3rdparty"))) + message(FATAL_ERROR "${tgt}: ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} filename is a duplicate of ${RES}") + endif() + endif() + + target_sources(${tgt} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}) endforeach() endfunction()