Skip to content

Commit

Permalink
CMake: define _GNU_SOURCE for Clang, as well
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
micahsnyder committed Nov 23, 2022
1 parent e0be839 commit e8a1fa6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions cmake/FindLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()

Expand Down

0 comments on commit e8a1fa6

Please sign in to comment.