@@ -22,7 +22,7 @@ option(build_parse "Parses source code and dumps the dependencies between th
2222option (build_search "Build external search tools (doxysearch and doxyindexer)" OFF )
2323option (build_doc "Build user manual (HTML and PDF)" OFF )
2424option (build_doc_chm "Build user manual (CHM)" OFF )
25- if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
25+ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
2626 option (use_libc++ "Use libc++ as C++ standard library." ON )
2727endif ()
2828option (use_libclang "Add support for libclang parsing." OFF )
@@ -36,6 +36,7 @@ option(enable_coverage "Enable coverage reporting for gcc/clang [development]" O
3636option (enable_tracing "Enable tracing option in release builds [development]" OFF )
3737option (enable_lex_debug "Enable debugging info for lexical scanners in release builds [development]" OFF )
3838
39+ include (CheckCXXCompilerFlag)
3940
4041set (force_qt CACHE INTERNAL "Forces doxywizard to build using the specified major version, this can be Qt5 or Qt6" )
4142set_property (CACHE force_qt PROPERTY STRINGS OFF Qt6 Qt5)
@@ -82,8 +83,17 @@ if (build_wizard)
8283 endif ()
8384endif ()
8485
85- # use C++17 standard for compiling
86- set (CMAKE_CXX_STANDARD 17)
86+ # use C++17 standard for compiling (unless very new Clang is present)
87+ if (
88+ (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND
89+ CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 17) OR
90+ (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
91+ CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19)
92+ )
93+ set (CMAKE_CXX_STANDARD 20)
94+ else ()
95+ set (CMAKE_CXX_STANDARD 17)
96+ endif ()
8797set (CMAKE_CXX_STANDARD_REQUIRED ON )
8898set (CMAKE_CXX_EXTENSIONS ON )
8999
@@ -116,11 +126,28 @@ if (CMAKE_SYSTEM MATCHES "Darwin")
116126 set (EXTRA_LIBS ${CORESERVICES_LIB} )
117127endif ()
118128
119- if ("${CMAKE_CXX_COMPILER_ID} " MATCHES "Clang" )
120- set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_LIBCPP_ENABLE_ASSERTIONS=1" )
121- elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
122- set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_ASSERTIONS" )
123- endif ()
129+ check_cxx_source_compiles(
130+ "
131+ #include <algorithm>
132+
133+ #if !defined(__clang__) || !defined(_LIBCPP_VERSION)
134+ # error \" This is not clang with libcxx by llvm\"
135+ #endif
136+
137+ int main() {
138+ return 0;
139+ }
140+ "
141+ IS_CLANG_LIBCPP
142+ FAIL_REGEX "This is not clang with libcxx by llvm"
143+ )
144+
145+ add_compile_definitions (
146+ # LLVM's clang in combination with libc++
147+ $<$<AND :$<CONFIG:Debug>,$<BOOL :${IS_CLANG_LIBCPP} >>:_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG>
148+ # LLVM's clang or gcc in combination with libstdc++ (GNU)
149+ $<$<AND :$<CONFIG:Debug>,$<NOT :$<BOOL :${IS_CLANG_LIBCPP} >>>:_GLIBCXX_ASSERTIONS>
150+ )
124151
125152set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSQLITE_OMIT_LOAD_EXTENSION=1" )
126153
@@ -171,7 +198,11 @@ if (CMAKE_SYSTEM_NAME MATCHES "Windows")
171198endif ()
172199
173200# needed for JavaCC
174- set (JAVA_CC_EXTRA_FLAGS "-DJAVACC_CHAR_TYPE=\" unsigned char\" " )
201+ if (CMAKE_CXX_STANDARD EQUAL 20)
202+ set (JAVA_CC_EXTRA_FLAGS "-DJAVACC_CHAR_TYPE=\" char8_t\" " )
203+ else ()
204+ set (JAVA_CC_EXTRA_FLAGS "-DJAVACC_CHAR_TYPE=\" unsigned char\" " )
205+ endif ()
175206set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${JAVA_CC_EXTRA_FLAGS} " )
176207set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${JAVA_CC_EXTRA_FLAGS} " )
177208
0 commit comments