NMEA: sentence ZPI added
[marnav.git] / src / CMakeLists.txt
blobb85f916ed7cdfce3c2f79828ff1333edf58680d4
1 cmake_minimum_required(VERSION 3.11)
3 ### lib: marnav
5 message(STATUS "Build shared library : ${BUILD_SHARED_LIBS}")
6 message(STATUS "Build IO support     : ${ENABLE_IO}")
7 message(STATUS "Build Tools          : ${ENABLE_TOOLS}")
9 configure_file(
10         ${CMAKE_CURRENT_SOURCE_DIR}/marnav/version.hpp.in
11         ${CMAKE_CURRENT_BINARY_DIR}/marnav/version.hpp
12         )
14 install(
15         FILES ${CMAKE_CURRENT_BINARY_DIR}/marnav/version.hpp
16         DESTINATION include/marnav
17         )
19 add_library(marnav ${LIBRARY_TYPE})
20 add_library(marnav::marnav ALIAS marnav)
22 target_compile_features(marnav
23         PRIVATE
24                 cxx_std_11
25         )
27 target_sources(marnav
28         PRIVATE
29                 marnav/ais/ais.cpp
30                 marnav/ais/angle.cpp
31                 marnav/ais/binary_001_11.cpp
32                 marnav/ais/binary_200_10.cpp
33                 marnav/ais/binary_data.cpp
34                 marnav/ais/message_01.cpp
35                 marnav/ais/message_02.cpp
36                 marnav/ais/message_03.cpp
37                 marnav/ais/message_04.cpp
38                 marnav/ais/message_05.cpp
39                 marnav/ais/message_06.cpp
40                 marnav/ais/message_07.cpp
41                 marnav/ais/message_08.cpp
42                 marnav/ais/message_09.cpp
43                 marnav/ais/message_10.cpp
44                 marnav/ais/message_11.cpp
45                 marnav/ais/message_12.cpp
46                 marnav/ais/message_13.cpp
47                 marnav/ais/message_14.cpp
48                 marnav/ais/message_17.cpp
49                 marnav/ais/message_18.cpp
50                 marnav/ais/message_19.cpp
51                 marnav/ais/message_20.cpp
52                 marnav/ais/message_21.cpp
53                 marnav/ais/message_22.cpp
54                 marnav/ais/message_23.cpp
55                 marnav/ais/message_24.cpp
56                 marnav/ais/name.cpp
57                 marnav/ais/rate_of_turn.cpp
58                 marnav/ais/vessel_dimension.cpp
59                 marnav/geo/angle.cpp
60                 marnav/geo/cpa.cpp
61                 marnav/geo/geodesic.cpp
62                 marnav/geo/position.cpp
63                 marnav/geo/region.cpp
64                 marnav/nmea/aam.cpp
65                 marnav/nmea/ais_helper.cpp
66                 marnav/nmea/alm.cpp
67                 marnav/nmea/angle.cpp
68                 marnav/nmea/apa.cpp
69                 marnav/nmea/apb.cpp
70                 marnav/nmea/bec.cpp
71                 marnav/nmea/bod.cpp
72                 marnav/nmea/bwc.cpp
73                 marnav/nmea/bwr.cpp
74                 marnav/nmea/bww.cpp
75                 marnav/nmea/checks.cpp
76                 marnav/nmea/checksum.cpp
77                 marnav/nmea/convert.cpp
78                 marnav/nmea/date.cpp
79                 marnav/nmea/dbk.cpp
80                 marnav/nmea/dbt.cpp
81                 marnav/nmea/detail.cpp
82                 marnav/nmea/dpt.cpp
83                 marnav/nmea/dsc.cpp
84                 marnav/nmea/dse.cpp
85                 marnav/nmea/dtm.cpp
86                 marnav/nmea/fsi.cpp
87                 marnav/nmea/gbs.cpp
88                 marnav/nmea/gga.cpp
89                 marnav/nmea/glc.cpp
90                 marnav/nmea/gll.cpp
91                 marnav/nmea/gns.cpp
92                 marnav/nmea/grs.cpp
93                 marnav/nmea/gsa.cpp
94                 marnav/nmea/gst.cpp
95                 marnav/nmea/gsv.cpp
96                 marnav/nmea/gtd.cpp
97                 marnav/nmea/hdg.cpp
98                 marnav/nmea/hdm.cpp
99                 marnav/nmea/hdt.cpp
100                 marnav/nmea/hex_digit.hpp
101                 marnav/nmea/hfb.cpp
102                 marnav/nmea/hsc.cpp
103                 marnav/nmea/io.cpp
104                 marnav/nmea/its.cpp
105                 marnav/nmea/lcd.cpp
106                 marnav/nmea/manufacturer.cpp
107                 marnav/nmea/mob.cpp
108                 marnav/nmea/msk.cpp
109                 marnav/nmea/mss.cpp
110                 marnav/nmea/mta.cpp
111                 marnav/nmea/mtw.cpp
112                 marnav/nmea/mwd.cpp
113                 marnav/nmea/mwv.cpp
114                 marnav/nmea/name.cpp
115                 marnav/nmea/nmea.cpp
116                 marnav/nmea/osd.cpp
117                 marnav/nmea/pgrme.cpp
118                 marnav/nmea/pgrmm.cpp
119                 marnav/nmea/pgrmz.cpp
120                 marnav/nmea/r00.cpp
121                 marnav/nmea/rma.cpp
122                 marnav/nmea/rmb.cpp
123                 marnav/nmea/rmc.cpp
124                 marnav/nmea/rot.cpp
125                 marnav/nmea/route.cpp
126                 marnav/nmea/rpm.cpp
127                 marnav/nmea/rsa.cpp
128                 marnav/nmea/rsd.cpp
129                 marnav/nmea/rte.cpp
130                 marnav/nmea/sentence.cpp
131                 marnav/nmea/sfi.cpp
132                 marnav/nmea/split.cpp
133                 marnav/nmea/stalk.cpp
134                 marnav/nmea/stn.cpp
135                 marnav/nmea/string.cpp
136                 marnav/nmea/tag_block.cpp
137                 marnav/nmea/talker_id.cpp
138                 marnav/nmea/tds.cpp
139                 marnav/nmea/tfi.cpp
140                 marnav/nmea/time.cpp
141                 marnav/nmea/tll.cpp
142                 marnav/nmea/tpc.cpp
143                 marnav/nmea/tpr.cpp
144                 marnav/nmea/tpt.cpp
145                 marnav/nmea/ttm.cpp
146                 marnav/nmea/vbw.cpp
147                 marnav/nmea/vdm.cpp
148                 marnav/nmea/vdo.cpp
149                 marnav/nmea/vdr.cpp
150                 marnav/nmea/vhw.cpp
151                 marnav/nmea/vlw.cpp
152                 marnav/nmea/vpw.cpp
153                 marnav/nmea/vtg.cpp
154                 marnav/nmea/vwe.cpp
155                 marnav/nmea/vwr.cpp
156                 marnav/nmea/waypoint.cpp
157                 marnav/nmea/wcv.cpp
158                 marnav/nmea/wdc.cpp
159                 marnav/nmea/wdr.cpp
160                 marnav/nmea/wnc.cpp
161                 marnav/nmea/wpl.cpp
162                 marnav/nmea/xdr.cpp
163                 marnav/nmea/xte.cpp
164                 marnav/nmea/xtr.cpp
165                 marnav/nmea/zda.cpp
166                 marnav/nmea/zdl.cpp
167                 marnav/nmea/zfi.cpp
168                 marnav/nmea/zfo.cpp
169                 marnav/nmea/zpi.cpp
170                 marnav/nmea/zta.cpp
171                 marnav/nmea/zte.cpp
172                 marnav/nmea/ztg.cpp
173                 marnav/seatalk/message.cpp
174                 marnav/seatalk/message_00.cpp
175                 marnav/seatalk/message_01.cpp
176                 marnav/seatalk/message_05.cpp
177                 marnav/seatalk/message_10.cpp
178                 marnav/seatalk/message_11.cpp
179                 marnav/seatalk/message_20.cpp
180                 marnav/seatalk/message_21.cpp
181                 marnav/seatalk/message_22.cpp
182                 marnav/seatalk/message_23.cpp
183                 marnav/seatalk/message_24.cpp
184                 marnav/seatalk/message_25.cpp
185                 marnav/seatalk/message_26.cpp
186                 marnav/seatalk/message_27.cpp
187                 marnav/seatalk/message_30.cpp
188                 marnav/seatalk/message_36.cpp
189                 marnav/seatalk/message_38.cpp
190                 marnav/seatalk/message_50.cpp
191                 marnav/seatalk/message_51.cpp
192                 marnav/seatalk/message_52.cpp
193                 marnav/seatalk/message_53.cpp
194                 marnav/seatalk/message_54.cpp
195                 marnav/seatalk/message_56.cpp
196                 marnav/seatalk/message_58.cpp
197                 marnav/seatalk/message_59.cpp
198                 marnav/seatalk/message_65.cpp
199                 marnav/seatalk/message_66.cpp
200                 marnav/seatalk/message_6c.cpp
201                 marnav/seatalk/message_86.cpp
202                 marnav/seatalk/message_87.cpp
203                 marnav/seatalk/message_89.cpp
204                 marnav/seatalk/seatalk.cpp
205                 marnav/utils/mmsi.cpp
206                 marnav/utils/mmsi_country.cpp
207         )
209 include(CheckSymbolExists)
210 if(APPLE)
211         check_symbol_exists(strtod_l xlocale.h HAVE_STRTOD_L)
212 else()
213         check_symbol_exists(strtod_l stdlib.h HAVE_STRTOD_L)
214 endif()
216 if(DEFINED HAVE_STRTOD_L)
217         target_sources(marnav PRIVATE marnav/nmea/io_double_strtodl.cpp)
218 else()
219         target_sources(marnav PRIVATE marnav/nmea/io_double_strstream.cpp)
220 endif()
222 install(
223         DIRECTORY
224                 ${PROJECT_SOURCE_DIR}/include/marnav/ais
225                 ${PROJECT_SOURCE_DIR}/include/marnav/geo
226                 ${PROJECT_SOURCE_DIR}/include/marnav/math
227                 ${PROJECT_SOURCE_DIR}/include/marnav/nmea
228                 ${PROJECT_SOURCE_DIR}/include/marnav/seatalk
229                 ${PROJECT_SOURCE_DIR}/include/marnav/units
230                 ${PROJECT_SOURCE_DIR}/include/marnav/utils
231         DESTINATION include/marnav
232         )
234 if(ENABLE_IO)
235         target_sources(marnav
236                 PRIVATE
237                         marnav/io/serial.cpp
238                         marnav/io/nmea_reader.cpp
239                         marnav/io/default_nmea_reader.cpp
240                         marnav/io/seatalk_reader.cpp
241                         marnav/io/default_seatalk_reader.cpp
242                 )
243         install(
244                 DIRECTORY ${PROJECT_SOURCE_DIR}/include/marnav/io
245                 DESTINATION include/marnav
246                 )
247 endif()
249 target_include_directories(marnav
250         PRIVATE
251                 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
252         PUBLIC
253                 $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
254                 $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
255                 $<INSTALL_INTERFACE:include>
256         )
258 target_compile_options(marnav
259         PRIVATE
260                 -pipe
261                 -ggdb
262                 -Wall
263                 -Wextra
264                 -pedantic-errors
265                 -Wold-style-cast
266                 -Wcast-align
267                 -Wcast-qual
268                 -Werror
269                 -Wdisabled-optimization
270                 -Wfloat-conversion
271                 -Wfloat-equal
272                 -Wformat=2
273                 -Wformat-security
274                 -Wformat-y2k
275                 -Wimport
276                 -Winit-self
277                 -Wmissing-field-initializers
278                 -Wmissing-format-attribute
279                 -Wmissing-include-dirs
280                 -Wmissing-noreturn
281                 -Wnon-virtual-dtor
282                 -Woverloaded-virtual
283                 -Wpacked
284                 -Wpointer-arith
285                 -Wredundant-decls
286                 -Wstrict-aliasing=2
287                 -Wswitch
288                 -Wunreachable-code
289                 -Wunused
290                 -Wunused-parameter
291                 -Wvariadic-macros
292                 -Wwrite-strings
293                 # explicitly disabled on purpose:
294                 -Wno-inline
295                 -Wno-conversion
296                 -Wno-shadow
297                 -Wno-sign-conversion
298                 -Wno-stack-protector
299                 -Wno-effc++
300                 -Wno-padded
301                 -Wno-long-long
302                 -Wno-unused-function
303                 -Wno-comment
304                 -Wno-format-nonliteral
305                 -Wno-switch-enum
306                 -Wno-switch-default
307         )
309 if(ENABLE_PROFILING)
310         target_compile_options(marnav
311                 PRIVATE
312                         -pg
313                 )
314 endif()
316 if(ENABLE_BENCHMARK)
317         target_compile_options(marnav
318                 PRIVATE
319                         -fno-omit-frame-pointer
320                 )
321 endif()
323 if(ENABLE_SANITIZER)
324         message(STATUS "Sanitizer: enabled")
325         target_compile_options(marnav
326                 PRIVATE
327                         -fsanitize=address
328                         -fsanitize=undefined
329                 )
331         target_link_libraries(marnav
332                 asan
333                 ubsan
334                 )
335 endif()
337 if(CMAKE_BUILD_TYPE MATCHES Coverage)
338         message(STATUS "Coverage: enabled")
339         target_compile_options(marnav
340                 PRIVATE
341                         --coverage
342                         -fprofile-arcs
343                         -ftest-coverage
344                         -fno-inline
345                         -fno-inline-small-functions
346                         -fno-default-inline
347                 )
348 endif()
350 set_target_properties(marnav
351         PROPERTIES VERSION "${PROJECT_VERSION}"
352         SOVERSION "${PROJECT_VERSION}"
353         )
355 # stuff for the config and config-version files
356 set(INCLUDE_INSTALL_DIR include)
357 set(LIB_INSTALL_DIR lib)
358 include(CMakePackageConfigHelpers)
360 set(targets_export_name ${PROJECT_NAME}-targets)
362 install(
363         TARGETS marnav
364         EXPORT ${targets_export_name}
365         LIBRARY DESTINATION ${LIB_INSTALL_DIR}
366         ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
367         RUNTIME DESTINATION bin
368         INCLUDES DESTINATION ${INCLUDE_INSTALL_DIR}
369         )
371 configure_package_config_file(
372         config.cmake.in
373         "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
374         INSTALL_DESTINATION "${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME}"
375         PATH_VARS INCLUDE_INSTALL_DIR
376         )
378 install(
379         EXPORT ${targets_export_name}
380         NAMESPACE "${PROJECT_NAME}::"
381         DESTINATION "${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME}"
382         )
384 write_basic_package_version_file(
385         "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
386         VERSION "${PROJECT_VERSION}" COMPATIBILITY SameMajorVersion)
388 install(
389         FILES
390                 "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
391                 "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
392         DESTINATION
393                 "${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME}"
394         )
397 if(ENABLE_TOOLS)
398         ### bin: nmeasum
399         add_executable(nmeasum)
400         target_sources(nmeasum PRIVATE nmeasum.cpp)
401         target_link_libraries(nmeasum PRIVATE marnav::marnav)
403         target_compile_options(nmeasum
404                 PRIVATE
405                         -pipe
406                         -ggdb
407                         -Wall
408                         -Wextra
409                         -pedantic-errors
410                 )
412         ### bin: nmeadump
413         if(ENABLE_IO)
414                 add_executable(nmeadump)
415                 target_sources(nmeadump PRIVATE nmeadump.cpp)
417                 target_compile_options(nmeadump
418                         PRIVATE
419                                 -pipe
420                                 -ggdb
421                                 -Wall
422                                 -Wextra
423                                 -pedantic-errors
424                         )
426                 target_link_libraries(nmeadump
427                         PRIVATE
428                                 marnav::marnav
429                                 cxxopts::cxxopts
430                                 fmt::fmt
431                         )
432         endif()
433 endif()