Skip to content

Commit df75819

Browse files
committed
refs #14584 - separated handling of Clang and AppleClang in CMake
1 parent 45e0eb0 commit df75819

4 files changed

Lines changed: 28 additions & 15 deletions

File tree

cmake/compilerCheck.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
22
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1)
33
message(ERROR "GCC >= 5.1 required - detected ${CMAKE_CXX_COMPILER_VERSION} not supported")
44
endif()
5-
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
5+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
66
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)
77
message(ERROR "Clang >= 3.5 required - detected ${CMAKE_CXX_COMPILER_VERSION} not supported")
88
endif()
9+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
10+
# TODO: AppleClang versions do not align with Clang versions - add check for proper version
911
elseif(MSVC)
1012
if(MSVC_VERSION VERSION_LESS 1900)
1113
message(ERROR "Visual Studio >= 2015 (19.0) required - detected ${MSVC_VERSION} not supported")
1214
endif()
15+
else()
16+
message(WARNING "Unknown compiler ${CMAKE_CXX_COMPILER_ID}")
1317
endif()

cmake/compilerDefinitions.cmake

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,29 @@ if(MSVC)
88
add_definitions(-DWIN32_LEAN_MEAN)
99
endif()
1010

11-
# TODO: this should probably apply to the compiler and not the platform - I think it is only "broken" with MinGW
12-
# TODO: AppleClang only has libc++
13-
# TODO: what about clang-cl and native Win32 clang?
14-
if(CPPCHK_GLIBCXX_DEBUG AND UNIX AND CMAKE_BUILD_TYPE STREQUAL "Debug")
15-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
16-
if(USE_LIBCXX)
17-
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18)
18-
add_definitions(-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG)
19-
else()
20-
add_definitions(-D_LIBCPP_ENABLE_ASSERTIONS=1)
21-
endif()
22-
# TODO: also add _LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS?
11+
# libstdc++-specific flags
12+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR (NOT USE_LIBCXX AND CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
13+
if(CPPCHK_GLIBCXX_DEBUG AND CMAKE_BUILD_TYPE STREQUAL "Debug")
14+
add_definitions(-D_GLIBCXX_DEBUG)
15+
endif()
16+
endif()
17+
18+
# TODO: what about clang-cl?
19+
# libc++-specific flags - AppleClang only has libc++
20+
if ((USE_LIBCXX AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
21+
if(CPPCHK_GLIBCXX_DEBUG AND CMAKE_BUILD_TYPE STREQUAL "Debug")
22+
# TODO: AppleClang versions do not align with Clang versions - add check for proper version
23+
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18)
24+
add_definitions(-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG)
25+
else()
26+
add_definitions(-D_LIBCPP_ENABLE_ASSERTIONS=1)
2327
endif()
28+
# TODO: also add _LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS?
2429
else()
2530
# TODO: check if this can be enabled again for Clang - also done in Makefile
2631
add_definitions(-D_GLIBCXX_DEBUG)
2732
endif()
28-
endif()
2933

30-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND USE_LIBCXX)
3134
add_definitions(-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
3235
endif()
3336

cmake/options.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ if (NOT USE_BOOST AND USE_BOOST_INT128)
116116
endif()
117117
option(USE_LIBCXX "Use libc++ instead of libstdc++" OFF)
118118

119+
if(USE_LIBCXX AND NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
120+
message(FATAL_ERROR "libc++ can only be used with a Clang-based compiler")
121+
endif()
122+
119123
option(NO_UNIX_SIGNAL_HANDLING "Disable usage of Unix Signal Handling" OFF)
120124
option(NO_UNIX_BACKTRACE_SUPPORT "Disable usage of Unix Backtrace support" OFF)
121125
option(NO_WINDOWS_SEH "Disable usage of Windows SEH" OFF)

lib/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
# define UNUSED
9797
#endif
9898

99+
// TODO: AppleClang versions do not align with Clang versions - add check for proper version
99100
// warn_unused
100101
#if __has_cpp_attribute (gnu::warn_unused) || \
101102
(defined(__clang__) && (__clang_major__ >= 15))
@@ -115,6 +116,7 @@
115116
# define DEPRECATED
116117
#endif
117118

119+
// TODO: AppleClang versions do not align with Clang versions - add check for proper version
118120
// returns_nonnull
119121
#if __has_cpp_attribute (gnu::returns_nonnull)
120122
# define RET_NONNULL [[gnu::returns_nonnull]]

0 commit comments

Comments
 (0)