Skip to content

Commit 83a7e99

Browse files
authored
fixed #14584 - set minimum required AppleClang version to 6.0 / separated handling of Clang and AppleClang in CMake (#8257)
1 parent d6ac48f commit 83a7e99

5 files changed

Lines changed: 32 additions & 16 deletions

File tree

cmake/compilerCheck.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ 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+
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
11+
message(ERROR "AppleClang >= 6.0 required - detected ${CMAKE_CXX_COMPILER_VERSION} not supported")
12+
endif()
913
elseif(MSVC)
1014
if(MSVC_VERSION VERSION_LESS 1900)
1115
message(ERROR "Visual Studio >= 2015 (19.0) required - detected ${MSVC_VERSION} not supported")
1216
endif()
17+
else()
18+
message(WARNING "Unknown compiler ${CMAKE_CXX_COMPILER_ID}")
1319
endif()

cmake/compilerDefinitions.cmake

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,30 @@ 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: determine proper version for AppleClang - current value is based on the oldest version avaialble in CI
23+
if((CMAKE_CXX_COMPILER_ID STREQUALS "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18) OR
24+
(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 17))
25+
add_definitions(-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG)
26+
else()
27+
add_definitions(-D_LIBCPP_ENABLE_ASSERTIONS=1)
2328
endif()
29+
# TODO: also add _LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS?
2430
else()
2531
# TODO: check if this can be enabled again for Clang - also done in Makefile
2632
add_definitions(-D_GLIBCXX_DEBUG)
2733
endif()
28-
endif()
2934

30-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND USE_LIBCXX)
3135
add_definitions(-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
3236
endif()
3337

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]]

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ You can stop the script whenever you like with Ctrl C.
3636
3737
## Compiling
3838
39-
Cppcheck requires a C++ compiler with (partial) C++11 support. Minimum required versions are GCC 5.1 / Clang 3.5 / Visual Studio 2015.
39+
Cppcheck requires a C++ compiler with (partial) C++11 support. Minimum required versions are GCC 5.1 / Clang 3.5 / AppleClang 6.0 / Visual Studio 2015.
4040
4141
To build the GUI application, you need to use the CMake build system.
4242

0 commit comments

Comments
 (0)