Version 0.8.1
[marnav.git] / CMakeLists.txt
blob4df639c440d24fa1118d9d45e482420b74741306
1 cmake_minimum_required(VERSION 3.11)
3 set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
4 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
6 project(marnav VERSION 0.8.1 LANGUAGES CXX C)
8 ### compiler check
9 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
10         message(STATUS "Compiler: GNU")
11 elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
12         message(STATUS "Compiler: Clang")
13 else()
14         message(FATAL_ERROR "Unsupported compiler detected: ${CMAKE_CXX_COMPILER_ID}")
15 endif()
17 # C++11, no compiler extensions
18 set(CMAKE_CXX_STANDARD 11)
19 set(CMAKE_CXX_STANDARD_REQUIRED ON)
20 set(CMAKE_CXX_EXTENSIONS OFF)
22 ### check for repository
23 include(GitInformation)
24 if(GIT_FOUND)
25         git_check_repository(GIT_REPO_FOUND)
26         if(GIT_REPO_FOUND)
27                 git_commit_hash(GIT_COMMIT_HASH GIT_COMMIT_HASH_SHORT)
28                 git_branch_name(GIT_BRANCH)
29                 message(STATUS "git branch: ${GIT_BRANCH}")
30                 message(STATUS "git commit hash: ${GIT_COMMIT_HASH}")
32                 # version handling if repository information is available
33                 if(NOT ("${CMAKE_BUILD_TYPE}" MATCHES "Release"))
34                         set(PROJECT_VERSION "${PROJECT_VERSION}-${GIT_COMMIT_HASH_SHORT}")
35                 endif()
36         else()
37                 message(STATUS "no git repository found, no further version info available")
38         endif()
39 else()
40         message(STATUS "git not found, no further version info available")
41 endif()
43 message(STATUS "Project Vesion: ${PROJECT_VERSION}")
45 ### external projects
46 include(ExternalProject)
48 ### options
49 option(ENABLE_PROFILING "Enable Profiling" OFF)
50 option(ENABLE_BENCHMARK "Enable Benchmark" OFF)
51 option(ENABLE_WARNING_HELL "Enable Warning Hell" OFF)
52 option(ENABLE_SANITIZER "Enable Sanitizing (address, undefined)" OFF)
53 option(ENABLE_AIS "Enable AIS support" ON)
54 option(ENABLE_SEATALK "Enable SeaTalk support" ON)
55 option(ENABLE_IO "Enable IO support" ON)
56 option(ENABLE_EXAMPLES "Enable Examples" ON)
57 option(ENABLE_TESTS "Enable Tests" ON)
58 option(ENABLE_TOOLS "Enable Tools" ON)
60 ### common
61 message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
62 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
63 file(MAKE_DIRECTORY
64         ${CMAKE_CURRENT_BINARY_DIR}/doc
65         ${CMAKE_CURRENT_BINARY_DIR}/doc/coverage
66         ${CMAKE_CURRENT_BINARY_DIR}/local/include
67         )
68 string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower)
70 ### library
71 add_subdirectory(src)
73 ### examples
74 message(STATUS "Build Examples: ${ENABLE_EXAMPLES}")
75 if(ENABLE_EXAMPLES)
76         add_subdirectory(examples)
77 endif()
79 ### ctags / cscope
80 include(CTags)
81 if(CTAGS_PATH AND CSCOPE_PATH)
82         setup_ctags_target("${CMAKE_CURRENT_SOURCE_DIR}/src/*.?pp")
83 endif()
85 ### documentation
86 find_package(Doxygen)
87 if(DOXYGEN_FOUND)
88         if(GIT_REPO_FOUND)
89                 git_authors(GIT_AUTHORS AUTHOR_LIST)
90         else()
91                 message(STATUS "no git repository found, using default authors list")
92                 set(AUTHOR_LIST "Mario Konrad, with help from others")
93         endif()
94         configure_file(
95                 ${CMAKE_CURRENT_SOURCE_DIR}/doc/main.dox.in
96                 ${CMAKE_CURRENT_BINARY_DIR}/doc/main.dox
97                 )
98         configure_file(
99                 ${CMAKE_CURRENT_SOURCE_DIR}/doxygen.conf.in
100                 ${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf
101                 )
102         add_custom_target(doc
103                 COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf
104                 )
105         add_dependencies(doc tags)
106 endif()
108 ### cppcheck
109 find_program(CPPCHECK_PATH cppcheck)
110 if(CPPCHECK_PATH)
111         message(STATUS "cppcheck found: ${CPPCHECK_PATH}")
112         add_custom_target(cppcheck
113                 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 -I ${CMAKE_CURRENT_BINARY_DIR}/local/include ${CMAKE_CURRENT_SOURCE_DIR}/src 2> ${CMAKE_CURRENT_BINARY_DIR}/doc/cppcheck.txt
114                 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
115         )
116 else()
117         message(STATUS "cppcheck not found, target not available.")
118 endif()
120 ### testing common stuff
121 enable_testing()
123 ### unit tests, assumes gtest (because of the program argument)
124 message(STATUS "Build Tests: ${ENABLE_TESTS}")
125 if(ENABLE_TESTS)
126         include(ExternGmock)
127         include(ExternBenchmark)
128         add_custom_target(unittest)
129         macro(run_unittest unittest_target)
130                 add_custom_target(${unittest_target}_runtest
131                         COMMAND ${unittest_target} --gtest_shuffle
132                         DEPENDS ${unittest_target}
133                         WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
134                         )
135                 add_dependencies(unittest ${unittest_target}_runtest)
136         endmacro()
138         add_subdirectory(test)
139 endif()
141 ### coverage
142 if(build_type_lower MATCHES coverage)
143         include(CodeCoverage)
144         setup_target_for_coverage(coverage
145                 testrunner
146                 doc/coverage
147                 )
148 endif()
151 ### package
152 set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
153 set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
154 set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
155 set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
156 set(CPACK_PACKAGE_NAME "marnav")
157 set(CPACK_PACKAGE_VENDOR "Mario Konrad")
158 set(CPACK_PACKAGE_CONTACT "Mario Konrad <mario.konrad@gmx.net>")
159 set(CPACK_PACAKGE_DESCRIPTION "Library for maritime navigation.")
160 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Library")
161 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
162 set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
163 set(CPACK_MONOLITHIC_INSTALL 1)
164 #set(CPACK_PACKAGE_EXECUTABLES "??" "??")
165 set(CPACK_STRIP_FILES true)
167 # package: debian
168 set(CPACK_DEBIAN_PACKAGE_NAME ${CPACK_DEBIAN_PACKAGE_NAME})
169 set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
170 set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACAKGE_DESCRIPTION})
171 set(CPACK_DEBIAN_PACKAGE_DEPENDS "libstdc++6 (>= 4.9)")
172 set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.3)")
173 set(CPACK_DEBIAN_PACKAGE_SECTION "misc")
174 if (CMAKE_SIZEOF_VOID_P MATCHES "8")
175         set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
176 else()
177         set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386")
178 endif()
180 include(CPack)