[compiler-rt] r227509 - [compiler-rt] OS X: Update the CMake and Make builds to explicitely use libc++, mmacosx-version-min and SDKs

Justin Bogner mail at justinbogner.com
Tue Feb 3 01:17:46 PST 2015


Kuba Brecka <kuba.brecka at gmail.com> writes:
> Author: kuba.brecka
> Date: Thu Jan 29 17:19:26 2015
> New Revision: 227509
>
> URL: http://llvm.org/viewvc/llvm-project?rev=227509&view=rev
> Log:
> [compiler-rt] OS X: Update the CMake and Make builds to explicitely
> use libc++, mmacosx-version-min and SDKs
>
> In both CMake and Makefiles, we are inconsistent about the use of
> libstdc++ vs. libc++, SDKs and minimum deployment targets for OS
> X. Let's fix the detection of SDKs, and let's explicitely set that we
> link against libc++ and mmacosx-version-min is 10.7.
>
>
> Modified:
>     compiler-rt/trunk/CMakeLists.txt
>     compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
>     compiler-rt/trunk/make/platform/clang_darwin.mk
>
> Modified: compiler-rt/trunk/CMakeLists.txt
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/CMakeLists.txt?rev=227509&r1=227508&r2=227509&view=diff
> ==============================================================================
> --- compiler-rt/trunk/CMakeLists.txt (original)
> +++ compiler-rt/trunk/CMakeLists.txt Thu Jan 29 17:19:26 2015
> @@ -271,12 +271,27 @@ append_list_if(COMPILER_RT_HAS_WD4391_FL
>  append_list_if(COMPILER_RT_HAS_WD4722_FLAG /wd4722 SANITIZER_COMMON_CFLAGS)
>  append_list_if(COMPILER_RT_HAS_WD4800_FLAG /wd4800 SANITIZER_COMMON_CFLAGS)
>  if(APPLE)
> -  # Obtain the iOS Simulator SDK path from xcodebuild.
> -  execute_process(
> -    COMMAND xcodebuild -version -sdk iphonesimulator Path
> -    OUTPUT_VARIABLE IOSSIM_SDK_DIR
> -    OUTPUT_STRIP_TRAILING_WHITESPACE
> -  )
> +  macro(find_darwin_sdk_dir var sdk_name)
> +    # Let's first try the internal SDK, otherwise use the public SDK.
> +    execute_process(
> +      COMMAND xcodebuild -version -sdk ${sdk_name}.internal Path
> +      OUTPUT_VARIABLE ${var}
> +      OUTPUT_STRIP_TRAILING_WHITESPACE
> +      ERROR_FILE /dev/null
> +    )
> +    if(${var} STREQUAL "")
> +      execute_process(
> +        COMMAND xcodebuild -version -sdk ${sdk_name} Path
> +        OUTPUT_VARIABLE ${var}
> +        OUTPUT_STRIP_TRAILING_WHITESPACE
> +        ERROR_FILE /dev/null
> +      )
> +    endif()
> +  endmacro()
> +
> +  find_darwin_sdk_dir(OSX_SDK_DIR macosx)
> +  find_darwin_sdk_dir(IOSSIM_SDK_DIR iphonesimulator)
> +
>    string(REGEX MATCH "-mmacosx-version-min="
>           MACOSX_VERSION_MIN_FLAG "${CMAKE_CXX_FLAGS}")
>    set(SANITIZER_COMMON_SUPPORTED_DARWIN_OS osx)
> @@ -286,10 +301,12 @@ if(APPLE)
>  
>    set(SANITIZER_MIN_OSX_VERSION 10.7)
>    set(CMAKE_OSX_DEPLOYMENT_TARGET "") # We're setting the flag manually below.
> -  set(DARWIN_osx_CFLAGS -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION})
> +  set(DARWIN_osx_CFLAGS -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION}
> +    -isysroot ${OSX_SDK_DIR} -stdlib=libc++)
>    set(DARWIN_iossim_CFLAGS
>      -mios-simulator-version-min=7.0 -isysroot ${IOSSIM_SDK_DIR})
> -  set(DARWIN_osx_LINKFLAGS)
> +  set(DARWIN_osx_LINKFLAGS -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION}
> +    -isysroot ${OSX_SDK_DIR} -stdlib=libc++)

This doesn't work if you don't have an Xcode installed (ie, just command
line tools). OSX_SDK_DIR ends up empty so you get the rather confusing
error of "no such sysroot directory: '-stdlib=libc++'".

The clue that the problem is a missing Xcode shows up earlier on stderr:

    xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

>    set(DARWIN_iossim_LINKFLAGS
>      -Wl,-ios_simulator_version_min,7.0.0
>      -mios-simulator-version-min=7.0
>
> 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=227509&r1=227508&r2=227509&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/tests/CMakeLists.txt (original)
> +++ compiler-rt/trunk/lib/asan/tests/CMakeLists.txt Thu Jan 29 17:19:26 2015
> @@ -47,6 +47,11 @@ list(APPEND ASAN_UNITTEST_COMMON_CFLAGS
>    -DASAN_HAS_EXCEPTIONS=1
>    -DASAN_UAR=0)
>  
> +if(APPLE)
> +  list(APPEND ASAN_UNITTEST_COMMON_CFLAGS ${DARWIN_osx_CFLAGS})
> +  list(APPEND ASAN_UNITTEST_COMMON_LINKFLAGS ${DARWIN_osx_LINKFLAGS})
> +endif()
> +
>  set(ASAN_BLACKLIST_FILE "${CMAKE_CURRENT_SOURCE_DIR}/asan_test.ignore")
>  set(ASAN_UNITTEST_INSTRUMENTED_CFLAGS
>    ${ASAN_UNITTEST_COMMON_CFLAGS}
>
> Modified: compiler-rt/trunk/make/platform/clang_darwin.mk
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/make/platform/clang_darwin.mk?rev=227509&r1=227508&r2=227509&view=diff
> ==============================================================================
> --- compiler-rt/trunk/make/platform/clang_darwin.mk (original)
> +++ compiler-rt/trunk/make/platform/clang_darwin.mk Thu Jan 29 17:19:26 2015
> @@ -44,10 +44,14 @@ XCRun = \
>      result=`xcrun -find $(1) 2> /dev/null`; \
>      if [ "$$?" != "0" ]; then result=$(1); fi; \
>      echo $$result)
> +# Prefer building with the internal SDKs.
>  XCRunSdkPath = \
>    $(shell \
> -    result=`xcrun --sdk $(1) --show-sdk-path 2> /dev/null`; \
> -    if [ "$$?" != "0" ]; then result=""; fi; \
> +    result=`xcrun --sdk $(1).internal --show-sdk-path 2> /dev/null`; \
> +    if [ "$$?" != "0" ]; then \
> +      result=`xcrun --sdk $(1) --show-sdk-path 2> /dev/null`; \
> +      if [ "$$?" != "0" ]; then result=""; fi; \
> +    fi; \
>      echo $$result)
>  ###
>  
> @@ -170,6 +174,7 @@ CFLAGS.10.4		:= $(CFLAGS) $(OSX_DEPLOYME
>  
>  CFLAGS.asan_osx_dynamic := \
>  	$(CFLAGS) -mmacosx-version-min=10.7 \
> +	-stdlib=libc++ \
>  	-isysroot $(OSX_SDK) \
>  	-fno-builtin \
>  	-gline-tables-only \
> @@ -219,7 +224,9 @@ CFLAGS.profile_ios.arm64  := $(CFLAGS) $
>  
>  # Configure the asan_osx_dynamic library to be built shared.
>  SHARED_LIBRARY.asan_osx_dynamic := 1
> -LDFLAGS.asan_osx_dynamic := -lstdc++ -undefined dynamic_lookup -install_name @rpath/libclang_rt.asan_osx_dynamic.dylib
> +LDFLAGS.asan_osx_dynamic := -lc++ -undefined dynamic_lookup -install_name @rpath/libclang_rt.asan_osx_dynamic.dylib \
> +  -mmacosx-version-min=10.7 \
> +  -isysroot $(OSX_SDK)
>  
>  # Configure the asan_iossim_dynamic library to be built shared.
>  SHARED_LIBRARY.asan_iossim_dynamic := 1
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list