bug fix: Travis-CI compiler version output was wrong
[marnav.git] / CMakeLists.txt
blob0c10186c7ab25d87d1b2e09503f0bf7657e314bb
1 cmake_minimum_required(VERSION 3.0)
2 project(marnav)
4 set(VERSION_MAJOR "0")
5 set(VERSION_MINOR "3")
6 set(VERSION_PATCH "7")
8 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
9 include(ExternalProject)
10 include(ExternGmock)
11 include(GitInformation)
13 set(PROJECT_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${GIT_COMMIT_HASH_SHORT}")
14 if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
15         set(PROJECT_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
16 endif()
18 option(ENABLE_PROFILING "Enable Profiling" OFF)
19 option(ENABLE_WARNING_HELL "Enable Warning Hell" OFF)
21 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
22         message(STATUS "Compiler settings for GNU")
24         if(ENABLE_PROFILING)
25                 set(CXX_PROFILE_FLAGS "-pg")
26         endif()
28         set(GNU_CXX_WARNING_FLAGS "-Wall -Wextra -pedantic-errors")
29         if(ENABLE_WARNING_HELL)
30                 message(STATUS "Behold: entering the hell of extended warnings")
32                 # some are not enabled on purpose
33                 #set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Weffc++")
34                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wcast-align")
35                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wcast-qual")
36                 #set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wconversion")
37                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Werror")
38                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wdisabled-optimization")
39                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wfloat-equal")
40                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wformat=2")
41                 #set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wformat-nonliteral")
42                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wformat-security")
43                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wformat-y2k")
44                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wimport")
45                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Winit-self")
46                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Winline")
47                 #set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wlong-long")
48                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wmissing-field-initializers")
49                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wmissing-format-attribute")
50                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wmissing-include-dirs")
51                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wmissing-noreturn")
52                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wold-style-cast")
53                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Woverloaded-virtual")
54                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wpacked")
55                 #set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wpadded")
56                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wpointer-arith")
57                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wredundant-decls")
58                 #set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wshadow")
59                 #set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wstack-protector")
60                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wstrict-aliasing=2")
61                 #set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wswitch-enum")
62                 #set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wswitch-default")
63                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wunreachable-code")
64                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wunused")
65                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wunused-parameter")
66                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wvariadic-macros")
67                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wwrite-strings")
69                 # explicitly disabled on purpose
70                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wno-unused-function")
71                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wno-comment")
72                 set(GNU_CXX_WARNING_FLAGS "${GNU_CXX_WARNING_FLAGS} -Wno-format-nonliteral")
73         endif()
75         set(CMAKE_CXX_FLAGS          "${CMAKE_CXX_FLAGS}         ${CXX_PROFILE_FLAGS} -std=c++11 ${GNU_CXX_WARNING_FLAGS} -pipe -O0 -ggdb")
76         set(CMAKE_CXX_FLAGS_DEBUG    "${CMAKE_CXX_FLAGS_DEBUG}   ${CXX_PROFILE_FLAGS} -std=c++11 ${GNU_CXX_WARNING_FLAGS} -pipe -O0 -ggdb")
77         set(CMAKE_CXX_FLAGS_RELEASE  "${CMAKE_CXX_FLAGS_RELEASE} ${CXX_PROFILE_FLAGS} -std=c++11 ${GNU_CXX_WARNING_FLAGS} -pipe -O3 -ggdb")
78         set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG}   ${CXX_PROFILE_FLAGS} --coverage -fprofile-arcs -ftest-coverage -fno-inline -fno-inline-small-functions -fno-default-inline")
79 elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
80         message(STATUS "Compiler settings for Clang")
81         set(CMAKE_CXX_FLAGS          "${CMAKE_CXX_FLAGS}         -std=c++11 -Wall -Wextra -O0 -g")
82         set(CMAKE_CXX_FLAGS_DEBUG    "${CMAKE_CXX_FLAGS_DEBUG}   -std=c++11 -Wall -Wextra -O0 -g")
83         set(CMAKE_CXX_FLAGS_RELEASE  "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11 -Wall -Wextra -O4 -g")
84         set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG}   --coverage -fprofile-arcs -ftest-coverage -fno-inline -fno-inline-small-functions -fno-default-inline")
85 else()
86         message(STATUS "Compiler settings for <unknown>")
87 endif()
89 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
91 ### common
92 file(MAKE_DIRECTORY
93         ${CMAKE_CURRENT_BINARY_DIR}/doc
94         ${CMAKE_CURRENT_BINARY_DIR}/doc/coverage
95         ${CMAKE_CURRENT_BINARY_DIR}/local/include
96         )
98 ### library
99 include_directories(src)
100 include_directories(${CMAKE_CURRENT_BINARY_DIR}/src)
101 add_subdirectory(src)
103 ### examples
104 add_subdirectory(examples)
106 ### ctags / cscope
107 find_program(CTAGS_PATH ctags)
108 find_program(CSCOPE_PATH cscope)
109 if(CTAGS_PATH AND CSCOPE_PATH)
110         message(STATUS "Found ctags: ${CTAGS_PATH}")
111         message(STATUS "Found cscope: ${CSCOPE_PATH}")
113         set_source_files_properties(cscope.files PROPERTIES GENERATED true)
114         set_source_files_properties(cscope.out PROPERTIES GENERATED true)
115         set_source_files_properties(tags PROPERTIES GENERATED true)
117         file(GLOB_RECURSE SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.?pp")
118         string(REPLACE ";" "\n" SOURCE_FILES "${SOURCE_FILES}")
119         file(WRITE "${CMAKE_BINARY_DIR}/cscope.files.in" "${SOURCE_FILES}")
120         configure_file("${CMAKE_BINARY_DIR}/cscope.files.in" "${CMAKE_BINARY_DIR}/cscope.files" COPYONLY)
122         add_custom_target(tags
123                 COMMAND ${CTAGS_PATH} --c++-kinds=+p --fields=+iaS --extra=+q -L ${CMAKE_BINARY_DIR}/cscope.files
124                 COMMAND ${CSCOPE_PATH} -b
125                 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
126                 )
127 endif()
129 ### documentation
130 find_package(Doxygen)
131 if(DOXYGEN_FOUND)
132         configure_file(
133                 ${CMAKE_CURRENT_SOURCE_DIR}/doc/main.dox.in
134                 ${CMAKE_CURRENT_BINARY_DIR}/doc/main.dox
135                 )
136         configure_file(
137                 ${CMAKE_CURRENT_SOURCE_DIR}/doxygen.conf.in
138                 ${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf
139                 )
140         add_custom_target(doc
141                 COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf
142                 )
143         add_dependencies(doc tags)
144 endif()
146 ### cppcheck
147 find_program(CPPCHECK_PATH cppcheck)
148 if(CPPCHECK_PATH)
149         message(STATUS "cppcheck found: ${CPPCHECK_PATH}")
150         add_custom_target(cppcheck
151                 COMMAND ${CPPCHECK_PATH} --suppressions-list=${CMAKE_CURRENT_SOURCE_DIR}/cppcheck-suppress.txt --std=c++11 --platform=unix32 -v -f --enable=all --template='{file}:{line},{severity},{id},{message}' -I ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/test 2> ${CMAKE_CURRENT_BINARY_DIR}/doc/cppcheck.txt
152                 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
153         )
154 else()
155         message(STATUS "cppcheck not found, target not available.")
156 endif()
158 ### testing common stuff
159 enable_testing()
161 ### unit tests
162 add_custom_target(unittest)
163 macro(run_unittest unittest_target)
164         add_custom_target(${unittest_target}_runtest
165                 COMMAND ${unittest_target}
166                 DEPENDS ${unittest_target}
167                 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
168                 )
169         add_dependencies(unittest ${unittest_target}_runtest)
170 endmacro()
172 add_subdirectory(test)
174 ### coverage
175 if (CMAKE_BUILD_TYPE STREQUAL "Coverage")
176         include(CodeCoverage)
177         setup_target_for_coverage(coverage
178                 testrunner
179                 doc/coverage
180                 )
181 endif()
184 ### package
185 set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
186 set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
187 set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
188 set(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
189 set(CPACK_PACKAGE_NAME "marnav")
190 set(CPACK_PACKAGE_VENDOR "Mario Konrad")
191 set(CPACK_PACKAGE_CONTACT "Mario Konrad <mario.konrad@gmx.net>")
192 set(CPACK_PACAKGE_DESCRIPTION "Library for maritime navigation.")
193 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Library")
194 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
195 set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
196 set(CPACK_MONOLITHIC_INSTALL 1)
197 #set(CPACK_PACKAGE_EXECUTABLES "??" "??")
198 set(CPACK_STRIP_FILES true)
200 # package: debian
201 set(CPACK_DEBIAN_PACKAGE_NAME ${CPACK_DEBIAN_PACKAGE_NAME})
202 set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
203 set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACAKGE_DESCRIPTION})
204 set(CPACK_DEBIAN_PACKAGE_DEPENDS "libstdc++6 (>= 4.8)")
205 set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.3)")
206 set(CPACK_DEBIAN_PACKAGE_SECTION "misc")
207 if (CMAKE_SIZEOF_VOID_P MATCHES "8")
208         set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
209 else()
210         set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386")
211 endif()
213 include(CPack)