CMake, compiler-rt, and MacOS

Hi Chandler,

If I remember correctly, you are the de-facto maintainer for the
CMake-built-mainainer, so..:

Sure, but I'm often busy. You're better off using the development mailing
list for questions such as this, and I've moved the conversation there.

I have a problem compiling compiler-rt on MacOS with libc++. For this to
work, the flag -mmacosx-version-min=10.7 is required, so I use:
CMAKE_CXX_FLAGS:STRING=-mmacosx-version-min=10.7 -stdlib=libc++

However, around line 140, the CMakeLists.txt of compiler-rt contains:
if(APPLE)
  list(APPEND SANITIZER_COMMON_CFLAGS -mmacosx-version-min=10.5)
endif()

Now, when building with clang, the minimal minimal version is used, so
10.5, which results in a compiler error complaining that the minimal
version should be 10.7.

My question: could you please add some CMake logic to the compiler-rt
CMakeLists.txt to check if there is already a macosx-version-min flag set,
or to not include the flag if -stdlib=libc++ is set?

I don't know the specific needs of either libc++ or the sanitizer on mac;
instead this should be answered by one of the folks actively working on
that area. There are several on the list that can likely help.

+samsonov, glider

+samsonov, glider

Hi Chandler,

If I remember correctly, you are the de-facto maintainer for the
CMake-built-mainainer, so..:

Sure, but I'm often busy. You're better off using the development mailing
list for questions such as this, and I've moved the conversation there.

I have a problem compiling compiler-rt on MacOS with libc++. For this to
work, the flag -mmacosx-version-min=10.7 is required, so I use:
CMAKE_CXX_FLAGS:STRING=-mmacosx-version-min=10.7 -stdlib=libc++

However, around line 140, the CMakeLists.txt of compiler-rt contains:
if(APPLE)
  list(APPEND SANITIZER_COMMON_CFLAGS -mmacosx-version-min=10.5)
endif()

Now, when building with clang, the minimal minimal version is used, so
10.5, which results in a compiler error complaining that the minimal
version should be 10.7.

My question: could you please add some CMake logic to the compiler-rt
CMakeLists.txt to check if there is already a macosx-version-min flag set,
or to not include the flag if -stdlib=libc++ is set?

Hi Erik,
IIRC, using -stdlib=libc++ on Mac should also require presence of flag
-mmacosx-version-min? If that's the case, then probably we can put the logic
of determining the set of flags required for libc++ into CMake build rules
and use CMake variable like COMPILER_RT_USES_LIBCXX. Does the attached
patch solve a problem for you? If you're building LLVM/Clang tree, however,
we may want to hoist this to smth. like LLVM_USES_LIBCXX.

zpatch.macosx_version (1.4 KB)

Yes, that works, when I (manually) set the COMPILER_RT_USES_LIBCXX flag. I was wondering if that flag could actually be set when detecting the -stdlib=libc++ flag…

– Erik.

+samsonov, glider

Hi Chandler,

If I remember correctly, you are the de-facto maintainer for the
CMake-built-mainainer, so..:

Sure, but I'm often busy. You're better off using the development
mailing list for questions such as this, and I've moved the conversation
there.

I have a problem compiling compiler-rt on MacOS with libc++. For this
to work, the flag -mmacosx-version-min=10.7 is required, so I use:
CMAKE_CXX_FLAGS:STRING=-mmacosx-version-min=10.7 -stdlib=libc++

However, around line 140, the CMakeLists.txt of compiler-rt contains:
if(APPLE)
  list(APPEND SANITIZER_COMMON_CFLAGS -mmacosx-version-min=10.5)
endif()

Now, when building with clang, the minimal minimal version is used, so
10.5, which results in a compiler error complaining that the minimal
version should be 10.7.

My question: could you please add some CMake logic to the compiler-rt
CMakeLists.txt to check if there is already a macosx-version-min flag set,
or to not include the flag if -stdlib=libc++ is set?

Hi Erik,
IIRC, using -stdlib=libc++ on Mac should also require presence of flag
-mmacosx-version-min? If that's the case, then probably we can put the logic
of determining the set of flags required for libc++ into CMake build rules
and use CMake variable like COMPILER_RT_USES_LIBCXX. Does the attached
patch solve a problem for you? If you're building LLVM/Clang tree,
however, we may want to hoist this to smth. like LLVM_USES_LIBCXX.

Yes, that works, when I (manually) set the COMPILER_RT_USES_LIBCXX flag. I
was wondering if that flag could actually be set when detecting the
-stdlib=libc++ flag...

r174699 should do this.