[compiler-rt] r310945 - [CMake compiler-rt] NFC: Minor CMake refactoring.

George Karpenkov via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 15 11:38:15 PDT 2017


Author: george.karpenkov
Date: Tue Aug 15 11:38:14 2017
New Revision: 310945

URL: http://llvm.org/viewvc/llvm-project?rev=310945&view=rev
Log:
[CMake compiler-rt] NFC: Minor CMake refactoring.

Detect ObjC files in `clang_compile` and pass an appropriate flag to a
compiler, also change `clang_compile` to a function.

Differential Revision: https://reviews.llvm.org/D36727

Modified:
    compiler-rt/trunk/cmake/Modules/CompilerRTCompile.cmake
    compiler-rt/trunk/lib/asan/tests/CMakeLists.txt

Modified: compiler-rt/trunk/cmake/Modules/CompilerRTCompile.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/CompilerRTCompile.cmake?rev=310945&r1=310944&r2=310945&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/Modules/CompilerRTCompile.cmake (original)
+++ compiler-rt/trunk/cmake/Modules/CompilerRTCompile.cmake Tue Aug 15 11:38:14 2017
@@ -61,7 +61,7 @@ endfunction()
 # clang_compile(<object> <source>
 #               CFLAGS <list of compile flags>
 #               DEPS <list of dependencies>)
-macro(clang_compile object_file source)
+function(clang_compile object_file source)
   cmake_parse_arguments(SOURCE "" "" "CFLAGS;DEPS" ${ARGN})
   get_filename_component(source_rpath ${source} REALPATH)
   if(NOT COMPILER_RT_STANDALONE_BUILD)
@@ -71,6 +71,7 @@ macro(clang_compile object_file source)
     list(APPEND SOURCE_DEPS CompilerRTUnitTestCheckCxx)
   endif()
   string(REGEX MATCH "[.](cc|cpp)$" is_cxx ${source_rpath})
+  string(REGEX MATCH "[.](m|mm)$" is_objc ${source_rpath})
   if(is_cxx)
     string(REPLACE " " ";" global_flags "${CMAKE_CXX_FLAGS}")
   else()
@@ -84,6 +85,9 @@ macro(clang_compile object_file source)
   if (APPLE)
     set(global_flags ${OSX_SYSROOT_FLAG} ${global_flags})
   endif()
+  if (is_objc)
+    list(APPEND global_flags -ObjC)
+  endif()
 
   # Ignore unknown warnings. CMAKE_CXX_FLAGS may contain GCC-specific options
   # which are not supported by Clang.
@@ -96,7 +100,7 @@ macro(clang_compile object_file source)
             ${source_rpath}
     MAIN_DEPENDENCY ${source}
     DEPENDS ${SOURCE_DEPS})
-endmacro()
+endfunction()
 
 # On Darwin, there are no system-wide C++ headers and the just-built clang is
 # therefore not able to compile C++ files unless they are copied/symlinked into

Modified: compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/CMakeLists.txt?rev=310945&r1=310944&r2=310945&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/tests/CMakeLists.txt Tue Aug 15 11:38:14 2017
@@ -186,7 +186,7 @@ set(ASAN_INST_TEST_SOURCES
   asan_str_test.cc
   asan_test_main.cc)
 if(APPLE)
-  list(APPEND ASAN_INST_TEST_SOURCES asan_mac_test.cc)
+  list(APPEND ASAN_INST_TEST_SOURCES asan_mac_test.cc asan_mac_test_helpers.mm)
 endif()
 
 set(ASAN_BENCHMARKS_SOURCES
@@ -201,11 +201,6 @@ macro(add_asan_tests_for_arch_and_kind a
     asan_compile(ASAN_INST_TEST_OBJECTS ${src} ${arch} ${kind}
                  CFLAGS ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} ${cflags})
   endforeach()
-  if (APPLE)
-    # Add Mac-specific helper.
-    asan_compile(ASAN_INST_TEST_OBJECTS asan_mac_test_helpers.mm ${arch} ${kind}
-                 CFLAGS ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} -ObjC ${cflags})
-  endif()
 
   if (MSVC)
     # With the MSVC CRT, the choice between static and dynamic CRT is made at




More information about the llvm-commits mailing list