blob: 766607d8a70c0a8b70ad7cd0ecd636de0d9f125b [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
onqtam99e3bd02016-03-18 14:46:21 +020067 add_compiler_flags(-ggdb) # temp - to see valgrind issues
68
hardlyb1e7e142014-08-06 00:43:51 +030069 add_compiler_flags(-ansi)
70 add_compiler_flags(-Wall)
71 add_compiler_flags(-Wextra)
72 add_compiler_flags(-Wconversion)
73 add_compiler_flags(-Wno-missing-field-initializers)
74 add_compiler_flags(-Wold-style-cast)
75 add_compiler_flags(-Wfloat-equal)
76 add_compiler_flags(-Wlogical-op)
77 add_compiler_flags(-Wundef)
78 add_compiler_flags(-Wredundant-decls)
79 add_compiler_flags(-Wshadow)
80 add_compiler_flags(-Wstrict-overflow=5)
81 add_compiler_flags(-Wwrite-strings)
82 add_compiler_flags(-Wpointer-arith)
83 add_compiler_flags(-Wcast-qual)
84 add_compiler_flags(-Wformat=2)
85 add_compiler_flags(-Wswitch-default)
86 add_compiler_flags(-Wmissing-include-dirs)
87 add_compiler_flags(-Wcast-align)
88 add_compiler_flags(-Wformat-nonliteral)
89 add_compiler_flags(-Wparentheses)
90 add_compiler_flags(-Winit-self)
91 add_compiler_flags(-Wuninitialized)
92 add_compiler_flags(-Wswitch-enum)
93 add_compiler_flags(-Wno-endif-labels)
94 add_compiler_flags(-Wunused-function)
95 add_compiler_flags(-Wnon-virtual-dtor)
96 add_compiler_flags(-Wno-pmf-conversions)
97 add_compiler_flags(-Wctor-dtor-privacy)
98 add_compiler_flags(-Wsign-promo)
99 add_compiler_flags(-Wdisabled-optimization)
100 add_compiler_flags(-Waggregate-return)
101 add_compiler_flags(-Weffc++)
102 add_compiler_flags(-Winline)
103 add_compiler_flags(-Winvalid-pch)
104 add_compiler_flags(-Wstack-protector)
105 add_compiler_flags(-Wunsafe-loop-optimizations)
106 add_compiler_flags(-Wmissing-declarations)
107 add_compiler_flags(-Woverloaded-virtual)
108
109 if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
110 add_compiler_flags(-Wdouble-promotion)
111 add_compiler_flags(-Wtrampolines)
112 add_compiler_flags(-Wzero-as-null-pointer-constant)
113 add_compiler_flags(-Wuseless-cast)
114 add_compiler_flags(-Wvector-operation-performance)
115 add_compiler_flags(-Wsized-deallocation)
116 endif()
117
118 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.3)
119 add_compiler_flags(-Wshift-overflow=2)
120 add_compiler_flags(-Wnull-dereference)
121 add_compiler_flags(-Wduplicated-cond)
onqtam6b7eb052016-03-18 12:43:55 +0200122 add_compiler_flags(-Wmisleading-indentation)
123 add_compiler_flags(-Wshift-negative-value)
hardlyb1e7e142014-08-06 00:43:51 +0300124 endif()
125endif()
126
127if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
128 add_compiler_flags(-Weverything)
129endif()
130
131if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
132 #add_compiler_flags(/WX)
133 add_compiler_flags(/W4) # /Wall is too aggressive - even the standard C headers give thousands of errors...
134endif()