AIS: maneuver indicator is now an enumeration.
[marnav.git] / CMakeLists.txt
blobfebe2d277665bed3bcdb4ea5f9b60baa6e9e9321
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.5.0 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 ### version handling
23 if(NOT ("${CMAKE_BUILD_TYPE}" STREQUAL "Release"))
24         set(PROJECT_VERSION "${PROJECT_VERSION}-${GIT_COMMIT_HASH_SHORT}")
25 endif()
26 message(STATUS "Project Vesion: ${PROJECT_VERSION}")
28 ### external projects
29 include(ExternalProject)
30 include(ExternGmock)
31 include(ExternBenchmark)
33 ### options
34 option(ENABLE_PROFILING "Enable Profiling" OFF)
35 option(ENABLE_BENCHMARK "Enable Benchmark" OFF)
36 option(ENABLE_WARNING_HELL "Enable Warning Hell" OFF)
37 option(ENABLE_AIS "Enable AIS support" ON)
38 option(ENABLE_SEATALK "Enable SeaTalk support" ON)
39 option(ENABLE_IO "Enable IO support" ON)
41 ### common
42 message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
43 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
44 file(MAKE_DIRECTORY
45         ${CMAKE_CURRENT_BINARY_DIR}/doc
46         ${CMAKE_CURRENT_BINARY_DIR}/doc/coverage
47         ${CMAKE_CURRENT_BINARY_DIR}/local/include
48         )
49 string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower)
51 ### library
52 add_subdirectory(src)
54 ### examples
55 add_subdirectory(examples)
57 ### ctags / cscope
58 find_program(CTAGS_PATH ctags)
59 find_program(CSCOPE_PATH cscope)
60 if(CTAGS_PATH AND CSCOPE_PATH)
61         message(STATUS "Found ctags: ${CTAGS_PATH}")
62         message(STATUS "Found cscope: ${CSCOPE_PATH}")
64         set_source_files_properties(cscope.files PROPERTIES GENERATED true)
65         set_source_files_properties(cscope.out PROPERTIES GENERATED true)
66         set_source_files_properties(tags PROPERTIES GENERATED true)
68         file(GLOB_RECURSE SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.?pp")
69         string(REPLACE ";" "\n" SOURCE_FILES "${SOURCE_FILES}")
70         file(WRITE "${CMAKE_BINARY_DIR}/cscope.files.in" "${SOURCE_FILES}")
71         configure_file("${CMAKE_BINARY_DIR}/cscope.files.in" "${CMAKE_BINARY_DIR}/cscope.files" COPYONLY)
73         add_custom_target(tags
74                 COMMAND ${CTAGS_PATH} --c++-kinds=+p --fields=+iaS --extra=+q -L ${CMAKE_BINARY_DIR}/cscope.files
75                 COMMAND ${CSCOPE_PATH} -b
76                 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
77                 )
78 endif()
80 ### documentation
81 find_package(Doxygen)
82 if(DOXYGEN_FOUND)
83         configure_file(
84                 ${CMAKE_CURRENT_SOURCE_DIR}/doc/main.dox.in
85                 ${CMAKE_CURRENT_BINARY_DIR}/doc/main.dox
86                 )
87         configure_file(
88                 ${CMAKE_CURRENT_SOURCE_DIR}/doxygen.conf.in
89                 ${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf
90                 )
91         add_custom_target(doc
92                 COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf
93                 )
94         add_dependencies(doc tags)
95 endif()
97 ### cppcheck
98 find_program(CPPCHECK_PATH cppcheck)
99 if(CPPCHECK_PATH)
100         message(STATUS "cppcheck found: ${CPPCHECK_PATH}")
101         add_custom_target(cppcheck
102                 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
103                 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
104         )
105 else()
106         message(STATUS "cppcheck not found, target not available.")
107 endif()
109 ### testing common stuff
110 enable_testing()
112 ### unit tests, assumes gtest (because of the program argument)
113 add_custom_target(unittest)
114 macro(run_unittest unittest_target)
115         add_custom_target(${unittest_target}_runtest
116                 COMMAND ${unittest_target} --gtest_shuffle
117                 DEPENDS ${unittest_target}
118                 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
119                 )
120         add_dependencies(unittest ${unittest_target}_runtest)
121 endmacro()
123 add_subdirectory(test)
125 ### coverage
126 if(build_type_lower MATCHES coverage)
127         include(CodeCoverage)
128         setup_target_for_coverage(coverage
129                 testrunner
130                 doc/coverage
131                 )
132 endif()
135 ### package
136 set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
137 set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
138 set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
139 set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
140 set(CPACK_PACKAGE_NAME "marnav")
141 set(CPACK_PACKAGE_VENDOR "Mario Konrad")
142 set(CPACK_PACKAGE_CONTACT "Mario Konrad <mario.konrad@gmx.net>")
143 set(CPACK_PACAKGE_DESCRIPTION "Library for maritime navigation.")
144 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Library")
145 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
146 set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
147 set(CPACK_MONOLITHIC_INSTALL 1)
148 #set(CPACK_PACKAGE_EXECUTABLES "??" "??")
149 set(CPACK_STRIP_FILES true)
151 # package: debian
152 set(CPACK_DEBIAN_PACKAGE_NAME ${CPACK_DEBIAN_PACKAGE_NAME})
153 set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
154 set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACAKGE_DESCRIPTION})
155 set(CPACK_DEBIAN_PACKAGE_DEPENDS "libstdc++6 (>= 4.8)")
156 set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.3)")
157 set(CPACK_DEBIAN_PACKAGE_SECTION "misc")
158 if (CMAKE_SIZEOF_VOID_P MATCHES "8")
159         set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
160 else()
161         set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386")
162 endif()
164 include(CPack)