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)
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")
14 message(FATAL_ERROR "Unsupported compiler detected: ${CMAKE_CXX_COMPILER_ID}")
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)
25 git_check_repository(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}")
37 message(STATUS "no git repository found, no further version info available")
40 message(STATUS "git not found, no further version info available")
43 message(STATUS "Project Vesion: ${PROJECT_VERSION}")
46 include(ExternalProject)
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)
61 message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
62 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
64 ${CMAKE_CURRENT_BINARY_DIR}/doc
65 ${CMAKE_CURRENT_BINARY_DIR}/doc/coverage
66 ${CMAKE_CURRENT_BINARY_DIR}/local/include
68 string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower)
74 message(STATUS "Build Examples: ${ENABLE_EXAMPLES}")
76 add_subdirectory(examples)
81 if(CTAGS_PATH AND CSCOPE_PATH)
82 setup_ctags_target("${CMAKE_CURRENT_SOURCE_DIR}/src/*.?pp")
89 git_authors(GIT_AUTHORS AUTHOR_LIST)
91 message(STATUS "no git repository found, using default authors list")
92 set(AUTHOR_LIST "Mario Konrad, with help from others")
95 ${CMAKE_CURRENT_SOURCE_DIR}/doc/main.dox.in
96 ${CMAKE_CURRENT_BINARY_DIR}/doc/main.dox
99 ${CMAKE_CURRENT_SOURCE_DIR}/doxygen.conf.in
100 ${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf
102 add_custom_target(doc
103 COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf
105 add_dependencies(doc tags)
109 find_program(CPPCHECK_PATH cppcheck)
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}
117 message(STATUS "cppcheck not found, target not available.")
120 ### testing common stuff
123 ### unit tests, assumes gtest (because of the program argument)
124 message(STATUS "Build Tests: ${ENABLE_TESTS}")
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}"
135 add_dependencies(unittest ${unittest_target}_runtest)
138 add_subdirectory(test)
142 if(build_type_lower MATCHES coverage)
143 include(CodeCoverage)
144 setup_target_for_coverage(coverage
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)
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")
177 set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386")