[PATCH] D12174: [CMake] Fix building unit tests on Darwin

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 20 10:21:19 PDT 2015


Chris Bieneman <beanz at apple.com> writes:
> beanz updated this revision to Diff 32643.
> beanz added a comment.
>
> Fixing patches based on filcab's feedback.

Minor nit, then this LGTM.

>
> http://reviews.llvm.org/D12174
>
> Files:
>   cmake/Modules/CompilerRTDarwinUtils.cmake
>   cmake/config-ix.cmake
>   lib/asan/tests/CMakeLists.txt
>   lib/sanitizer_common/tests/CMakeLists.txt
>   test/asan/CMakeLists.txt
>   test/sanitizer_common/CMakeLists.txt
>
> Index: test/sanitizer_common/CMakeLists.txt
> ===================================================================
> --- test/sanitizer_common/CMakeLists.txt
> +++ test/sanitizer_common/CMakeLists.txt
> @@ -19,14 +19,19 @@
>    if(${tool_toupper}_SUPPORTED_ARCH AND NOT COMPILER_RT_STANDALONE_BUILD)
>      list(APPEND SANITIZER_COMMON_TEST_DEPS ${tool})
>    endif()
> -  foreach(arch ${${tool_toupper}_SUPPORTED_ARCH})
> +  set(TEST_ARCH ${${tool_toupper}_SUPPORTED_ARCH})
> +  if(APPLE)
> +    darwin_filter_host_archs(${tool_toupper}_SUPPORTED_ARCH TEST_ARCH)
> +  endif()
> +
> +  foreach(arch ${TEST_ARCH})
>      set(SANITIZER_COMMON_LIT_TEST_MODE ${tool})
>      set(SANITIZER_COMMON_TEST_TARGET_ARCH ${arch})
>      if(${arch} MATCHES "arm|aarch64")
>        # This is only true if we're cross-compiling.
>        set(SANITIZER_COMMON_TEST_TARGET_CFLAGS
>            ${COMPILER_RT_TEST_COMPILER_CFLAGS})
> -    else()
> +    elseif(NOT APPLE)
>        get_target_flags_for_arch(${arch} SANITIZER_COMMON_TEST_TARGET_CFLAGS)
>        string(REPLACE ";" " " SANITIZER_COMMON_TEST_TARGET_CFLAGS "${SANITIZER_COMMON_TEST_TARGET_CFLAGS}")
>      endif()
> Index: test/asan/CMakeLists.txt
> ===================================================================
> --- test/asan/CMakeLists.txt
> +++ test/asan/CMakeLists.txt
> @@ -24,7 +24,12 @@
>  endif()
>  set(ASAN_DYNAMIC_TEST_DEPS ${ASAN_TEST_DEPS})
>  
> -foreach(arch ${ASAN_SUPPORTED_ARCH})
> +set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH})
> +if(APPLE)
> +  darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
> +endif()
> +
> +foreach(arch ${ASAN_TEST_ARCH})
>    if(ANDROID)
>      set(ASAN_TEST_TARGET_ARCH ${arch}-android)
>    else()
> @@ -37,7 +42,7 @@
>      # Build all tests with host compiler and use host tools.
>      set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
>      set(ASAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS})
> -  else()
> +  elseif(NOT APPLE)
>      get_target_flags_for_arch(${arch} ASAN_TEST_TARGET_CFLAGS)
>      string(REPLACE ";" " " ASAN_TEST_TARGET_CFLAGS "${ASAN_TEST_TARGET_CFLAGS}")
>    endif()
> Index: lib/sanitizer_common/tests/CMakeLists.txt
> ===================================================================
> --- lib/sanitizer_common/tests/CMakeLists.txt
> +++ lib/sanitizer_common/tests/CMakeLists.txt
> @@ -4,6 +4,9 @@
>  
>  # FIXME: use SANITIZER_COMMON_SUPPORTED_ARCH here
>  filter_available_targets(SANITIZER_UNITTEST_SUPPORTED_ARCH x86_64 i386 mips64 mips64el)
> +if(APPLE)
> +  darwin_filter_host_archs(SANITIZER_UNITTEST_SUPPORTED_ARCH SANITIZER_COMMON_SUPPORTED_ARCH)
> +endif()
>  
>  set(SANITIZER_UNITTESTS
>    sanitizer_allocator_test.cc
> Index: lib/asan/tests/CMakeLists.txt
> ===================================================================
> --- lib/asan/tests/CMakeLists.txt
> +++ lib/asan/tests/CMakeLists.txt
> @@ -116,6 +116,9 @@
>    get_filename_component(basename ${source} NAME)
>    set(output_obj "${obj_list}.${basename}.${arch}${kind}.o")
>    get_target_flags_for_arch(${arch} TARGET_CFLAGS)
> +  if(APPLE)
> +    set(TARGET_CFLAGS ${DARWIN_osx_CFLAGS} -arch ${arch})
> +  endif()
>    set(COMPILE_DEPS ${ASAN_UNITTEST_HEADERS} ${ASAN_BLACKLIST_FILE})
>    if(NOT COMPILER_RT_STANDALONE_BUILD)
>      list(APPEND COMPILE_DEPS gtest asan)
> @@ -261,7 +264,11 @@
>  endmacro()
>  
>  if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID)
> -  foreach(arch ${ASAN_SUPPORTED_ARCH})
> +  set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH})
> +  if(APPLE)
> +    darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
> +  endif()
> +  foreach(arch ${ASAN_TEST_ARCH})
>      add_asan_tests_for_arch_and_kind(${arch} "-inline")
>      add_asan_tests_for_arch_and_kind(${arch} "-with-calls"
>        -mllvm -asan-instrumentation-with-call-threshold=0)
> Index: cmake/config-ix.cmake
> ===================================================================
> --- cmake/config-ix.cmake
> +++ cmake/config-ix.cmake
> @@ -238,7 +238,12 @@
>    if(ARCH_INDEX EQUAL -1)
>      message(FATAL_ERROR "Unsupported architecture: ${arch}")
>    else()
> -    set(${out_var} ${TARGET_${arch}_CFLAGS} PARENT_SCOPE)
> +    if (NOT APPLE)
> +      set(${out_var} ${TARGET_${arch}_CFLAGS} PARENT_SCOPE)
> +    else()
> +      # This is only called in constructing cflags for tests, so we assume OS X.

Could you wordsmith this to more explicitly call out that the reason
this makes sense is that these targets are going to run on the host
system? "tests" could mean something that's cross compiled and run
remotely, but that's obviously not the case here.

> +      set(${out_var} -arch ${arch} PARENT_SCOPE)
> +    endif()
>    endif()
>  endfunction()
>  
> Index: cmake/Modules/CompilerRTDarwinUtils.cmake
> ===================================================================
> --- cmake/Modules/CompilerRTDarwinUtils.cmake
> +++ cmake/Modules/CompilerRTDarwinUtils.cmake
> @@ -77,3 +77,25 @@
>    endforeach()
>    set(${valid_archs} ${working_archs} PARENT_SCOPE)
>  endfunction()
> +
> +# This function checks the host cpusubtype to see if it is post-haswell. Haswell
> +# and later machines can run x86_64h binaries. Haswell is cpusubtype 8.
> +function(darwin_filter_host_archs input output)
> +  list_union(tmp_var DARWIN_osx_ARCHS ${input})
> +  execute_process(
> +    COMMAND sysctl hw.cpusubtype
> +    OUTPUT_VARIABLE SUBTYPE)
> +
> +  string(REGEX MATCH "hw.cpusubtype: ([0-9]*)"
> +         SUBTYPE_MATCHED "${SUBTYPE}")
> +  set(HASWELL_SUPPORTED Off)
> +  if(ARCHES_MATCHED)
> +    if(CMAKE_MATCH_1 GREATER_OR_EQUAL_TO 8)
> +      set(HASWELL_SUPPORTED On)
> +    endif()
> +  endif()
> +  if(NOT HASWELL_SUPPORTED)
> +    list(REMOVE_ITEM tmp_var x86_64h)
> +  endif()
> +  set(${output} ${tmp_var} PARENT_SCOPE)
> +endfunction()


More information about the llvm-commits mailing list