[compiler-rt] r215247 - [CMake] Determine which compiler-rt libraries are supported on

Alexey Samsonov vonosmas at gmail.com
Fri Aug 8 15:01:20 PDT 2014


Author: samsonov
Date: Fri Aug  8 17:01:20 2014
New Revision: 215247

URL: http://llvm.org/viewvc/llvm-project?rev=215247&view=rev
Log:
[CMake] Determine which compiler-rt libraries are supported on
a given platform in a top-level CMakeLists.txt to use it both
in lib/ and in test/ subdirectories. Move architecture/platform
checks to config-ix.

Modified:
    compiler-rt/trunk/CMakeLists.txt
    compiler-rt/trunk/cmake/config-ix.cmake
    compiler-rt/trunk/lib/CMakeLists.txt
    compiler-rt/trunk/test/CMakeLists.txt
    compiler-rt/trunk/test/ubsan/CMakeLists.txt

Modified: compiler-rt/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/CMakeLists.txt?rev=215247&r1=215246&r2=215247&view=diff
==============================================================================
--- compiler-rt/trunk/CMakeLists.txt (original)
+++ compiler-rt/trunk/CMakeLists.txt Fri Aug  8 17:01:20 2014
@@ -179,9 +179,6 @@ else()
   set(TARGET_32_BIT_CFLAGS "")
 endif()
 
-# List of architectures we can target.
-set(COMPILER_RT_SUPPORTED_ARCH)
-
 function(get_target_flags_for_arch arch out_var)
   list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX)
   if(ARCH_INDEX EQUAL -1)
@@ -191,52 +188,6 @@ function(get_target_flags_for_arch arch
   endif()
 endfunction()
 
-# Try to compile a very simple source file to ensure we can target the given
-# platform. We use the results of these tests to build only the various target
-# runtime libraries supported by our current compilers cross-compiling
-# abilities.
-set(SIMPLE_SOURCE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple.cc)
-file(WRITE ${SIMPLE_SOURCE} "#include <stdlib.h>\n#include <limits>\nint main() {}\n")
-
-# test_target_arch(<arch> <target flags...>)
-# Sets the target flags for a given architecture and determines if this
-# architecture is supported by trying to build a simple file.
-macro(test_target_arch arch)
-  set(TARGET_${arch}_CFLAGS ${ARGN})
-  try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE}
-              COMPILE_DEFINITIONS "${TARGET_${arch}_CFLAGS}"
-              OUTPUT_VARIABLE TARGET_${arch}_OUTPUT
-              CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${TARGET_${arch}_CFLAGS}")
-  if(${CAN_TARGET_${arch}})
-    list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
-  elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "${arch}" OR
-         "${arch}" STREQUAL "arm_android")
-    # Bail out if we cannot target the architecture we plan to test.
-    message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}")
-  endif()
-endmacro()
-
-if(ANDROID)
-  test_target_arch(arm_android "")
-else()
-  if("${LLVM_NATIVE_ARCH}" STREQUAL "X86")
-    if (NOT MSVC)
-      test_target_arch(x86_64 ${TARGET_64_BIT_CFLAGS})
-    endif()
-    test_target_arch(i386 ${TARGET_32_BIT_CFLAGS})
-  elseif("${LLVM_NATIVE_ARCH}" STREQUAL "PowerPC")
-    test_target_arch(powerpc64 ${TARGET_64_BIT_CFLAGS})
-  elseif("${LLVM_NATIVE_ARCH}" STREQUAL "Mips")
-    test_target_arch(mips "")
-  endif()
-
-  # Build ARM libraries if we are configured to test on ARM
-  if("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "arm|aarch64")
-    test_target_arch(arm "-march=armv7-a")
-    test_target_arch(aarch64 "-march=armv8-a")
-  endif()
-endif()
-
 # We support running instrumented tests when we're not cross compiling
 # and target a UNIX-like system or Windows.
 # We can run tests on Android even when we are cross-compiling.
@@ -251,17 +202,6 @@ endif()
 find_flag_in_string("${CMAKE_CXX_FLAGS}" "-stdlib=libc++"
                     COMPILER_RT_USES_LIBCXX)
 
-function(filter_available_targets out_var)
-  set(archs)
-  foreach(arch ${ARGN})
-    list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX)
-    if(NOT (ARCH_INDEX EQUAL -1) AND CAN_TARGET_${arch})
-      list(APPEND archs ${arch})
-    endif()
-  endforeach()
-  set(${out_var} ${archs} PARENT_SCOPE)
-endfunction()
-
 option(COMPILER_RT_DEBUG "Build runtimes with full debug info" OFF)
 # COMPILER_RT_DEBUG_PYBOOL is used by lit.common.configured.in.
 pythonize_bool(COMPILER_RT_DEBUG)
@@ -361,18 +301,6 @@ if(APPLE)
     -isysroot ${IOSSIM_SDK_DIR})
 endif()
 
-# Architectures supported by Sanitizer runtimes. Specific sanitizers may
-# support only subset of these (e.g. TSan works on x86_64 only).
-filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH
-  x86_64 i386 powerpc64 arm aarch64 mips)
-filter_available_targets(ASAN_SUPPORTED_ARCH x86_64 i386 powerpc64 arm mips)
-filter_available_targets(DFSAN_SUPPORTED_ARCH x86_64)
-filter_available_targets(LSAN_SUPPORTED_ARCH x86_64)
-filter_available_targets(MSAN_SUPPORTED_ARCH x86_64)
-filter_available_targets(PROFILE_SUPPORTED_ARCH x86_64 i386 arm aarch64)
-filter_available_targets(TSAN_SUPPORTED_ARCH x86_64)
-filter_available_targets(UBSAN_SUPPORTED_ARCH x86_64 i386 arm aarch64)
-
 add_subdirectory(include)
 
 set(COMPILER_RT_LIBCXX_PATH ${LLVM_MAIN_SRC_DIR}/projects/libcxx)

Modified: compiler-rt/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/config-ix.cmake?rev=215247&r1=215246&r2=215247&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/config-ix.cmake (original)
+++ compiler-rt/trunk/cmake/config-ix.cmake Fri Aug  8 17:01:20 2014
@@ -48,3 +48,144 @@ check_symbol_exists(__func__ "" COMPILER
 check_library_exists(m pow "" COMPILER_RT_HAS_LIBM)
 check_library_exists(dl dlopen "" COMPILER_RT_HAS_LIBDL)
 check_library_exists(pthread pthread_create "" COMPILER_RT_HAS_LIBPTHREAD)
+
+# Architectures.
+
+# List of all architectures we can target.
+set(COMPILER_RT_SUPPORTED_ARCH)
+
+# Try to compile a very simple source file to ensure we can target the given
+# platform. We use the results of these tests to build only the various target
+# runtime libraries supported by our current compilers cross-compiling
+# abilities.
+set(SIMPLE_SOURCE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple.cc)
+file(WRITE ${SIMPLE_SOURCE} "#include <stdlib.h>\n#include <limits>\nint main() {}\n")
+
+# test_target_arch(<arch> <target flags...>)
+# Sets the target flags for a given architecture and determines if this
+# architecture is supported by trying to build a simple file.
+macro(test_target_arch arch)
+  set(TARGET_${arch}_CFLAGS ${ARGN})
+  try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE}
+              COMPILE_DEFINITIONS "${TARGET_${arch}_CFLAGS}"
+              OUTPUT_VARIABLE TARGET_${arch}_OUTPUT
+              CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${TARGET_${arch}_CFLAGS}")
+  if(${CAN_TARGET_${arch}})
+    list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
+  elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "${arch}" OR
+         "${arch}" STREQUAL "arm_android")
+    # Bail out if we cannot target the architecture we plan to test.
+    message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}")
+  endif()
+endmacro()
+
+# Generate the COMPILER_RT_SUPPORTED_ARCH list.
+if(ANDROID)
+  test_target_arch(arm_android "")
+else()
+  if("${LLVM_NATIVE_ARCH}" STREQUAL "X86")
+    if (NOT MSVC)
+      test_target_arch(x86_64 ${TARGET_64_BIT_CFLAGS})
+    endif()
+    test_target_arch(i386 ${TARGET_32_BIT_CFLAGS})
+  elseif("${LLVM_NATIVE_ARCH}" STREQUAL "PowerPC")
+    test_target_arch(powerpc64 ${TARGET_64_BIT_CFLAGS})
+  elseif("${LLVM_NATIVE_ARCH}" STREQUAL "Mips")
+    test_target_arch(mips "")
+  endif()
+  # Build ARM libraries if we are configured to test on ARM
+  if("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "arm|aarch64")
+    test_target_arch(arm "-march=armv7-a")
+    test_target_arch(aarch64 "-march=armv8-a")
+  endif()
+endif()
+
+# Takes ${ARGN} and puts only supported architectures in @out_var list.
+function(filter_available_targets out_var)
+  set(archs)
+  foreach(arch ${ARGN})
+    list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX)
+    if(NOT (ARCH_INDEX EQUAL -1) AND CAN_TARGET_${arch})
+      list(APPEND archs ${arch})
+    endif()
+  endforeach()
+  set(${out_var} ${archs} PARENT_SCOPE)
+endfunction()
+
+# Arhcitectures supported by compiler-rt libraries.
+# FIXME: add arm_android here
+filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH
+  x86_64 i386 powerpc64 arm aarch64 mips arm_android)
+filter_available_targets(ASAN_SUPPORTED_ARCH
+  x86_64 i386 powerpc64 arm mips arm_android)
+filter_available_targets(DFSAN_SUPPORTED_ARCH x86_64)
+filter_available_targets(LSAN_SUPPORTED_ARCH x86_64)
+filter_available_targets(MSAN_SUPPORTED_ARCH x86_64)
+filter_available_targets(PROFILE_SUPPORTED_ARCH x86_64 i386 arm aarch64)
+filter_available_targets(TSAN_SUPPORTED_ARCH x86_64)
+filter_available_targets(UBSAN_SUPPORTED_ARCH x86_64 i386 arm aarch64)
+
+if(ANDROID)
+  set(OS_NAME "Android")
+else()
+  set(OS_NAME "${CMAKE_SYSTEM_NAME}")
+endif()
+
+if (SANITIZER_COMMON_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
+    (OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD" OR
+    (OS_NAME MATCHES "Windows" AND MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 4)))
+  set(COMPILER_RT_HAS_SANITIZER_COMMON TRUE)
+else()
+  set(COMPILER_RT_HAS_SANITIZER_COMMON FALSE)
+endif()
+
+if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH)
+  set(COMPILER_RT_HAS_ASAN TRUE)
+else()
+  set(COMPILER_RT_HAS_ASAN FALSE)
+endif()
+
+# TODO: Add builtins support.
+
+if (COMPILER_RT_HAS_SANITIZER_COMMON AND DFSAN_SUPPORTED_ARCH AND
+    OS_NAME MATCHES "Linux")
+  set(COMPILER_RT_HAS_DFSAN TRUE)
+else()
+  set(COMPILER_RT_HAS_DFSAN FALSE)
+endif()
+
+if (COMPILER_RT_HAS_SANITIZER_COMMON AND LSAN_SUPPORTED_ARCH AND
+    OS_NAME MATCHES "Darwin|Linux|FreeBSD")
+  set(COMPILER_RT_HAS_LSAN TRUE)
+else()
+  set(COMPILER_RT_HAS_LSAN FALSE)
+endif()
+
+if (COMPILER_RT_HAS_SANITIZER_COMMON AND MSAN_SUPPORTED_ARCH AND
+    OS_NAME MATCHES "Linux")
+  set(COMPILER_RT_HAS_MSAN TRUE)
+else()
+  set(COMPILER_RT_HAS_MSAN FALSE)
+endif()
+
+if (PROFILE_SUPPORTED_ARCH AND
+    OS_NAME MATCHES "Darwin|Linux|FreeBSD")
+  set(COMPILER_RT_HAS_PROFILE TRUE)
+else()
+  set(COMPILER_RT_HAS_PROFILE FALSE)
+endif()
+
+if (COMPILER_RT_HAS_SANITIZER_COMMON AND TSAN_SUPPORTED_ARCH AND
+    OS_NAME MATCHES "Linux")
+  set(COMPILER_RT_HAS_TSAN TRUE)
+else()
+  set(COMPILER_RT_HAS_TSAN FALSE)
+endif()
+
+if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND
+    OS_NAME MATCHES "Darwin|Linux|FreeBSD")
+  set(COMPILER_RT_HAS_UBSAN TRUE)
+else()
+  set(COMPILER_RT_HAS_UBSAN FALSE)
+endif()
+

Modified: compiler-rt/trunk/lib/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/CMakeLists.txt?rev=215247&r1=215246&r2=215247&view=diff
==============================================================================
--- compiler-rt/trunk/lib/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/CMakeLists.txt Fri Aug  8 17:01:20 2014
@@ -3,37 +3,41 @@
 
 include(AddCompilerRT)
 include(SanitizerUtils)
-# Don't build sanitizers in the bootstrap build.
-if(NOT LLVM_USE_SANITIZER)
-  # AddressSanitizer is supported on Linux, FreeBSD and Mac OS X.
-  # 32-bit Windows support is experimental.
-  if(CMAKE_SYSTEM_NAME MATCHES "Darwin|Linux|FreeBSD")
-    set(SUPPORTS_BUILDING_ASAN TRUE)
-  elseif(CMAKE_SYSTEM_NAME MATCHES "Windows"
-         AND MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 4)
-    set(SUPPORTS_BUILDING_ASAN TRUE)
-  else()
-    set(SUPPORTS_BUILDING_ASAN FALSE)
-  endif()
-  if(SUPPORTS_BUILDING_ASAN)
-    add_subdirectory(asan)
-    add_subdirectory(interception)
-    add_subdirectory(sanitizer_common)
-  endif()
-  if(CMAKE_SYSTEM_NAME MATCHES "Darwin|Linux|FreeBSD" AND NOT ANDROID)
-    # LSan, UBsan and profile can be built on Mac OS, FreeBSD and Linux.
-    add_subdirectory(lsan)
-    add_subdirectory(profile)
-    add_subdirectory(ubsan)
-  endif()
-  if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT ANDROID)
-    # ThreadSanitizer and MemorySanitizer are supported on Linux only.
-    add_subdirectory(tsan)
-    add_subdirectory(tsan/dd)
-    add_subdirectory(msan)
-    add_subdirectory(msandr)
-    add_subdirectory(dfsan)
-  endif()
+
+if(COMPILER_RT_HAS_SANITIZER_COMMON)
+  add_subdirectory(interception)
+  add_subdirectory(sanitizer_common)
+endif()
+
+if(COMPILER_RT_HAS_ASAN)
+  add_subdirectory(asan)
 endif()
 
 add_subdirectory(builtins)
+
+if(COMPILER_RT_HAS_DFSAN)
+  add_subdirectory(dfsan)
+endif()
+
+if(COMPILER_RT_HAS_LSAN)
+  add_subdirectory(lsan)
+endif()
+
+if(COMPILER_RT_HAS_MSAN)
+  add_subdirectory(msan)
+  add_subdirectory(msandr)
+endif()
+
+if(COMPILER_RT_HAS_PROFILE)
+  add_subdirectory(profile)
+endif()
+
+if(COMPILER_RT_HAS_TSAN)
+  add_subdirectory(tsan)
+  add_subdirectory(tsan/dd)
+endif()
+
+if(COMPILER_RT_HAS_UBSAN)
+  add_subdirectory(ubsan)
+endif()
+

Modified: compiler-rt/trunk/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/CMakeLists.txt?rev=215247&r1=215246&r2=215247&view=diff
==============================================================================
--- compiler-rt/trunk/test/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/CMakeLists.txt Fri Aug  8 17:01:20 2014
@@ -24,28 +24,28 @@ endif()
 # Run sanitizer tests only if we're sure that clang would produce
 # working binaries.
 if(COMPILER_RT_CAN_EXECUTE_TESTS)
-  if(ASAN_SUPPORTED_ARCH OR ANDROID)
+  if(COMPILER_RT_HAS_ASAN)
     add_subdirectory(asan)
   endif()
-  if(DFSAN_SUPPORTED_ARCH)
+  if(COMPILER_RT_HAS_DFSAN)
     add_subdirectory(dfsan)
   endif()
-  if(LSAN_SUPPORTED_ARCH)
+  if(COMPILER_RT_HAS_LSAN)
     add_subdirectory(lsan)
   endif()
-  if(MSAN_SUPPORTED_ARCH)
+  if(COMPILER_RT_HAS_MSAN)
     add_subdirectory(msan)
   endif()
-  if(PROFILE_SUPPORTED_ARCH)
+  if(COMPILER_RT_HAS_PROFILE)
     add_subdirectory(profile)
   endif()
-  if(SANITIZER_COMMON_SUPPORTED_ARCH)
+  if(COMPILER_RT_HAS_SANITIZER_COMMON)
     add_subdirectory(sanitizer_common)
   endif()
-  if(TSAN_SUPPORTED_ARCH)
+  if(COMPILER_RT_HAS_TSAN)
     add_subdirectory(tsan)
   endif()
-  if(UBSAN_SUPPORTED_ARCH)
+  if(COMPILER_RT_HAS_UBSAN)
     add_subdirectory(ubsan)
   endif()
 endif()

Modified: compiler-rt/trunk/test/ubsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/CMakeLists.txt?rev=215247&r1=215246&r2=215247&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/ubsan/CMakeLists.txt Fri Aug  8 17:01:20 2014
@@ -6,7 +6,7 @@ configure_lit_site_cfg(
   ${CMAKE_CURRENT_BINARY_DIR}/UbsanConfig/lit.site.cfg)
 set(UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/UbsanConfig)
 
-if(ASAN_SUPPORTED_ARCH)
+if(COMPILER_RT_HAS_ASAN)
   set(UBSAN_LIT_TEST_MODE "AddressSanitizer")
   configure_lit_site_cfg(
     ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in





More information about the llvm-commits mailing list