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