onqtam | fa11399 | 2016-03-18 18:41:25 +0200 | [diff] [blame] | 1 | if(common_included)
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 2 | return()
|
| 3 | endif()
|
onqtam | fa11399 | 2016-03-18 18:41:25 +0200 | [diff] [blame] | 4 | set(common_included true)
|
| 5 |
|
| 6 | include(CMakeParseArguments)
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 7 |
|
onqtam | 4cdf5d8 | 2016-03-15 16:25:19 +0200 | [diff] [blame] | 8 | # cache this for use inside of the function
|
| 9 | set(CURRENT_LIST_DIR_CACHED ${CMAKE_CURRENT_LIST_DIR})
|
| 10 |
|
onqtam | 222ecad | 2016-03-15 11:54:37 +0200 | [diff] [blame] | 11 | enable_testing()
|
| 12 |
|
| 13 | set(TEST_MODE "NORMAL" CACHE STRING "Test mode - normal/run through valgrind/collect output/compare with output")
|
| 14 | set_property(CACHE TEST_MODE PROPERTY STRINGS "NORMAL;VALGRIND;COLLECT;COMPARE")
|
| 15 |
|
| 16 | # add a customized overloaded version of add_test() to suite my needs
|
| 17 | function(add_test)
|
onqtam | 8ccce3b | 2016-04-20 20:46:05 +0300 | [diff] [blame] | 18 | cmake_parse_arguments(ARG "NO_VALGRIND;NO_OUTPUT" "NAME" "COMMAND" ${ARGN})
|
onqtam | 222ecad | 2016-03-15 11:54:37 +0200 | [diff] [blame] | 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()
|
onqtam | aa605c1 | 2016-04-21 16:34:04 +0300 | [diff] [blame] | 34 | # append the argument for removing paths from filenames in the output so tests give the same output everywhere
|
| 35 | set(the_command "${the_command} -dt-no-path-in-filenames=1")
|
| 36 |
|
onqtam | 222ecad | 2016-03-15 11:54:37 +0200 | [diff] [blame] | 37 | string(STRIP ${the_command} the_command)
|
| 38 |
|
onqtam | 222ecad | 2016-03-15 11:54:37 +0200 | [diff] [blame] | 39 | if(${TEST_MODE} STREQUAL "COLLECT" OR ${TEST_MODE} STREQUAL "COMPARE")
|
| 40 | if(NOT ARG_NO_OUTPUT)
|
| 41 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test_output/)
|
| 42 | set(the_test_mode ${TEST_MODE})
|
onqtam | 4cdf5d8 | 2016-03-15 16:25:19 +0200 | [diff] [blame] | 43 | list(APPEND ADDITIONAL_FLAGS -DTEST_OUTPUT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/test_output/${ARG_NAME}.txt)
|
| 44 | list(APPEND ADDITIONAL_FLAGS -DTEST_TEMP_FILE=${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/temp_test_output.txt)
|
onqtam | 222ecad | 2016-03-15 11:54:37 +0200 | [diff] [blame] | 45 | endif()
|
| 46 | endif()
|
| 47 |
|
| 48 | list(APPEND ADDITIONAL_FLAGS -DTEST_MODE=${the_test_mode})
|
| 49 |
|
onqtam | 4cdf5d8 | 2016-03-15 16:25:19 +0200 | [diff] [blame] | 50 | _add_test(NAME ${ARG_NAME} COMMAND ${CMAKE_COMMAND} -DCOMMAND=${the_command} ${ADDITIONAL_FLAGS} -P ${CURRENT_LIST_DIR_CACHED}/exec_test.cmake)
|
onqtam | 222ecad | 2016-03-15 11:54:37 +0200 | [diff] [blame] | 51 | endfunction()
|
| 52 |
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 53 | macro(add_compiler_flags)
|
| 54 | foreach(flag ${ARGV})
|
| 55 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
|
| 56 | endforeach()
|
| 57 | endmacro()
|
| 58 |
|
| 59 | if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
onqtam | f3a680f | 2016-04-30 03:15:07 +0300 | [diff] [blame] | 60 | add_compiler_flags(-Werror)
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 61 | add_compiler_flags(-std=c++98)
|
| 62 | add_compiler_flags(-pedantic)
|
| 63 | add_compiler_flags(-pedantic-errors)
|
| 64 | add_compiler_flags(-fvisibility=hidden)
|
| 65 | add_compiler_flags(-fstrict-aliasing)
|
| 66 | endif()
|
| 67 |
|
| 68 | if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
onqtam | 1c7321d | 2016-03-19 17:31:51 +0200 | [diff] [blame] | 69 | add_compiler_flags(-fstack-protector-all)
|
| 70 | add_compiler_flags(-funsafe-loop-optimizations)
|
| 71 | add_compiler_flags(-fdiagnostics-show-option)
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 72 | add_compiler_flags(-ansi)
|
| 73 | add_compiler_flags(-Wall)
|
| 74 | add_compiler_flags(-Wextra)
|
| 75 | add_compiler_flags(-Wconversion)
|
| 76 | add_compiler_flags(-Wno-missing-field-initializers)
|
| 77 | add_compiler_flags(-Wold-style-cast)
|
| 78 | add_compiler_flags(-Wfloat-equal)
|
| 79 | add_compiler_flags(-Wlogical-op)
|
| 80 | add_compiler_flags(-Wundef)
|
| 81 | add_compiler_flags(-Wredundant-decls)
|
| 82 | add_compiler_flags(-Wshadow)
|
| 83 | add_compiler_flags(-Wstrict-overflow=5)
|
| 84 | add_compiler_flags(-Wwrite-strings)
|
| 85 | add_compiler_flags(-Wpointer-arith)
|
| 86 | add_compiler_flags(-Wcast-qual)
|
| 87 | add_compiler_flags(-Wformat=2)
|
| 88 | add_compiler_flags(-Wswitch-default)
|
| 89 | add_compiler_flags(-Wmissing-include-dirs)
|
| 90 | add_compiler_flags(-Wcast-align)
|
| 91 | add_compiler_flags(-Wformat-nonliteral)
|
| 92 | add_compiler_flags(-Wparentheses)
|
| 93 | add_compiler_flags(-Winit-self)
|
| 94 | add_compiler_flags(-Wuninitialized)
|
| 95 | add_compiler_flags(-Wswitch-enum)
|
| 96 | add_compiler_flags(-Wno-endif-labels)
|
| 97 | add_compiler_flags(-Wunused-function)
|
| 98 | add_compiler_flags(-Wnon-virtual-dtor)
|
| 99 | add_compiler_flags(-Wno-pmf-conversions)
|
| 100 | add_compiler_flags(-Wctor-dtor-privacy)
|
| 101 | add_compiler_flags(-Wsign-promo)
|
onqtam | 1cda096 | 2016-04-19 17:40:43 +0300 | [diff] [blame] | 102 | add_compiler_flags(-Wsign-conversion)
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 103 | add_compiler_flags(-Wdisabled-optimization)
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 104 | add_compiler_flags(-Weffc++)
|
| 105 | add_compiler_flags(-Winline)
|
| 106 | add_compiler_flags(-Winvalid-pch)
|
| 107 | add_compiler_flags(-Wstack-protector)
|
| 108 | add_compiler_flags(-Wunsafe-loop-optimizations)
|
| 109 | add_compiler_flags(-Wmissing-declarations)
|
| 110 | add_compiler_flags(-Woverloaded-virtual)
|
onqtam | 1cda096 | 2016-04-19 17:40:43 +0300 | [diff] [blame] | 111 | add_compiler_flags(-Wstrict-null-sentinel)
|
onqtam | 336f95e | 2016-04-20 00:31:51 +0300 | [diff] [blame] | 112 | if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6)
|
| 113 | add_compiler_flags(-Wnoexcept)
|
| 114 | endif()
|
onqtam | fe5482f | 2016-04-30 03:24:20 +0300 | [diff] [blame] | 115 | #add_compiler_flags(-Waggregate-return) # GCC 4.8 does not silence this even with "#pragma GCC diagnostic ignored"
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 116 |
|
| 117 | if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
|
| 118 | add_compiler_flags(-Wdouble-promotion)
|
| 119 | add_compiler_flags(-Wtrampolines)
|
| 120 | add_compiler_flags(-Wzero-as-null-pointer-constant)
|
| 121 | add_compiler_flags(-Wuseless-cast)
|
| 122 | add_compiler_flags(-Wvector-operation-performance)
|
| 123 | add_compiler_flags(-Wsized-deallocation)
|
| 124 | endif()
|
| 125 |
|
| 126 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.3)
|
| 127 | add_compiler_flags(-Wshift-overflow=2)
|
| 128 | add_compiler_flags(-Wnull-dereference)
|
| 129 | add_compiler_flags(-Wduplicated-cond)
|
onqtam | 6b7eb05 | 2016-03-18 12:43:55 +0200 | [diff] [blame] | 130 | add_compiler_flags(-Wmisleading-indentation)
|
| 131 | add_compiler_flags(-Wshift-negative-value)
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 132 | endif()
|
| 133 | endif()
|
| 134 |
|
| 135 | if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
| 136 | add_compiler_flags(-Weverything)
|
| 137 | endif()
|
| 138 |
|
| 139 | if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
onqtam | f3a680f | 2016-04-30 03:15:07 +0300 | [diff] [blame] | 140 | add_compiler_flags(/WX)
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 141 | add_compiler_flags(/W4) # /Wall is too aggressive - even the standard C headers give thousands of errors...
|
| 142 | endif()
|