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)
|
| 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 |
|
onqtam | 222ecad | 2016-03-15 11:54:37 +0200 | [diff] [blame] | 36 | 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})
|
onqtam | 4cdf5d8 | 2016-03-15 16:25:19 +0200 | [diff] [blame] | 40 | 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)
|
onqtam | 222ecad | 2016-03-15 11:54:37 +0200 | [diff] [blame] | 42 | endif()
|
| 43 | endif()
|
| 44 |
|
| 45 | list(APPEND ADDITIONAL_FLAGS -DTEST_MODE=${the_test_mode})
|
| 46 |
|
onqtam | 4cdf5d8 | 2016-03-15 16:25:19 +0200 | [diff] [blame] | 47 | _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] | 48 | endfunction()
|
| 49 |
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 50 | macro(add_compiler_flags)
|
| 51 | foreach(flag ${ARGV})
|
| 52 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
|
| 53 | endforeach()
|
| 54 | endmacro()
|
| 55 |
|
| 56 | if(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)
|
| 63 | endif()
|
| 64 |
|
| 65 | if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
| 66 | #add_compiler_flags(-fstack-protector-all)
|
| 67 | #add_compiler_flags(-funsafe-loop-optimizations)
|
onqtam | f921d3f | 2016-03-18 11:34:18 +0200 | [diff] [blame] | 68 |
|
onqtam | 99e3bd0 | 2016-03-18 14:46:21 +0200 | [diff] [blame] | 69 | add_compiler_flags(-ggdb) # temp - to see valgrind issues
|
| 70 |
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 71 | 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)
|
onqtam | 6b7eb05 | 2016-03-18 12:43:55 +0200 | [diff] [blame] | 124 | add_compiler_flags(-Wmisleading-indentation)
|
| 125 | add_compiler_flags(-Wshift-negative-value)
|
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 126 | endif()
|
| 127 | endif()
|
| 128 |
|
| 129 | if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
| 130 | add_compiler_flags(-Weverything)
|
| 131 | endif()
|
| 132 |
|
| 133 | if(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...
|
| 136 | endif()
|