blob: 6b5074d47bf09ac06e7934cb597f5be69bfba176 [file] [log] [blame]
hardlyb1e7e142014-08-06 00:43:51 +03001if(warnings_included)
2 return()
3endif()
4set(warnings_included true)
5
onqtam4cdf5d82016-03-15 16:25:19 +02006# cache this for use inside of the function
7set(CURRENT_LIST_DIR_CACHED ${CMAKE_CURRENT_LIST_DIR})
8
onqtam222ecad2016-03-15 11:54:37 +02009enable_testing()
10
11set(TEST_MODE "NORMAL" CACHE STRING "Test mode - normal/run through valgrind/collect output/compare with output")
12set_property(CACHE TEST_MODE PROPERTY STRINGS "NORMAL;VALGRIND;COLLECT;COMPARE")
13
14# add a customized overloaded version of add_test() to suite my needs
15function(add_test)
16 cmake_parse_arguments(ARG "NO_VALGRIND;NO_OUTPUT" "NAME" "COMMAND" ${ARGN})
17 if(NOT "${ARG_UNPARSED_ARGUMENTS}" STREQUAL "" OR "${ARG_NAME}" STREQUAL "" OR "${ARG_COMMAND}" STREQUAL "")
18 message(FATAL_ERROR "add_test() called with wrong options!")
19 endif()
20
21 set(the_test_mode NORMAL)
22
23 # construct the command that will be called by the exec_test.cmake script
24 set(the_command "")
25 if(${TEST_MODE} STREQUAL "VALGRIND" AND NOT ARG_NO_VALGRIND)
26 set(the_test_mode VALGRIND)
27 set(the_command "valgrind -v --leak-check=full --track-origins=yes --error-exitcode=1")
28 endif()
29 foreach(cur ${ARG_COMMAND})
30 set(the_command "${the_command} ${cur}")
31 endforeach()
32 string(STRIP ${the_command} the_command)
33
onqtam222ecad2016-03-15 11:54:37 +020034 if(${TEST_MODE} STREQUAL "COLLECT" OR ${TEST_MODE} STREQUAL "COMPARE")
35 if(NOT ARG_NO_OUTPUT)
36 file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test_output/)
37 set(the_test_mode ${TEST_MODE})
onqtam4cdf5d82016-03-15 16:25:19 +020038 list(APPEND ADDITIONAL_FLAGS -DTEST_OUTPUT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/test_output/${ARG_NAME}.txt)
39 list(APPEND ADDITIONAL_FLAGS -DTEST_TEMP_FILE=${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/temp_test_output.txt)
onqtam222ecad2016-03-15 11:54:37 +020040 endif()
41 endif()
42
43 list(APPEND ADDITIONAL_FLAGS -DTEST_MODE=${the_test_mode})
44
onqtam4cdf5d82016-03-15 16:25:19 +020045 _add_test(NAME ${ARG_NAME} COMMAND ${CMAKE_COMMAND} -DCOMMAND=${the_command} ${ADDITIONAL_FLAGS} -P ${CURRENT_LIST_DIR_CACHED}/exec_test.cmake)
onqtam222ecad2016-03-15 11:54:37 +020046endfunction()
47
hardlyb1e7e142014-08-06 00:43:51 +030048macro(add_compiler_flags)
49 foreach(flag ${ARGV})
50 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
51 endforeach()
52endmacro()
53
54if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
55 #add_compiler_flags(-Werror)
56 add_compiler_flags(-std=c++98)
57 add_compiler_flags(-pedantic)
58 add_compiler_flags(-pedantic-errors)
59 add_compiler_flags(-fvisibility=hidden)
60 add_compiler_flags(-fstrict-aliasing)
61endif()
62
63if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
64 #add_compiler_flags(-fstack-protector-all)
65 #add_compiler_flags(-funsafe-loop-optimizations)
onqtamf921d3f2016-03-18 11:34:18 +020066
hardlyb1e7e142014-08-06 00:43:51 +030067 add_compiler_flags(-ansi)
68 add_compiler_flags(-Wall)
69 add_compiler_flags(-Wextra)
70 add_compiler_flags(-Wconversion)
71 add_compiler_flags(-Wno-missing-field-initializers)
72 add_compiler_flags(-Wold-style-cast)
73 add_compiler_flags(-Wfloat-equal)
74 add_compiler_flags(-Wlogical-op)
75 add_compiler_flags(-Wundef)
76 add_compiler_flags(-Wredundant-decls)
77 add_compiler_flags(-Wshadow)
78 add_compiler_flags(-Wstrict-overflow=5)
79 add_compiler_flags(-Wwrite-strings)
80 add_compiler_flags(-Wpointer-arith)
81 add_compiler_flags(-Wcast-qual)
82 add_compiler_flags(-Wformat=2)
83 add_compiler_flags(-Wswitch-default)
84 add_compiler_flags(-Wmissing-include-dirs)
85 add_compiler_flags(-Wcast-align)
86 add_compiler_flags(-Wformat-nonliteral)
87 add_compiler_flags(-Wparentheses)
88 add_compiler_flags(-Winit-self)
89 add_compiler_flags(-Wuninitialized)
90 add_compiler_flags(-Wswitch-enum)
91 add_compiler_flags(-Wno-endif-labels)
92 add_compiler_flags(-Wunused-function)
93 add_compiler_flags(-Wnon-virtual-dtor)
94 add_compiler_flags(-Wno-pmf-conversions)
95 add_compiler_flags(-Wctor-dtor-privacy)
96 add_compiler_flags(-Wsign-promo)
97 add_compiler_flags(-Wdisabled-optimization)
98 add_compiler_flags(-Waggregate-return)
99 add_compiler_flags(-Weffc++)
100 add_compiler_flags(-Winline)
101 add_compiler_flags(-Winvalid-pch)
102 add_compiler_flags(-Wstack-protector)
103 add_compiler_flags(-Wunsafe-loop-optimizations)
104 add_compiler_flags(-Wmissing-declarations)
105 add_compiler_flags(-Woverloaded-virtual)
106
107 if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
108 add_compiler_flags(-Wdouble-promotion)
109 add_compiler_flags(-Wtrampolines)
110 add_compiler_flags(-Wzero-as-null-pointer-constant)
111 add_compiler_flags(-Wuseless-cast)
112 add_compiler_flags(-Wvector-operation-performance)
113 add_compiler_flags(-Wsized-deallocation)
114 endif()
115
116 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.3)
117 add_compiler_flags(-Wshift-overflow=2)
118 add_compiler_flags(-Wnull-dereference)
119 add_compiler_flags(-Wduplicated-cond)
onqtam6b7eb052016-03-18 12:43:55 +0200120 add_compiler_flags(-Wmisleading-indentation)
121 add_compiler_flags(-Wshift-negative-value)
hardlyb1e7e142014-08-06 00:43:51 +0300122 endif()
123endif()
124
125if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
126 add_compiler_flags(-Weverything)
127endif()
128
129if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
130 #add_compiler_flags(/WX)
131 add_compiler_flags(/W4) # /Wall is too aggressive - even the standard C headers give thousands of errors...
132endif()