From a29e31496fb6b8400aae6193bf4565a366ce717c Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Wed, 21 Oct 2026 18:09:09 +0200 Subject: [PATCH] UseSWIG: Revert "use $ genex" Revert commit 25798c15 (UseSWIG: use $ genex, 2026-06-05). Moving source file properties evaluation from configuration to generation time prevents the possibility to have the same source file, in one directory, in different targets with different settings. Revert to the previous implementation not using $ generator expression. Fixes: #28193 --- Modules/UseSWIG.cmake | 70 ++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 24 deletions(-) diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index 1666f35706..a3618ca15c 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -589,23 +589,40 @@ function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) set (swig_source_file_flags ${CMAKE_SWIG_FLAGS}) # handle various swig compile flags properties - ### include directories - list (APPEND swig_source_file_flags "$>,PREPEND,-I>") - list (APPEND swig_source_file_flags "$>>,PREPEND,-I>") - # use target INCLUDE_DIRECTORIES if source property USE_TARGET_INCLUDE_DIRECTORIES is "ON" or, - # if undefined, if target property SWIG_USE_TARGET_INCLUDE_DIRECTORIES is "ON" - list (APPEND swig_source_file_flags "$>,$,$<$>,0>,$>>:$>>>,PREPEND,-I>") + get_source_file_property (include_directories "${infile}" INCLUDE_DIRECTORIES) + if (include_directories) + list (APPEND swig_source_file_flags "$,PREPEND,-I>") + endif() + set (property "$") + list (APPEND swig_source_file_flags "$,PREPEND,-I>") + set (property "$>") + get_source_file_property(use_target_include_dirs "${infile}" USE_TARGET_INCLUDE_DIRECTORIES) + set (property "$>,PREPEND,-I>") + if (use_target_include_dirs) + list (APPEND swig_source_file_flags "${property}") + elseif(use_target_include_dirs STREQUAL "NOTFOUND") + # not defined at source level, rely on target level + list (APPEND swig_source_file_flags "$<$>:${property}>") + endif() - ### compile definitions - list (APPEND swig_source_file_flags "$>>,PREPEND,-D>") - list (APPEND swig_source_file_flags "$>,PREPEND,-D>") + set (property "$") + list (APPEND swig_source_file_flags "$>,PREPEND,-D>") + get_source_file_property (compile_definitions "${infile}" COMPILE_DEFINITIONS) + if (compile_definitions) + list (APPEND swig_source_file_flags "$,PREPEND,-D>") + endif() - ### compile options list (APPEND swig_source_file_flags "$>") - list (APPEND swig_source_file_flags "$") + get_source_file_property (compile_options "${infile}" COMPILE_OPTIONS) + if (compile_options) + list (APPEND swig_source_file_flags ${compile_options}) + endif() # legacy support - list (APPEND swig_source_file_flags "$") + get_source_file_property (swig_flags "${infile}" SWIG_FLAGS) + if (swig_flags) + list (APPEND swig_source_file_flags ${swig_flags}) + endif() get_filename_component(swig_source_file_fullname "${infile}" ABSOLUTE) @@ -640,11 +657,16 @@ function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) set(swig_special_flags) # default is c, so add c++ flag if it is c++ - list (APPEND swig_special_flags "$<$>:-c++>") + if(swig_source_file_cplusplus) + list (APPEND swig_special_flags "-c++") + endif() cmake_policy(GET CMP0086 module_name_policy) if (module_name_policy STREQUAL "NEW") - list (APPEND swig_special_flags "$<$>:-module$$>") + get_source_file_property(module_name "${infile}" SWIG_MODULE_NAME) + if (module_name) + list (APPEND swig_special_flags "-module" "${module_name}") + endif() else() if (NOT module_name_policy) cmake_policy(ISSUE_WARNING CMP0086) @@ -671,7 +693,10 @@ function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) # dependencies set (swig_dependencies DEPENDS ${SWIG_MODULE_${name}_EXTRA_DEPS} $) - list (APPEND swig_dependencies "$") + get_source_file_property(file_depends "${infile}" DEPENDS) + if (file_depends) + list (APPEND swig_dependencies ${file_depends}) + endif() if (UseSWIG_MODULE_VERSION VERSION_GREATER 1) # as part of custom command, start by removing old generated files @@ -737,17 +762,14 @@ function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) PROPERTIES GENERATED 1) ## add all properties for generated file to various properties - set_property (SOURCE "${swig_generated_file_fullname}" PROPERTY INCLUDE_DIRECTORIES - "$>" - "$>") + get_property (include_directories SOURCE "${infile}" PROPERTY GENERATED_INCLUDE_DIRECTORIES) + set_property (SOURCE "${swig_generated_file_fullname}" PROPERTY INCLUDE_DIRECTORIES ${include_directories} $>) - set_property (SOURCE "${swig_generated_file_fullname}" PROPERTY COMPILE_DEFINITIONS - "$>" - "$>") + get_property (compile_definitions SOURCE "${infile}" PROPERTY GENERATED_COMPILE_DEFINITIONS) + set_property (SOURCE "${swig_generated_file_fullname}" PROPERTY COMPILE_DEFINITIONS $> ${compile_definitions}) - set_property (SOURCE "${swig_generated_file_fullname}" PROPERTY COMPILE_OPTIONS - "$>" - "$>") + get_property (compile_options SOURCE "${infile}" PROPERTY GENERATED_COMPILE_OPTIONS) + set_property (SOURCE "${swig_generated_file_fullname}" PROPERTY COMPILE_OPTIONS $> ${compile_options}) if (SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG MATCHES "php") set_property (SOURCE "${swig_generated_file_fullname}" APPEND PROPERTY INCLUDE_DIRECTORIES "${outdir}")