From e8a1fa6d537cfcdb40565ce94285102f5d4b4afa Mon Sep 17 00:00:00 2001 From: Micah Snyder Date: Tue, 22 Nov 2022 11:59:02 -0800 Subject: [PATCH] CMake: define _GNU_SOURCE for Clang, as well Building with these will fail for Clang because _GNU_SOURCE is not defined. -Werror=implicit-function-declaration -Werror=implicit-int -Werror=strict-prototypes Also added fix to use "MATCHES" instead of "EQUALS" in FindLLVM where the same sort of logic is used. --- CMakeLists.txt | 8 +++++++- cmake/FindLLVM.cmake | 12 +++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) 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()