Browse Source

Merge topic 'UseSWIG-avoid-dllimport-repeat'

76a0286b UseSWIG: Add `-dllimport` only if not already specified

Acked-by: Kitware Robot <[email protected]>
Merge-request: !958
Brad King 8 years ago
parent
commit
2afc4bf608
1 changed files with 7 additions and 4 deletions
  1. 7 4
      Modules/UseSWIG.cmake

+ 7 - 4
Modules/UseSWIG.cmake

@@ -82,10 +82,6 @@ macro(SWIG_MODULE_INITIALIZE name language)
     set(SWIG_MODULE_${name}_REAL_NAME "_${name}")
   elseif("x${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "xPERL")
     set(SWIG_MODULE_${name}_EXTRA_FLAGS "-shadow")
-  elseif("x${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "xCSHARP")
-    # This makes sure that the name used in the generated DllImport
-    # matches the library name created by CMake
-    set(SWIG_MODULE_${name}_EXTRA_FLAGS "-dllimport;${name}")
   endif()
 endmacro()
 
@@ -192,6 +188,13 @@ macro(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile)
   if(swig_source_file_cplusplus)
     set(swig_special_flags ${swig_special_flags} "-c++")
   endif()
+  if("x${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "xCSHARP")
+    if(NOT ";${swig_source_file_flags};${CMAKE_SWIG_FLAGS};" MATCHES ";-dllimport;")
+      # This makes sure that the name used in the generated DllImport
+      # matches the library name created by CMake
+      set(SWIG_MODULE_${name}_EXTRA_FLAGS "-dllimport;${name}")
+    endif()
+  endif()
   set(swig_extra_flags)
   if(SWIG_MODULE_${name}_EXTRA_FLAGS)
     set(swig_extra_flags ${swig_extra_flags} ${SWIG_MODULE_${name}_EXTRA_FLAGS})