diff --git a/CMakeLists.txt b/CMakeLists.txt index 32f56fcfd0..991580622a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,8 +188,14 @@ if (NOT DEFINED CMAKE_INSTALL_RPATH) endif() endif() +if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + set(USING_CLANG ON) +else() + set(USING_CLANG OFF) +endif() + if(C_LINUX) - if(CMAKE_COMPILER_IS_GNUCXX) + if(CMAKE_COMPILER_IS_GNUCXX OR USING_CLANG) # Set _GNU_SOURCE for O_LARGEFILE, O_CLOEXEC, O_DIRECTORY, O_NOFOLLOW, etc flags on older systems # (pre POSIX.1-2008: glibc 2.11 and earlier). #4042 set(_GNU_SOURCE 1) diff --git a/cmake/FindLLVM.cmake b/cmake/FindLLVM.cmake index 7c395bdc44..6357585e85 100644 --- a/cmake/FindLLVM.cmake +++ b/cmake/FindLLVM.cmake @@ -113,7 +113,7 @@ else() ) if(result_code) _LLVM_FAIL("Failed to execute llvm-config ('${LLVM_CONFIG}', result code: '${result_code})'") - else() + else() file(TO_CMAKE_PATH "${tmplibs}" tmplibs) string(REGEX MATCHALL "${pattern}[^ ]+" LLVM_${var} ${tmplibs}) endif() @@ -163,9 +163,15 @@ else() set(LLVM_NATIVE_ARCH ${CMAKE_MATCH_1}) message(STATUS "LLVM_NATIVE_ARCH: ${LLVM_NATIVE_ARCH}") + if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + set(USING_CLANG ON) + else() + set(USING_CLANG OFF) + endif() + # On CMake builds of LLVM, the output of llvm-config --cxxflags does not # include -fno-rtti, leading to linker errors. Be sure to add it. - if(NOT MSVC AND (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))) + if(NOT MSVC AND (CMAKE_COMPILER_IS_GNUCXX OR USING_CLANG)) if(NOT ${LLVM_CXXFLAGS} MATCHES "-fno-rtti") set(LLVM_CXXFLAGS "${LLVM_CXXFLAGS} -fno-rtti") endif() @@ -181,7 +187,7 @@ else() endif() # Remove gcc-specific flags for clang. - if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") + if(USING_CLANG) string(REPLACE "-Wno-maybe-uninitialized " "" LLVM_CXXFLAGS ${LLVM_CXXFLAGS}) endif()