[compiler-rt] r245317 - [CMake] Refactoring add_compiler_rt functions for darwin runtimes.

Chris Bieneman via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 10:32:18 PDT 2015


Author: cbieneman
Date: Tue Aug 18 12:32:18 2015
New Revision: 245317

URL: http://llvm.org/viewvc/llvm-project?rev=245317&view=rev
Log:
[CMake] Refactoring add_compiler_rt functions for darwin runtimes.

Summary: This patch consolidates add_compiler_rt_osx_static_runtime and add_compiler_rt_darwin_dynamic_runtime into a single new function add_compiler_rt_darwin_runtime.

Reviewers: filcab, samsonov, bogner

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D12106

Modified:
    compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
    compiler-rt/trunk/lib/asan/CMakeLists.txt
    compiler-rt/trunk/lib/profile/CMakeLists.txt
    compiler-rt/trunk/lib/safestack/CMakeLists.txt
    compiler-rt/trunk/lib/ubsan/CMakeLists.txt

Modified: compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake?rev=245317&r1=245316&r2=245317&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake (original)
+++ compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake Tue Aug 18 12:32:18 2015
@@ -86,47 +86,45 @@ macro(add_compiler_rt_runtime name arch
   endif()
 endmacro()
 
-# Same as add_compiler_rt_runtime(... STATIC), but creates a universal library
-# for several architectures.
-# add_compiler_rt_osx_static_runtime(<name> ARCHS <architectures>
-#                                    SOURCES <source files>
-#                                    CFLAGS <compile flags>
-#                                    DEFS <compile definitions>)
-macro(add_compiler_rt_osx_static_runtime name)
-  cmake_parse_arguments(LIB "" "" "ARCHS;SOURCES;CFLAGS;DEFS" ${ARGN})
-  add_library(${name} STATIC ${LIB_SOURCES})
-  set_target_compile_flags(${name} ${LIB_CFLAGS})
-  set_property(TARGET ${name} APPEND PROPERTY
-    COMPILE_DEFINITIONS ${LIB_DEFS})
-  set_target_properties(${name} PROPERTIES
-    OSX_ARCHITECTURES "${LIB_ARCHS}"
-    ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
-  install(TARGETS ${name}
-    ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
-endmacro()
-
-# Adds dynamic runtime library on osx/iossim, which supports multiple
+# Adds runtime library for darwin platforms, which supports multiple
 # architectures.
-# add_compiler_rt_darwin_dynamic_runtime(<name> <os>
-#                                        ARCHS <architectures>
-#                                        SOURCES <source files>
-#                                        CFLAGS <compile flags>
-#                                        DEFS <compile definitions>
-#                                        LINKFLAGS <link flags>)
-macro(add_compiler_rt_darwin_dynamic_runtime name os)
-  cmake_parse_arguments(LIB "" "" "ARCHS;SOURCES;CFLAGS;DEFS;LINKFLAGS" ${ARGN})
-  add_library(${name} SHARED ${LIB_SOURCES})
-  set_target_compile_flags(${name} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS})
-  set_target_link_flags(${name} ${LIB_LINKFLAGS} ${DARWIN_${os}_LINKFLAGS})
-  set_property(TARGET ${name} APPEND PROPERTY
-    COMPILE_DEFINITIONS ${LIB_DEFS})
+# add_compiler_rt_darwin_runtime(<name> <os>
+#                                STATIC|SHARED
+#                                ARCHS <architectures>
+#                                SOURCES <source files>
+#                                CFLAGS <compile flags>
+#                                DEFS <compile definitions>
+#                                LINKFLAGS <link flags>)
+function(add_compiler_rt_darwin_runtime name os)
+  cmake_parse_arguments(LIB "SHARED;STATIC" "" "ARCHS;SOURCES;CFLAGS;DEFS;LINKFLAGS" ${ARGN})
   list_union(filtered_arches DARWIN_${os}_ARCHS LIB_ARCHS)
-  set_target_properties(${name} PROPERTIES
-    OSX_ARCHITECTURES "${filtered_arches}"
-    LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
-  install(TARGETS ${name}
-    LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
-endmacro()
+  # if there are no supported architectures, don't create the library
+  if(filtered_arches)
+    if(LIB_SHARED)
+      add_library(${name} SHARED ${LIB_SOURCES})
+      set_target_properties(${name} PROPERTIES
+        LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
+      install(TARGETS ${name}
+        LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
+    elseif(LIB_STATIC)
+      add_library(${name} STATIC ${LIB_SOURCES})
+      set_target_properties(${name} PROPERTIES
+        ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
+      install(TARGETS ${name}
+        ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
+    else()
+      message(FATAL_ERROR "Must specified SHARED|STATIC to add_compiler_rt_darwin_runtime")
+    endif()
+    
+    set_target_compile_flags(${name} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS})
+    set_target_link_flags(${name} ${LIB_LINKFLAGS} ${DARWIN_${os}_LINKFLAGS})
+    set_property(TARGET ${name} APPEND PROPERTY
+      COMPILE_DEFINITIONS ${LIB_DEFS})
+
+    set_target_properties(${name} PROPERTIES
+      OSX_ARCHITECTURES "${filtered_arches}")
+  endif()
+endfunction()
 
 set(COMPILER_RT_TEST_CFLAGS)
 

Modified: compiler-rt/trunk/lib/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=245317&r1=245316&r2=245317&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/CMakeLists.txt Tue Aug 18 12:32:18 2015
@@ -111,7 +111,8 @@ endif()
 add_custom_target(asan)
 if(APPLE)
   foreach (os ${SANITIZER_COMMON_SUPPORTED_OS})
-    add_compiler_rt_darwin_dynamic_runtime(clang_rt.asan_${os}_dynamic ${os}
+    add_compiler_rt_darwin_runtime(clang_rt.asan_${os}_dynamic ${os}
+      SHARED
       ARCHS ${ASAN_SUPPORTED_ARCH}
       SOURCES $<TARGET_OBJECTS:RTAsan.${os}>
               $<TARGET_OBJECTS:RTInterception.${os}>

Modified: compiler-rt/trunk/lib/profile/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/CMakeLists.txt?rev=245317&r1=245316&r2=245317&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/profile/CMakeLists.txt Tue Aug 18 12:32:18 2015
@@ -11,10 +11,13 @@ set(PROFILE_SOURCES
   InstrProfilingUtil.c)
 
 if(APPLE)
-  add_compiler_rt_osx_static_runtime(clang_rt.profile_osx
-    ARCHS ${PROFILE_SUPPORTED_ARCH}
-    SOURCES ${PROFILE_SOURCES})
-  add_dependencies(profile clang_rt.profile_osx)
+  foreach (os ${SANITIZER_COMMON_SUPPORTED_OS})
+    add_compiler_rt_darwin_runtime(clang_rt.profile_${os} ${os}
+      STATIC
+      ARCHS ${PROFILE_SUPPORTED_ARCH}
+      SOURCES ${PROFILE_SOURCES})
+    add_dependencies(profile clang_rt.profile_${os})
+  endforeach()
 else()
   foreach(arch ${PROFILE_SUPPORTED_ARCH})
     add_compiler_rt_runtime(clang_rt.profile-${arch} ${arch} STATIC

Modified: compiler-rt/trunk/lib/safestack/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/safestack/CMakeLists.txt?rev=245317&r1=245316&r2=245317&view=diff
==============================================================================
--- compiler-rt/trunk/lib/safestack/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/safestack/CMakeLists.txt Tue Aug 18 12:32:18 2015
@@ -8,13 +8,16 @@ set(SAFESTACK_CFLAGS ${SANITIZER_COMMON_
 
 if(APPLE)
   # Build universal binary on APPLE.
-  add_compiler_rt_osx_static_runtime(clang_rt.safestack_osx
-    ARCH ${SAFESTACK_SUPPORTED_ARCH}
-    SOURCES ${SAFESTACK_SOURCES}
-            $<TARGET_OBJECTS:RTInterception.osx>
-            $<TARGET_OBJECTS:RTSanitizerCommon.osx>
-    CFLAGS ${SAFESTACK_CFLAGS})
-  add_dependencies(safestack clang_rt.safestack_osx)
+  foreach (os ${SANITIZER_COMMON_SUPPORTED_OS})
+    add_compiler_rt_darwin_runtime(clang_rt.safestack_${os} ${os}
+      STATIC
+      ARCH ${SAFESTACK_SUPPORTED_ARCH}
+      SOURCES ${SAFESTACK_SOURCES}
+              $<TARGET_OBJECTS:RTInterception.${os}>
+              $<TARGET_OBJECTS:RTSanitizerCommon.${os}>
+      CFLAGS ${SAFESTACK_CFLAGS})
+    add_dependencies(safestack clang_rt.safestack_${os})
+  endforeach()
 else()
   # Otherwise, build separate libraries for each target.
   foreach(arch ${SAFESTACK_SUPPORTED_ARCH})

Modified: compiler-rt/trunk/lib/ubsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/CMakeLists.txt?rev=245317&r1=245316&r2=245317&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/ubsan/CMakeLists.txt Tue Aug 18 12:32:18 2015
@@ -50,7 +50,8 @@ if(APPLE)
       SOURCES ${UBSAN_STANDALONE_SOURCES}
       CFLAGS ${UBSAN_STANDALONE_CFLAGS})
     foreach(os ${SANITIZER_COMMON_SUPPORTED_OS})
-      add_compiler_rt_darwin_dynamic_runtime(clang_rt.ubsan_${os}_dynamic ${os}
+      add_compiler_rt_darwin_runtime(clang_rt.ubsan_${os}_dynamic ${os}
+        SHARED
         ARCHS ${UBSAN_SUPPORTED_ARCH}
         SOURCES $<TARGET_OBJECTS:RTUbsan.${os}>
                 $<TARGET_OBJECTS:RTUbsan_standalone.${os}>




More information about the llvm-commits mailing list