• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# number of parallel jobs for CTest
2set(N 10)
3
4###############################################################################
5# Needed tools.
6###############################################################################
7
8include(FindPython3)
9find_package(Python3 COMPONENTS Interpreter)
10
11find_program(ASTYLE_TOOL NAMES astyle)
12execute_process(COMMAND ${ASTYLE_TOOL} --version OUTPUT_VARIABLE ASTYLE_TOOL_VERSION ERROR_VARIABLE ASTYLE_TOOL_VERSION)
13string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" ASTYLE_TOOL_VERSION "${ASTYLE_TOOL_VERSION}")
14message(STATUS "�� Artistic Style ${ASTYLE_TOOL_VERSION} (${ASTYLE_TOOL})")
15
16find_program(CLANG_TOOL NAMES clang++-HEAD clang++-12 clang++-11 clang++)
17execute_process(COMMAND ${CLANG_TOOL} --version OUTPUT_VARIABLE CLANG_TOOL_VERSION ERROR_VARIABLE CLANG_TOOL_VERSION)
18string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TOOL_VERSION "${CLANG_TOOL_VERSION}")
19message(STATUS "�� Clang ${CLANG_TOOL_VERSION} (${CLANG_TOOL})")
20
21find_program(CLANG_TIDY_TOOL NAMES clang-tidy-12 clang-tidy-11 clang-tidy)
22execute_process(COMMAND ${CLANG_TIDY_TOOL} --version OUTPUT_VARIABLE CLANG_TIDY_TOOL_VERSION ERROR_VARIABLE CLANG_TIDY_TOOL_VERSION)
23string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TIDY_TOOL_VERSION "${CLANG_TIDY_TOOL_VERSION}")
24message(STATUS "�� Clang-Tidy ${CLANG_TIDY_TOOL_VERSION} (${CLANG_TIDY_TOOL})")
25
26message(STATUS "�� CMake ${CMAKE_VERSION} (${CMAKE_COMMAND})")
27
28find_program(CPPCHECK_TOOL NAMES cppcheck)
29execute_process(COMMAND ${CPPCHECK_TOOL} --version OUTPUT_VARIABLE CPPCHECK_TOOL_VERSION ERROR_VARIABLE CPPCHECK_TOOL_VERSION)
30string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CPPCHECK_TOOL_VERSION "${CPPCHECK_TOOL_VERSION}")
31message(STATUS "�� Cppcheck ${CPPCHECK_TOOL_VERSION} (${CPPCHECK_TOOL})")
32
33find_program(GCC_TOOL NAMES g++-HEAD g++-11 g++-latest)
34execute_process(COMMAND ${GCC_TOOL} --version OUTPUT_VARIABLE GCC_TOOL_VERSION ERROR_VARIABLE GCC_TOOL_VERSION)
35string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCC_TOOL_VERSION "${GCC_TOOL_VERSION}")
36message(STATUS "�� GCC ${GCC_TOOL_VERSION} (${GCC_TOOL})")
37
38find_program(GCOV_TOOL NAMES gcov-HEAD gcov-11 gcov-10 gcov)
39execute_process(COMMAND ${GCOV_TOOL} --version OUTPUT_VARIABLE GCOV_TOOL_VERSION ERROR_VARIABLE GCOV_TOOL_VERSION)
40string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCOV_TOOL_VERSION "${GCOV_TOOL_VERSION}")
41message(STATUS "�� GCOV ${GCOV_TOOL_VERSION} (${GCOV_TOOL})")
42
43find_program(GIT_TOOL NAMES git)
44execute_process(COMMAND ${GIT_TOOL} --version OUTPUT_VARIABLE GIT_TOOL_VERSION ERROR_VARIABLE GIT_TOOL_VERSION)
45string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GIT_TOOL_VERSION "${GIT_TOOL_VERSION}")
46message(STATUS "�� Git ${GIT_TOOL_VERSION} (${GIT_TOOL})")
47
48find_program(IWYU_TOOL NAMES include-what-you-use iwyu)
49execute_process(COMMAND ${IWYU_TOOL} --version OUTPUT_VARIABLE IWYU_TOOL_VERSION ERROR_VARIABLE IWYU_TOOL_VERSION)
50string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" IWYU_TOOL_VERSION "${IWYU_TOOL_VERSION}")
51message(STATUS "�� include-what-you-use ${IWYU_TOOL_VERSION} (${IWYU_TOOL})")
52
53find_program(INFER_TOOL NAMES infer)
54execute_process(COMMAND ${INFER_TOOL} --version OUTPUT_VARIABLE INFER_TOOL_VERSION ERROR_VARIABLE INFER_TOOL_VERSION)
55string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" INFER_TOOL_VERSION "${INFER_TOOL_VERSION}")
56message(STATUS "�� Infer ${INFER_TOOL_VERSION} (${INFER_TOOL})")
57
58find_program(LCOV_TOOL NAMES lcov)
59execute_process(COMMAND ${LCOV_TOOL} --version OUTPUT_VARIABLE LCOV_TOOL_VERSION ERROR_VARIABLE LCOV_TOOL_VERSION)
60string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" LCOV_TOOL_VERSION "${LCOV_TOOL_VERSION}")
61message(STATUS "�� LCOV ${LCOV_TOOL_VERSION} (${LCOV_TOOL})")
62
63find_program(NINJA_TOOL NAMES ninja)
64execute_process(COMMAND ${NINJA_TOOL} --version OUTPUT_VARIABLE NINJA_TOOL_VERSION ERROR_VARIABLE NINJA_TOOL_VERSION)
65string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" NINJA_TOOL_VERSION "${NINJA_TOOL_VERSION}")
66message(STATUS "�� Ninja ${NINJA_TOOL_VERSION} (${NINJA_TOOL})")
67
68find_program(OCLINT_TOOL NAMES oclint-json-compilation-database)
69find_program(OCLINT_VERSION_TOOL NAMES oclint)
70execute_process(COMMAND ${OCLINT_VERSION_TOOL} --version OUTPUT_VARIABLE OCLINT_TOOL_VERSION ERROR_VARIABLE OCLINT_TOOL_VERSION)
71string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" OCLINT_TOOL_VERSION "${OCLINT_TOOL_VERSION}")
72message(STATUS "�� OCLint ${OCLINT_TOOL_VERSION} (${OCLINT_TOOL})")
73
74find_program(VALGRIND_TOOL NAMES valgrind)
75execute_process(COMMAND ${VALGRIND_TOOL} --version OUTPUT_VARIABLE VALGRIND_TOOL_VERSION ERROR_VARIABLE VALGRIND_TOOL_VERSION)
76string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" VALGRIND_TOOL_VERSION "${VALGRIND_TOOL_VERSION}")
77message(STATUS "�� Valgrind ${VALGRIND_TOOL_VERSION} (${VALGRIND_TOOL})")
78
79find_program(GENHTML_TOOL NAMES genhtml)
80find_program(PLOG_CONVERTER_TOOL NAMES plog-converter)
81find_program(PVS_STUDIO_ANALYZER_TOOL NAMES pvs-studio-analyzer)
82find_program(SCAN_BUILD_TOOL NAMES scan-build-11 scan-build)
83
84# the individual source files
85file(GLOB_RECURSE SRC_FILES ${PROJECT_SOURCE_DIR}/include/nlohmann/*.hpp)
86
87###############################################################################
88# Thorough check with recent compilers
89###############################################################################
90
91# Ignored Clang warnings:
92# -Wno-c++98-compat               The library targets C++11.
93# -Wno-c++98-compat-pedantic      The library targets C++11.
94# -Wno-deprecated-declarations    The library contains annotations for deprecated functions.
95# -Wno-extra-semi-stmt            The library uses std::assert which triggers this warning.
96# -Wno-padded                     We do not care about padding warnings.
97# -Wno-covered-switch-default     All switches list all cases and a default case.
98# -Wno-weak-vtables               The library is header-only.
99
100set(CLANG_CXXFLAGS "-std=c++11                        \
101    -Werror                                           \
102    -Weverything                                      \
103    -Wno-c++98-compat                                    \
104    -Wno-c++98-compat-pedantic                           \
105    -Wno-deprecated-declarations                         \
106    -Wno-extra-semi-stmt                                 \
107    -Wno-padded                                          \
108    -Wno-covered-switch-default                          \
109    -Wno-weak-vtables                                    \
110")
111
112# Ignored GCC warnings:
113# -Wno-abi-tag                    We do not care about ABI tags.
114# -Wno-aggregate-return           The library uses aggregate returns.
115# -Wno-long-long                  The library uses the long long type to interface with system functions.
116# -Wno-namespaces                 The library uses namespaces.
117# -Wno-padded                     We do not care about padding warnings.
118# -Wno-system-headers             We do not care about warnings in system headers.
119# -Wno-templates                  The library uses templates.
120
121set(GCC_CXXFLAGS "-std=c++11                          \
122    -pedantic                                         \
123    -Werror                                           \
124    --all-warnings                                    \
125    --extra-warnings                                  \
126    -W                                                \
127    -WNSObject-attribute                              \
128    -Wno-abi-tag                                         \
129    -Waddress                                         \
130    -Waddress-of-packed-member                        \
131    -Wno-aggregate-return                                \
132    -Waggressive-loop-optimizations                   \
133    -Waligned-new=all                                 \
134    -Wall                                             \
135    -Walloc-zero                                      \
136    -Walloca                                          \
137    -Wanalyzer-double-fclose                          \
138    -Wanalyzer-double-free                            \
139    -Wanalyzer-exposure-through-output-file           \
140    -Wanalyzer-file-leak                              \
141    -Wanalyzer-free-of-non-heap                       \
142    -Wanalyzer-malloc-leak                            \
143    -Wanalyzer-mismatching-deallocation               \
144    -Wanalyzer-null-argument                          \
145    -Wanalyzer-null-dereference                       \
146    -Wanalyzer-possible-null-argument                 \
147    -Wanalyzer-possible-null-dereference              \
148    -Wanalyzer-shift-count-negative                   \
149    -Wanalyzer-shift-count-overflow                   \
150    -Wanalyzer-stale-setjmp-buffer                    \
151    -Wanalyzer-tainted-array-index                    \
152    -Wanalyzer-too-complex                            \
153    -Wanalyzer-unsafe-call-within-signal-handler      \
154    -Wanalyzer-use-after-free                         \
155    -Wanalyzer-use-of-pointer-in-stale-stack-frame    \
156    -Wanalyzer-write-to-const                         \
157    -Wanalyzer-write-to-string-literal                \
158    -Warith-conversion                                \
159    -Warray-bounds                                    \
160    -Warray-bounds=2                                  \
161    -Warray-parameter=2                               \
162    -Wattribute-alias=2                               \
163    -Wattribute-warning                               \
164    -Wattributes                                      \
165    -Wbool-compare                                    \
166    -Wbool-operation                                  \
167    -Wbuiltin-declaration-mismatch                    \
168    -Wbuiltin-macro-redefined                         \
169    -Wc++0x-compat                                    \
170    -Wc++11-compat                                    \
171    -Wc++14-compat                                    \
172    -Wc++17-compat                                    \
173    -Wc++1z-compat                                    \
174    -Wc++20-compat                                    \
175    -Wc++2a-compat                                    \
176    -Wcannot-profile                                  \
177    -Wcast-align                                      \
178    -Wcast-align=strict                               \
179    -Wcast-function-type                              \
180    -Wcast-qual                                       \
181    -Wcatch-value=3                                   \
182    -Wchar-subscripts                                 \
183    -Wclass-conversion                                \
184    -Wclass-memaccess                                 \
185    -Wclobbered                                       \
186    -Wcomma-subscript                                 \
187    -Wcomment                                         \
188    -Wcomments                                        \
189    -Wconditionally-supported                         \
190    -Wconversion                                      \
191    -Wconversion-null                                 \
192    -Wcoverage-mismatch                               \
193    -Wcpp                                             \
194    -Wctad-maybe-unsupported                          \
195    -Wctor-dtor-privacy                               \
196    -Wdangling-else                                   \
197    -Wdate-time                                       \
198    -Wdelete-incomplete                               \
199    -Wdelete-non-virtual-dtor                         \
200    -Wdeprecated                                      \
201    -Wdeprecated-copy                                 \
202    -Wdeprecated-copy-dtor                            \
203    -Wdeprecated-declarations                         \
204    -Wdeprecated-enum-enum-conversion                 \
205    -Wdeprecated-enum-float-conversion                \
206    -Wdisabled-optimization                           \
207    -Wdiv-by-zero                                     \
208    -Wdouble-promotion                                \
209    -Wduplicated-branches                             \
210    -Wduplicated-cond                                 \
211    -Weffc++                                          \
212    -Wempty-body                                      \
213    -Wendif-labels                                    \
214    -Wenum-compare                                    \
215    -Wenum-conversion                                 \
216    -Wexpansion-to-defined                            \
217    -Wextra                                           \
218    -Wextra-semi                                      \
219    -Wfloat-conversion                                \
220    -Wfloat-equal                                     \
221    -Wformat-contains-nul                             \
222    -Wformat-diag                                     \
223    -Wformat-extra-args                               \
224    -Wformat-nonliteral                               \
225    -Wformat-overflow=2                               \
226    -Wformat-security                                 \
227    -Wformat-signedness                               \
228    -Wformat-truncation=2                             \
229    -Wformat-y2k                                      \
230    -Wformat-zero-length                              \
231    -Wformat=2                                        \
232    -Wframe-address                                   \
233    -Wfree-nonheap-object                             \
234    -Whsa                                             \
235    -Wif-not-aligned                                  \
236    -Wignored-attributes                              \
237    -Wignored-qualifiers                              \
238    -Wimplicit-fallthrough=5                          \
239    -Winaccessible-base                               \
240    -Winherited-variadic-ctor                         \
241    -Winit-list-lifetime                              \
242    -Winit-self                                       \
243    -Winline                                          \
244    -Wint-in-bool-context                             \
245    -Wint-to-pointer-cast                             \
246    -Winvalid-memory-model                            \
247    -Winvalid-offsetof                                \
248    -Winvalid-pch                                     \
249    -Wliteral-suffix                                  \
250    -Wlogical-not-parentheses                         \
251    -Wlogical-op                                      \
252    -Wno-long-long                                       \
253    -Wlto-type-mismatch                               \
254    -Wmain                                            \
255    -Wmaybe-uninitialized                             \
256    -Wmemset-elt-size                                 \
257    -Wmemset-transposed-args                          \
258    -Wmisleading-indentation                          \
259    -Wmismatched-dealloc                              \
260    -Wmismatched-new-delete                           \
261    -Wmismatched-tags                                 \
262    -Wmissing-attributes                              \
263    -Wmissing-braces                                  \
264    -Wmissing-declarations                            \
265    -Wmissing-field-initializers                      \
266    -Wmissing-include-dirs                            \
267    -Wmissing-profile                                 \
268    -Wmultichar                                       \
269    -Wmultiple-inheritance                            \
270    -Wmultistatement-macros                           \
271    -Wno-namespaces                                      \
272    -Wnarrowing                                       \
273    -Wnoexcept                                        \
274    -Wnoexcept-type                                   \
275    -Wnon-template-friend                             \
276    -Wnon-virtual-dtor                                \
277    -Wnonnull                                         \
278    -Wnonnull-compare                                 \
279    -Wnormalized=nfkc                                 \
280    -Wnull-dereference                                \
281    -Wodr                                             \
282    -Wold-style-cast                                  \
283    -Wopenmp-simd                                     \
284    -Woverflow                                        \
285    -Woverlength-strings                              \
286    -Woverloaded-virtual                              \
287    -Wpacked                                          \
288    -Wpacked-bitfield-compat                          \
289    -Wpacked-not-aligned                              \
290    -Wno-padded                                          \
291    -Wparentheses                                     \
292    -Wpedantic                                        \
293    -Wpessimizing-move                                \
294    -Wplacement-new=2                                 \
295    -Wpmf-conversions                                 \
296    -Wpointer-arith                                   \
297    -Wpointer-compare                                 \
298    -Wpragmas                                         \
299    -Wprio-ctor-dtor                                  \
300    -Wpsabi                                           \
301    -Wrange-loop-construct                            \
302    -Wredundant-decls                                 \
303    -Wredundant-move                                  \
304    -Wredundant-tags                                  \
305    -Wregister                                        \
306    -Wreorder                                         \
307    -Wrestrict                                        \
308    -Wreturn-local-addr                               \
309    -Wreturn-type                                     \
310    -Wscalar-storage-order                            \
311    -Wsequence-point                                  \
312    -Wshadow=compatible-local                         \
313    -Wshadow=global                                   \
314    -Wshadow=local                                    \
315    -Wshift-count-negative                            \
316    -Wshift-count-overflow                            \
317    -Wshift-negative-value                            \
318    -Wshift-overflow=2                                \
319    -Wsign-compare                                    \
320    -Wsign-conversion                                 \
321    -Wsign-promo                                      \
322    -Wsized-deallocation                              \
323    -Wsizeof-array-argument                           \
324    -Wsizeof-array-div                                \
325    -Wsizeof-pointer-div                              \
326    -Wsizeof-pointer-memaccess                        \
327    -Wstack-protector                                 \
328    -Wstrict-aliasing                                 \
329    -Wstrict-aliasing=3                               \
330    -Wstrict-null-sentinel                            \
331    -Wstrict-overflow                                 \
332    -Wstrict-overflow=5                               \
333    -Wstring-compare                                  \
334    -Wstringop-overflow=4                             \
335    -Wstringop-overread                               \
336    -Wstringop-truncation                             \
337    -Wsubobject-linkage                               \
338    -Wsuggest-attribute=cold                          \
339    -Wsuggest-attribute=const                         \
340    -Wsuggest-attribute=format                        \
341    -Wsuggest-attribute=malloc                        \
342    -Wsuggest-attribute=noreturn                      \
343    -Wsuggest-attribute=pure                          \
344    -Wsuggest-final-methods                           \
345    -Wsuggest-final-types                             \
346    -Wsuggest-override                                \
347    -Wswitch                                          \
348    -Wswitch-bool                                     \
349    -Wswitch-default                                  \
350    -Wswitch-enum                                     \
351    -Wswitch-outside-range                            \
352    -Wswitch-unreachable                              \
353    -Wsync-nand                                       \
354    -Wsynth                                           \
355    -Wno-system-headers                                  \
356    -Wtautological-compare                            \
357    -Wno-templates                                       \
358    -Wterminate                                       \
359    -Wtrampolines                                     \
360    -Wtrigraphs                                       \
361    -Wtsan                                            \
362    -Wtype-limits                                     \
363    -Wundef                                           \
364    -Wuninitialized                                   \
365    -Wunknown-pragmas                                 \
366    -Wunreachable-code                                \
367    -Wunsafe-loop-optimizations                       \
368    -Wunused                                          \
369    -Wunused-but-set-parameter                        \
370    -Wunused-but-set-variable                         \
371    -Wunused-const-variable=2                         \
372    -Wunused-function                                 \
373    -Wunused-label                                    \
374    -Wunused-local-typedefs                           \
375    -Wunused-macros                                   \
376    -Wunused-parameter                                \
377    -Wunused-result                                   \
378    -Wunused-value                                    \
379    -Wunused-variable                                 \
380    -Wuseless-cast                                    \
381    -Wvarargs                                         \
382    -Wvariadic-macros                                 \
383    -Wvector-operation-performance                    \
384    -Wvexing-parse                                    \
385    -Wvirtual-inheritance                             \
386    -Wvirtual-move-assign                             \
387    -Wvla                                             \
388    -Wvla-parameter                                   \
389    -Wvolatile                                        \
390    -Wvolatile-register-var                           \
391    -Wwrite-strings                                   \
392    -Wzero-as-null-pointer-constant                   \
393    -Wzero-length-bounds                              \
394")
395
396add_custom_target(ci_test_gcc
397    COMMAND CXX=${GCC_TOOL} CXXFLAGS=${GCC_CXXFLAGS} ${CMAKE_COMMAND}
398        -DCMAKE_BUILD_TYPE=Debug -GNinja
399        -DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON
400        -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_gcc
401    COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_gcc
402    COMMAND cd ${PROJECT_BINARY_DIR}/build_gcc && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
403    COMMENT "Compile and test with GCC using maximal warning flags"
404)
405
406add_custom_target(ci_test_clang
407    COMMAND CXX=${CLANG_TOOL} CXXFLAGS=${CLANG_CXXFLAGS} ${CMAKE_COMMAND}
408        -DCMAKE_BUILD_TYPE=Debug -GNinja
409        -DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON
410        -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang
411    COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang
412    COMMAND cd ${PROJECT_BINARY_DIR}/build_clang && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
413    COMMENT "Compile and test with Clang using maximal warning flags"
414)
415
416###############################################################################
417# Different C++ Standards.
418###############################################################################
419
420foreach(CXX_STANDARD 11 14 17 20)
421    add_custom_target(ci_test_gcc_cxx${CXX_STANDARD}
422        COMMAND CXX=${GCC_TOOL} ${CMAKE_COMMAND}
423            -DCMAKE_BUILD_TYPE=Debug -GNinja
424            -DCMAKE_CXX_STANDARD=${CXX_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED=ON
425            -DJSON_BuildTests=ON -DJSON_FastTests=ON
426            -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_gcc_cxx${CXX_STANDARD}
427        COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_gcc_cxx${CXX_STANDARD}
428        COMMAND cd ${PROJECT_BINARY_DIR}/build_gcc_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
429        COMMENT "Compile and test with GCC for C++${CXX_STANDARD}"
430    )
431
432    add_custom_target(ci_test_clang_cxx${CXX_STANDARD}
433        COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
434            -DCMAKE_BUILD_TYPE=Debug -GNinja
435            -DCMAKE_CXX_STANDARD=${CXX_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED=ON
436            -DJSON_BuildTests=ON
437            -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD}
438        COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD}
439        COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
440        COMMENT "Compile and test with Clang for C++${CXX_STANDARD}"
441    )
442endforeach()
443
444###############################################################################
445# Disable exceptions.
446###############################################################################
447
448add_custom_target(ci_test_noexceptions
449    COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
450    -DCMAKE_BUILD_TYPE=Debug -GNinja
451    -DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON -DCMAKE_CXX_FLAGS=-DJSON_NOEXCEPTION -DDOCTEST_TEST_FILTER=--no-throw
452    -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_noexceptions
453    COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_noexceptions
454    COMMAND cd ${PROJECT_BINARY_DIR}/build_noexceptions && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
455    COMMENT "Compile and test with exceptions switched off"
456)
457
458###############################################################################
459# Disable implicit conversions.
460###############################################################################
461
462add_custom_target(ci_test_noimplicitconversions
463    COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
464    -DCMAKE_BUILD_TYPE=Debug -GNinja
465    -DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON -DJSON_ImplicitConversions=OFF
466    -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_noimplicitconversions
467    COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_noimplicitconversions
468    COMMAND cd ${PROJECT_BINARY_DIR}/build_noimplicitconversions && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
469    COMMENT "Compile and test with implicit conversions switched off"
470)
471
472###############################################################################
473# Enable improved diagnostics.
474###############################################################################
475
476add_custom_target(ci_test_diagnostics
477    COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
478    -DCMAKE_BUILD_TYPE=Debug -GNinja
479    -DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON -DJSON_Diagnostics=ON
480    -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_diagnostics
481    COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_diagnostics
482    COMMAND cd ${PROJECT_BINARY_DIR}/build_diagnostics && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
483    COMMENT "Compile and test with improved diagnostics enabled"
484)
485
486###############################################################################
487# Coverage.
488###############################################################################
489
490add_custom_target(ci_test_coverage
491    COMMAND CXX=g++ ${CMAKE_COMMAND}
492        -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_CXX_FLAGS="--coverage;-fprofile-arcs;-ftest-coverage"
493        -DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON
494        -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_coverage
495    COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_coverage
496    COMMAND cd ${PROJECT_BINARY_DIR}/build_coverage && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
497
498    COMMAND ${LCOV_TOOL} --directory . --capture --output-file json.info --rc lcov_branch_coverage=1
499    COMMAND ${LCOV_TOOL} -e json.info ${SRC_FILES} --output-file json.info.filtered --rc lcov_branch_coverage=1
500    COMMAND ${CMAKE_SOURCE_DIR}/test/thirdparty/imapdl/filterbr.py json.info.filtered > json.info.filtered.noexcept
501    COMMAND genhtml --title "JSON for Modern C++" --legend --demangle-cpp --output-directory html --show-details --branch-coverage json.info.filtered.noexcept
502
503    COMMENT "Compile and test with coverage"
504)
505
506###############################################################################
507# Sanitizers.
508###############################################################################
509
510set(CLANG_CXX_FLAGS_SANITIZER "-g -O1 -fsanitize=address -fsanitize=undefined -fsanitize=integer -fsanitize=nullability -fno-omit-frame-pointer -fno-sanitize-recover=all -fno-sanitize=unsigned-integer-overflow -fno-sanitize=unsigned-shift-base")
511
512add_custom_target(ci_test_clang_sanitizer
513    COMMAND CXX=${CLANG_TOOL} CXXFLAGS=${CLANG_CXX_FLAGS_SANITIZER} ${CMAKE_COMMAND}
514        -DCMAKE_BUILD_TYPE=Debug -GNinja
515        -DJSON_BuildTests=ON
516        -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_sanitizer
517    COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_sanitizer
518    COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_sanitizer && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
519    COMMENT "Compile and test with sanitizers"
520)
521
522###############################################################################
523# Check if header is amalgamated and sources are properly indented.
524###############################################################################
525
526set(ASTYLE_FLAGS --style=allman --indent=spaces=4 --indent-modifiers --indent-switches --indent-preproc-block --indent-preproc-define --indent-col1-comments --pad-oper --pad-header --align-pointer=type --align-reference=type --add-brackets --convert-tabs --close-templates --lineend=linux --preserve-date --formatted)
527
528file(GLOB_RECURSE INDENT_FILES
529    ${PROJECT_SOURCE_DIR}/include/nlohmann/*.hpp
530    ${PROJECT_SOURCE_DIR}/test/src/*.cpp
531    ${PROJECT_SOURCE_DIR}/test/src/*.hpp
532    ${PROJECT_SOURCE_DIR}/benchmarks/src/benchmarks.cpp
533    ${PROJECT_SOURCE_DIR}/doc/examples/*.cpp
534)
535
536add_custom_target(ci_test_amalgamation
537    COMMAND rm -fr ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp~
538    COMMAND cp ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp~
539    COMMAND ${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/third_party/amalgamate/amalgamate.py -c ${PROJECT_SOURCE_DIR}/third_party/amalgamate/config.json -s .
540    COMMAND ${ASTYLE_TOOL} ${ASTYLE_FLAGS} --suffix=none --quiet ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp
541    COMMAND diff ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp~ ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp
542
543    COMMAND ${ASTYLE_TOOL} ${ASTYLE_FLAGS} ${INDENT_FILES}
544    COMMAND cd ${PROJECT_SOURCE_DIR} && for FILE in `find . -name '*.orig'`\; do false \; done
545
546    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
547    COMMENT "Check amalagamation and indentation"
548)
549
550###############################################################################
551# Valgrind.
552###############################################################################
553
554add_custom_target(ci_test_valgrind
555    COMMAND CXX=${GCC_TOOL} ${CMAKE_COMMAND}
556        -DCMAKE_BUILD_TYPE=Debug -GNinja
557        -DJSON_BuildTests=ON -DJSON_Valgrind=ON
558        -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_valgrind
559    COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_valgrind
560    COMMAND cd ${PROJECT_BINARY_DIR}/build_valgrind && ${CMAKE_CTEST_COMMAND} -L valgrind --parallel ${N} --output-on-failure
561    COMMENT "Compile and test with Valgrind"
562)
563
564###############################################################################
565# Check code with Clang Static Analyzer.
566###############################################################################
567
568set(CLANG_ANALYZER_CHECKS "fuchsia.HandleChecker,nullability.NullableDereferenced,nullability.NullablePassedToNonnull,nullability.NullableReturnedFromNonnull,optin.cplusplus.UninitializedObject,optin.cplusplus.VirtualCall,optin.mpi.MPI-Checker,optin.osx.OSObjectCStyleCast,optin.osx.cocoa.localizability.EmptyLocalizationContextChecker,optin.osx.cocoa.localizability.NonLocalizedStringChecker,optin.performance.GCDAntipattern,optin.performance.Padding,optin.portability.UnixAPI,security.FloatLoopCounter,security.insecureAPI.DeprecatedOrUnsafeBufferHandling,security.insecureAPI.bcmp,security.insecureAPI.bcopy,security.insecureAPI.bzero,security.insecureAPI.rand,security.insecureAPI.strcpy,valist.CopyToSelf,valist.Uninitialized,valist.Unterminated,webkit.NoUncountedMemberChecker,webkit.RefCntblBaseVirtualDtor,core.CallAndMessage,core.DivideZero,core.NonNullParamChecker,core.NullDereference,core.StackAddressEscape,core.UndefinedBinaryOperatorResult,core.VLASize,core.uninitialized.ArraySubscript,core.uninitialized.Assign,core.uninitialized.Branch,core.uninitialized.CapturedBlockVariable,core.uninitialized.UndefReturn,cplusplus.InnerPointer,cplusplus.Move,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,cplusplus.PlacementNew,cplusplus.PureVirtualCall,deadcode.DeadStores,nullability.NullPassedToNonnull,nullability.NullReturnedFromNonnull,osx.API,osx.MIG,osx.NumberObjectConversion,osx.OSObjectRetainCount,osx.ObjCProperty,osx.SecKeychainAPI,osx.cocoa.AtSync,osx.cocoa.AutoreleaseWrite,osx.cocoa.ClassRelease,osx.cocoa.Dealloc,osx.cocoa.IncompatibleMethodTypes,osx.cocoa.Loops,osx.cocoa.MissingSuperCall,osx.cocoa.NSAutoreleasePool,osx.cocoa.NSError,osx.cocoa.NilArg,osx.cocoa.NonNilReturnValue,osx.cocoa.ObjCGenerics,osx.cocoa.RetainCount,osx.cocoa.RunLoopAutoreleaseLeak,osx.cocoa.SelfInit,osx.cocoa.SuperDealloc,osx.cocoa.UnusedIvars,osx.cocoa.VariadicMethodTypes,osx.coreFoundation.CFError,osx.coreFoundation.CFNumber,osx.coreFoundation.CFRetainRelease,osx.coreFoundation.containers.OutOfBounds,osx.coreFoundation.containers.PointerSizedValues,security.insecureAPI.UncheckedReturn,security.insecureAPI.decodeValueOfObjCType,security.insecureAPI.getpw,security.insecureAPI.gets,security.insecureAPI.mkstemp,security.insecureAPI.mktemp,security.insecureAPI.vfork,unix.API,unix.Malloc,unix.MallocSizeof,unix.MismatchedDeallocator,unix.Vfork,unix.cstring.BadSizeArg,unix.cstring.NullArg")
569
570add_custom_target(ci_clang_analyze
571    COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
572        -DCMAKE_BUILD_TYPE=Debug -GNinja
573        -DJSON_BuildTests=ON
574        -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_analyze
575    COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_analyze && ${SCAN_BUILD_TOOL} -enable-checker ${CLANG_ANALYZER_CHECKS} --use-c++=${CLANG_TOOL} -analyze-headers -o ${PROJECT_BINARY_DIR}/report ninja
576    COMMENT "Check code with Clang Analyzer"
577)
578
579###############################################################################
580# Check code with Cppcheck.
581###############################################################################
582
583add_custom_target(ci_cppcheck
584    COMMAND ${CPPCHECK_TOOL} --enable=warning --suppress=missingReturn --inline-suppr --inconclusive --force --std=c++11 ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp --error-exitcode=1
585    COMMENT "Check code with Cppcheck"
586)
587
588###############################################################################
589# Check code with cpplint.
590###############################################################################
591
592add_custom_target(ci_cpplint
593    COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/third_party/cpplint/cpplint.py --filter=-whitespace,-legal,-runtime/references,-runtime/explicit,-runtime/indentation_namespace,-readability/casting,-readability/nolint --quiet --recursive ${SRC_FILES}
594    COMMENT "Check code with cpplint"
595)
596
597###############################################################################
598# Check code with OCLint.
599###############################################################################
600
601file(COPY ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp DESTINATION ${PROJECT_BINARY_DIR}/src_single)
602file(RENAME ${PROJECT_BINARY_DIR}/src_single/json.hpp ${PROJECT_BINARY_DIR}/src_single/all.cpp)
603file(APPEND "${PROJECT_BINARY_DIR}/src_single/all.cpp" "\n\nint main()\n{}\n")
604
605add_executable(single_all ${PROJECT_BINARY_DIR}/src_single/all.cpp)
606target_compile_features(single_all PRIVATE cxx_std_11)
607
608add_custom_target(ci_oclint
609    COMMAND ${CMAKE_COMMAND}
610        -DCMAKE_BUILD_TYPE=Debug
611        -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
612        -DJSON_BuildTests=OFF -DJSON_CI=ON
613        -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_oclint
614    COMMAND ${OCLINT_TOOL} -i ${PROJECT_BINARY_DIR}/build_oclint/src_single/all.cpp -p ${PROJECT_BINARY_DIR}/build_oclint --
615        -report-type html -enable-global-analysis --max-priority-1=0 --max-priority-2=1000 --max-priority-3=2000
616        --disable-rule=MultipleUnaryOperator
617        --disable-rule=DoubleNegative
618        --disable-rule=ShortVariableName
619        --disable-rule=GotoStatement
620        --disable-rule=LongLine
621        -o ${PROJECT_BINARY_DIR}/build_oclint/oclint_report.html
622    COMMENT "Check code with OCLint"
623)
624
625###############################################################################
626# Check code with Clang-Tidy.
627###############################################################################
628
629add_custom_target(ci_clang_tidy
630    COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
631        -DCMAKE_BUILD_TYPE=Debug -GNinja
632        -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_CLANG_TIDY=${CLANG_TIDY_TOOL}
633        -DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON
634        -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_tidy
635    COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_tidy
636    COMMENT "Check code with Clang-Tidy"
637)
638
639###############################################################################
640# Check code with PVS-Studio Analyzer <https://www.viva64.com/en/pvs-studio/>.
641###############################################################################
642
643add_custom_target(ci_pvs_studio
644    COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
645        -DCMAKE_BUILD_TYPE=Debug
646        -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
647        -DJSON_BuildTests=ON
648        -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_pvs_studio
649    COMMAND cd ${PROJECT_BINARY_DIR}/build_pvs_studio && ${PVS_STUDIO_ANALYZER_TOOL} analyze -j 10
650    COMMAND cd ${PROJECT_BINARY_DIR}/build_pvs_studio && ${PLOG_CONVERTER_TOOL} -a'GA:1,2;64:1;CS' -t fullhtml PVS-Studio.log -o pvs
651    COMMENT "Check code with PVS Studio"
652)
653
654###############################################################################
655# Check code with Infer <https://fbinfer.com> static analyzer.
656###############################################################################
657
658add_custom_target(ci_infer
659    COMMAND mkdir -p ${PROJECT_BINARY_DIR}/build_infer
660    COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} compile -- ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${PROJECT_SOURCE_DIR} -DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON
661    COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} run -- make
662    COMMENT "Check code with Infer"
663)
664
665###############################################################################
666# Run test suite with previously downloaded test data.
667###############################################################################
668
669add_custom_target(ci_offline_testdata
670    COMMAND mkdir -p ${PROJECT_BINARY_DIR}/build_offline_testdata/test_data
671    COMMAND cd ${PROJECT_BINARY_DIR}/build_offline_testdata/test_data && ${GIT_TOOL} clone -c advice.detachedHead=false --branch v3.0.0 https://github.com/nlohmann/json_test_data.git --quiet --depth 1
672    COMMAND ${CMAKE_COMMAND}
673        -DCMAKE_BUILD_TYPE=Debug -GNinja
674        -DJSON_BuildTests=ON -DJSON_FastTests=ON -DJSON_TestDataDirectory=${PROJECT_BINARY_DIR}/build_offline_testdata/test_data/json_test_data
675        -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_offline_testdata
676    COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_offline_testdata
677    COMMAND cd ${PROJECT_BINARY_DIR}/build_offline_testdata && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
678    COMMENT "Check code with previously downloaded test data"
679)
680
681###############################################################################
682# Run test suite when project was not checked out from Git
683###############################################################################
684
685add_custom_target(ci_non_git_tests
686    COMMAND mkdir -p ${PROJECT_BINARY_DIR}/build_non_git_tests/sources
687    COMMAND cd ${PROJECT_SOURCE_DIR} && for FILE in `${GIT_TOOL} ls-tree --name-only HEAD`\; do cp -r $$FILE ${PROJECT_BINARY_DIR}/build_non_git_tests/sources \; done
688    COMMAND ${CMAKE_COMMAND}
689        -DCMAKE_BUILD_TYPE=Debug -GNinja
690        -DJSON_BuildTests=ON -DJSON_FastTests=ON
691        -S${PROJECT_BINARY_DIR}/build_non_git_tests/sources -B${PROJECT_BINARY_DIR}/build_non_git_tests
692    COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_non_git_tests
693    COMMAND cd ${PROJECT_BINARY_DIR}/build_non_git_tests && ${CMAKE_CTEST_COMMAND} --parallel ${N} -LE git_required --output-on-failure
694    COMMENT "Check code when project was not checked out from Git"
695)
696
697###############################################################################
698# Run test suite and exclude tests that change installed files
699###############################################################################
700
701add_custom_target(ci_reproducible_tests
702    COMMAND ${CMAKE_COMMAND}
703        -DCMAKE_BUILD_TYPE=Debug -GNinja
704        -DJSON_BuildTests=ON -DJSON_FastTests=ON
705        -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_reproducible_tests
706    COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_reproducible_tests
707    COMMAND cd ${PROJECT_BINARY_DIR}/build_reproducible_tests && ${CMAKE_CTEST_COMMAND} --parallel ${N} -LE not_reproducible --output-on-failure
708    COMMENT "Check code and exclude tests that change installed files"
709)
710
711###############################################################################
712# Check if every header in the include folder includes sufficient headers to
713# be compiled individually.
714###############################################################################
715
716set(iwyu_path_and_options ${IWYU_TOOL} -Xiwyu --max_line_length=300)
717
718foreach(SRC_FILE ${SRC_FILES})
719    # get relative path of the header file
720    file(RELATIVE_PATH RELATIVE_SRC_FILE "${PROJECT_SOURCE_DIR}/include/nlohmann" "${SRC_FILE}")
721    # replace slashes and strip suffix
722    string(REPLACE "/" "_" RELATIVE_SRC_FILE "${RELATIVE_SRC_FILE}")
723    string(REPLACE ".hpp" "" RELATIVE_SRC_FILE "${RELATIVE_SRC_FILE}")
724    # create code file
725    file(WRITE "${PROJECT_BINARY_DIR}/src_single/${RELATIVE_SRC_FILE}.cpp" "#include \"${SRC_FILE}\" // IWYU pragma: keep\n\nint main()\n{}\n")
726    # create executable
727    add_executable(single_${RELATIVE_SRC_FILE} EXCLUDE_FROM_ALL ${PROJECT_BINARY_DIR}/src_single/${RELATIVE_SRC_FILE}.cpp)
728    target_include_directories(single_${RELATIVE_SRC_FILE} PRIVATE ${PROJECT_SOURCE_DIR}/include)
729    target_compile_features(single_${RELATIVE_SRC_FILE} PRIVATE cxx_std_11)
730    set_property(TARGET single_${RELATIVE_SRC_FILE} PROPERTY CXX_INCLUDE_WHAT_YOU_USE "${iwyu_path_and_options}")
731    # remember binary for ci_single_binaries target
732    list(APPEND single_binaries single_${RELATIVE_SRC_FILE})
733endforeach()
734
735add_custom_target(ci_single_binaries
736    DEPENDS ${single_binaries}
737    COMMENT "Check if headers are self-contained"
738)
739
740###############################################################################
741# Benchmarks
742###############################################################################
743
744add_custom_target(ci_benchmarks
745    COMMAND ${CMAKE_COMMAND}
746        -DCMAKE_BUILD_TYPE=Release -GNinja
747        -S${PROJECT_SOURCE_DIR}/benchmarks -B${PROJECT_BINARY_DIR}/build_benchmarks
748    COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_benchmarks --target json_benchmarks
749    COMMAND cd ${PROJECT_BINARY_DIR}/build_benchmarks && ./json_benchmarks
750    COMMENT "Run benchmarks"
751)
752
753###############################################################################
754# CMake flags
755###############################################################################
756
757if (APPLE)
758    set(CMAKE_310_BINARY ${PROJECT_BINARY_DIR}/cmake-3.1.0-Darwin64/CMake.app/Contents/bin/cmake)
759    add_custom_command(
760        OUTPUT ${CMAKE_310_BINARY}
761        COMMAND wget https://github.com/Kitware/CMake/releases/download/v3.1.0/cmake-3.1.0-Darwin64.tar.gz
762        COMMAND tar xfz cmake-3.1.0-Darwin64.tar.gz
763        COMMAND rm cmake-3.1.0-Darwin64.tar.gz
764        WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
765        COMMENT "Download CMake 3.1.0"
766    )
767else()
768    set(CMAKE_310_BINARY ${PROJECT_BINARY_DIR}/cmake-3.1.0-Linux-x86_64/bin/cmake)
769    add_custom_command(
770        OUTPUT ${CMAKE_310_BINARY}
771        COMMAND wget https://github.com/Kitware/CMake/releases/download/v3.1.0/cmake-3.1.0-Linux-x86_64.tar.gz
772        COMMAND tar xfz cmake-3.1.0-Linux-x86_64.tar.gz
773        COMMAND rm cmake-3.1.0-Linux-x86_64.tar.gz
774        WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
775        COMMENT "Download CMake 3.1.0"
776    )
777endif()
778
779set(JSON_CMAKE_FLAGS "JSON_BuildTests;JSON_Install;JSON_MultipleHeaders;JSON_ImplicitConversions;JSON_Valgrind;JSON_Diagnostics;JSON_SystemInclude")
780
781foreach(JSON_CMAKE_FLAG ${JSON_CMAKE_FLAGS})
782    string(TOLOWER "ci_cmake_flag_${JSON_CMAKE_FLAG}" JSON_CMAKE_FLAG_TARGET)
783    add_custom_target("${JSON_CMAKE_FLAG_TARGET}"
784        COMMENT "Check CMake flag ${JSON_CMAKE_FLAG} (CMake ${CMAKE_VERSION})"
785        COMMAND ${CMAKE_COMMAND}
786            -Werror=dev
787            -D${JSON_CMAKE_FLAG}=ON
788            -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_${JSON_CMAKE_FLAG_TARGET}
789    )
790    add_custom_target("${JSON_CMAKE_FLAG_TARGET}_31"
791        COMMENT "Check CMake flag ${JSON_CMAKE_FLAG} (CMake 3.1)"
792        COMMAND mkdir ${PROJECT_BINARY_DIR}/build_${JSON_CMAKE_FLAG_TARGET}_31
793        COMMAND cd ${PROJECT_BINARY_DIR}/build_${JSON_CMAKE_FLAG_TARGET}_31 && ${CMAKE_310_BINARY}
794            -Werror=dev ${PROJECT_SOURCE_DIR}
795            -D${JSON_CMAKE_FLAG}=ON
796            -DCMAKE_CXX_COMPILE_FEATURES="cxx_range_for" -DCMAKE_CXX_FLAGS="-std=gnu++11"
797        DEPENDS ${CMAKE_310_BINARY}
798    )
799    list(APPEND JSON_CMAKE_FLAG_TARGETS ${JSON_CMAKE_FLAG_TARGET} ${JSON_CMAKE_FLAG_TARGET}_31)
800    list(APPEND JSON_CMAKE_FLAG_BUILD_DIRS ${PROJECT_BINARY_DIR}/build_${JSON_CMAKE_FLAG_TARGET} ${PROJECT_BINARY_DIR}/build_${JSON_CMAKE_FLAG_TARGET}_31)
801endforeach()
802
803add_custom_target(ci_cmake_flags
804    DEPENDS ${JSON_CMAKE_FLAG_TARGETS}
805    COMMENT "Check CMake flags"
806)
807
808###############################################################################
809# Use more installed compilers.
810###############################################################################
811
812foreach(COMPILER g++-4.8 g++-4.9 g++-5 g++-7 g++-8 g++-9 g++-10 clang++-3.5 clang++-3.6 clang++-3.7 clang++-3.8 clang++-3.9 clang++-4.0 clang++-5.0 clang++-6.0 clang++-7 clang++-8 clang++-9 clang++-10 clang++-11)
813    find_program(COMPILER_TOOL NAMES ${COMPILER})
814    if (COMPILER_TOOL)
815        add_custom_target(ci_test_compiler_${COMPILER}
816            COMMAND CXX=${COMPILER} ${CMAKE_COMMAND}
817                -DCMAKE_BUILD_TYPE=Debug -GNinja
818                -DJSON_BuildTests=ON -DJSON_FastTests=ON
819                -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_compiler_${COMPILER}
820            COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_compiler_${COMPILER}
821            COMMAND cd ${PROJECT_BINARY_DIR}/build_compiler_${COMPILER} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --exclude-regex "test-unicode" --output-on-failure
822            COMMENT "Compile and test with ${COMPILER}"
823        )
824    endif()
825    unset(COMPILER_TOOL CACHE)
826endforeach()
827
828###############################################################################
829# Clean up all generated files.
830###############################################################################
831
832add_custom_target(ci_clean
833    COMMAND rm -fr ${PROJECT_BINARY_DIR}/build_* cmake-3.1.0-Darwin64 ${JSON_CMAKE_FLAG_BUILD_DIRS} ${single_binaries}
834    COMMENT "Clean generated directories"
835)
836