Merge pull request #427 from compnerd/cross-link

enable cross-linking/synchronise with Foundation
diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake
index 537e60c..bda9e6f 100644
--- a/cmake/modules/SwiftSupport.cmake
+++ b/cmake/modules/SwiftSupport.cmake
@@ -8,31 +8,35 @@
 
   cmake_parse_arguments(AST "${options}" "${single_value_options}" "${multiple_value_options}" ${ARGN})
 
-  set(flags ${CMAKE_SWIFT_FLAGS})
+  set(compile_flags ${CMAKE_SWIFT_FLAGS})
   set(link_flags)
 
   if(AST_TARGET)
-    list(APPEND flags -target;${AST_TARGET})
+    list(APPEND compile_flags -target;${AST_TARGET})
+    list(APPEND link_flags -target;${AST_TARGET})
   endif()
   if(AST_MODULE_NAME)
-    list(APPEND flags -module-name;${AST_MODULE_NAME})
+    list(APPEND compile_flags -module-name;${AST_MODULE_NAME})
   else()
-    list(APPEND flags -module-name;${target})
+    list(APPEND compile_flags -module-name;${target})
   endif()
   if(AST_MODULE_LINK_NAME)
-    list(APPEND flags -module-link-name;${AST_MODULE_LINK_NAME})
+    list(APPEND compile_flags -module-link-name;${AST_MODULE_LINK_NAME})
   endif()
   if(AST_MODULE_CACHE_PATH)
-    list(APPEND flags -module-cache-path;${AST_MODULE_CACHE_PATH})
+    list(APPEND compile_flags -module-cache-path;${AST_MODULE_CACHE_PATH})
+  endif()
+  if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
+    list(APPEND compile_flags -g)
   endif()
   if(AST_SWIFT_FLAGS)
     foreach(flag ${AST_SWIFT_FLAGS})
-      list(APPEND flags ${flag})
+      list(APPEND compile_flags ${flag})
     endforeach()
   endif()
   if(AST_CFLAGS)
     foreach(flag ${AST_CFLAGS})
-      list(APPEND flags -Xcc;${flag})
+      list(APPEND compile_flags -Xcc;${flag})
     endforeach()
   endif()
   if(AST_LINK_FLAGS)
@@ -99,7 +103,7 @@
                          ${source}
                          ${AST_DEPENDS}
                        COMMAND
-                         ${CMAKE_SWIFT_COMPILER} -frontend ${flags} -emit-module-path ${mod} -emit-module-doc-path ${doc} -o ${obj} -c ${all_sources})
+                         ${CMAKE_SWIFT_COMPILER} -frontend ${compile_flags} -emit-module-path ${mod} -emit-module-doc-path ${doc} -o ${obj} -c ${all_sources})
 
     list(APPEND objs ${obj})
     list(APPEND mods ${mod})
@@ -122,7 +126,7 @@
                          ${docs}
                          ${AST_DEPENDS}
                        COMMAND
-                         ${CMAKE_SWIFT_COMPILER} -frontend ${flags} -sil-merge-partial-modules -emit-module ${mods} -o ${module} -emit-module-doc-path ${documentation})
+                         ${CMAKE_SWIFT_COMPILER} -frontend ${compile_flags} -sil-merge-partial-modules -emit-module ${mods} -o ${module} -emit-module-doc-path ${documentation})
   endif()
 
   if(AST_LIBRARY)