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