]> granicus.if.org Git - clang/commitdiff
[libclang] Some changes on the linker options for libclang on a CMake build.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 6 Nov 2013 08:37:50 +0000 (08:37 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 6 Nov 2013 08:37:50 +0000 (08:37 +0000)
- Use the 'libclang.exports' file.
- Pass -Wl,-current_version
- Set install name to "@rpath"

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194134 91177308-0d34-0410-b5e6-96231b3b80d8

CMakeLists.txt
tools/libclang/CMakeLists.txt

index 69679538f7458a1e8b663f9ca7d124318b6ba533..8d02bf05f827d5976f1083f0948438887d285074 100644 (file)
@@ -199,6 +199,41 @@ function(clang_tablegen)
   endif()
 endfunction(clang_tablegen)
 
+# FIXME: Generalize and move to llvm.
+function(add_clang_symbol_exports target_name export_file)
+  # Makefile.rules contains special cases for different platforms.
+  # We restrict ourselves to Darwin for the time being.
+  if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+    add_custom_command(OUTPUT symbol.exports
+      COMMAND sed -e "s/^/_/" < ${export_file} > symbol.exports
+      DEPENDS ${export_file}
+      VERBATIM
+      COMMENT "Creating export file for ${target_name}")
+    add_custom_target(${target_name}_exports DEPENDS symbol.exports)
+    set_property(DIRECTORY APPEND
+      PROPERTY ADDITIONAL_MAKE_CLEAN_FILES symbol.exports)
+
+    get_property(srcs TARGET ${target_name} PROPERTY SOURCES)
+    foreach(src ${srcs})
+      get_filename_component(extension ${src} EXT)
+      if(extension STREQUAL ".cpp")
+        set(first_source_file ${src})
+        break()
+      endif()
+    endforeach()
+  
+    # Force re-linking when the exports file changes. Actually, it
+    # forces recompilation of the source file. The LINK_DEPENDS target
+    # property only works for makefile-based generators.
+    set_property(SOURCE ${first_source_file} APPEND PROPERTY
+      OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/symbol.exports)
+  
+    set_property(TARGET ${target_name} APPEND_STRING PROPERTY
+                 LINK_FLAGS " -Wl,-exported_symbols_list,${CMAKE_CURRENT_BINARY_DIR}/symbol.exports")
+    add_dependencies(${target_name} ${target_name}_exports)
+  endif()
+endfunction(add_clang_symbol_exports)
+
 macro(add_clang_library name)
   llvm_process_sources(srcs ${ARGN})
   if(MSVC_IDE OR XCODE)
@@ -238,6 +273,10 @@ macro(add_clang_library name)
   llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
   target_link_libraries( ${name} ${LLVM_COMMON_LIBS} )
   link_system_libs( ${name} )
+  
+  if (SHARED_LIBRARY AND EXPORTED_SYMBOL_FILE)
+    add_clang_symbol_exports( ${name} ${EXPORTED_SYMBOL_FILE} ) 
+  endif()
 
   if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "libclang")
     install(TARGETS ${name}
index 285820fe120f9a91e08d7363858699e6bea59bf5..a593dfccd00d97f250083ad1eecbc28634b2aad8 100644 (file)
@@ -71,6 +71,8 @@ set(GENERATED_HEADERS
   ClangStmtNodes
   )
 
+set(EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libclang.exports)
+
 if( LLVM_ENABLE_PIC )
   set(SHARED_LIBRARY TRUE)
   add_clang_library(libclang ${SOURCES})
@@ -93,11 +95,17 @@ if( LLVM_ENABLE_PIC )
 
   if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
     set(LIBCLANG_LINK_FLAGS
-      "-Wl,-compatibility_version -Wl,1 -Wl,-dead_strip")
+      " -Wl,-compatibility_version -Wl,1 -Wl,-dead_strip")
+    if (DEFINED ${LLVM_SUBMIT_VERSION})
+      set(LIBCLANG_LINK_FLAGS
+        "${LIBCLANG_LINK_FLAGS} -Wl,-current_version -Wl,${LLVM_SUBMIT_VERSION}.${LLVM_SUBMIT_SUBVERSION}")
+    endif()
+
+    set_property(TARGET libclang APPEND_STRING PROPERTY
+                 LINK_FLAGS ${LIBCLANG_LINK_FLAGS})
     set_target_properties(libclang
       PROPERTIES
-      LINK_FLAGS "${LIBCLANG_LINK_FLAGS}"
-      INSTALL_NAME_DIR "@executable_path/../lib")
+      INSTALL_NAME_DIR "@rpath")
   endif()