Version 0.6.1
[marnav.git] / CMakeLists.txt
blob2ae8bf78dfac63ee3e6a485cda5d606b91ef0383
1 cmake_minimum_required(VERSION 3.2)
3 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
4 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5 include(GitInformation)
7 project(marnav VERSION 0.6.1 LANGUAGES CXX C)
9 ### compiler check
10 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
11         message(STATUS "Compiler: GNU")
12 elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
13         message(STATUS "Compiler: Clang")
14 else()
15         message(FATAL_ERROR "Unsupported compiler detected: ${CMAKE_CXX_COMPILER_ID}")
16 endif()
18 set(CMAKE_CXX_STANDARD 11)
19 set(CMAKE_CXX_STANDARD_REQUIRED ON)
20 set(CMAKE_CXX_EXTENSIONS OFF)
22 git_commit_hash(GIT_COMMIT_HASH GIT_COMMIT_HASH_SHORT)
23 git_branch_name(GIT_BRANCH)
25 message(STATUS "git branch: ${GIT_BRANCH}")
26 message(STATUS "git commit hash: ${GIT_COMMIT_HASH}")
28 ### version handling
29 if(NOT ("${CMAKE_BUILD_TYPE}" MATCHES "Release"))
30         set(PROJECT_VERSION "${PROJECT_VERSION}-${GIT_COMMIT_HASH_SHORT}")
31 endif()
32 message(STATUS "Project Vesion: ${PROJECT_VERSION}")
34 ### external projects
35 include(ExternalProject)
36 include(ExternGmock)
37 include(ExternBenchmark)
39 ### options
40 option(ENABLE_PROFILING "Enable Profiling" OFF)
41 option(ENABLE_BENCHMARK "Enable Benchmark" OFF)
42 option(ENABLE_WARNING_HELL "Enable Warning Hell" OFF)
43 option(ENABLE_SANITIZER "Enable Sanitizing (address, undefined)" OFF)
44 option(ENABLE_AIS "Enable AIS support" ON)
45 option(ENABLE_SEATALK "Enable SeaTalk support" ON)
46 option(ENABLE_IO "Enable IO support" ON)
48 ### common
49 message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
50 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
51 file(MAKE_DIRECTORY
52         ${CMAKE_CURRENT_BINARY_DIR}/doc
53         ${CMAKE_CURRENT_BINARY_DIR}/doc/coverage
54         ${CMAKE_CURRENT_BINARY_DIR}/local/include
55         )
56 string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower)
58 ### library
59 add_subdirectory(src)
61 ### examples
62 add_subdirectory(examples)
64 ### ctags / cscope
65 include(CTags)
66 if(CTAGS_PATH AND CSCOPE_PATH)
67         setup_ctags_target("${CMAKE_CURRENT_SOURCE_DIR}/src/*.?pp")
68 endif()
70 ### documentation
71 find_package(Doxygen)
72 if(DOXYGEN_FOUND)
73         git_authors(GIT_AUTHORS AUTHOR_LIST)
74         configure_file(
75                 ${CMAKE_CURRENT_SOURCE_DIR}/doc/main.dox.in
76                 ${CMAKE_CURRENT_BINARY_DIR}/doc/main.dox
77                 )
78         configure_file(
79                 ${CMAKE_CURRENT_SOURCE_DIR}/doxygen.conf.in
80                 ${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf
81                 )
82         add_custom_target(doc
83                 COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf
84                 )
85         add_dependencies(doc tags)
86 endif()
88 ### cppcheck
89 find_program(CPPCHECK_PATH cppcheck)
90 if(CPPCHECK_PATH)
91         message(STATUS "cppcheck found: ${CPPCHECK_PATH}")
92         add_custom_target(cppcheck
93                 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
94                 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
95         )
96 else()
97         message(STATUS "cppcheck not found, target not available.")
98 endif()
100 ### testing common stuff
101 enable_testing()
103 ### unit tests, assumes gtest (because of the program argument)
104 add_custom_target(unittest)
105 macro(run_unittest unittest_target)
106         add_custom_target(${unittest_target}_runtest
107                 COMMAND ${unittest_target} --gtest_shuffle
108                 DEPENDS ${unittest_target}
109                 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
110                 )
111         add_dependencies(unittest ${unittest_target}_runtest)
112 endmacro()
114 add_subdirectory(test)
116 ### coverage
117 if(build_type_lower MATCHES coverage)
118         include(CodeCoverage)
119         setup_target_for_coverage(coverage
120                 testrunner
121                 doc/coverage
122                 )
123 endif()
126 ### package
127 set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
128 set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
129 set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
130 set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
131 set(CPACK_PACKAGE_NAME "marnav")
132 set(CPACK_PACKAGE_VENDOR "Mario Konrad")
133 set(CPACK_PACKAGE_CONTACT "Mario Konrad <mario.konrad@gmx.net>")
134 set(CPACK_PACAKGE_DESCRIPTION "Library for maritime navigation.")
135 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Library")
136 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
137 set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
138 set(CPACK_MONOLITHIC_INSTALL 1)
139 #set(CPACK_PACKAGE_EXECUTABLES "??" "??")
140 set(CPACK_STRIP_FILES true)
142 # package: debian
143 set(CPACK_DEBIAN_PACKAGE_NAME ${CPACK_DEBIAN_PACKAGE_NAME})
144 set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
145 set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACAKGE_DESCRIPTION})
146 set(CPACK_DEBIAN_PACKAGE_DEPENDS "libstdc++6 (>= 4.8)")
147 set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.3)")
148 set(CPACK_DEBIAN_PACKAGE_SECTION "misc")
149 if (CMAKE_SIZEOF_VOID_P MATCHES "8")
150         set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
151 else()
152         set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386")
153 endif()
155 include(CPack)