Dev: improve robustness of CTags.cmake
[marnav.git] / src / CMakeLists.txt
blobe42659777fbc05a4c6da0db84cd3cc101b24a147
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/mtw.cpp
111                 marnav/nmea/mwd.cpp
112                 marnav/nmea/mwv.cpp
113                 marnav/nmea/name.cpp
114                 marnav/nmea/nmea.cpp
115                 marnav/nmea/osd.cpp
116                 marnav/nmea/pgrme.cpp
117                 marnav/nmea/pgrmm.cpp
118                 marnav/nmea/pgrmz.cpp
119                 marnav/nmea/r00.cpp
120                 marnav/nmea/rma.cpp
121                 marnav/nmea/rmb.cpp
122                 marnav/nmea/rmc.cpp
123                 marnav/nmea/rot.cpp
124                 marnav/nmea/rpm.cpp
125                 marnav/nmea/rsa.cpp
126                 marnav/nmea/rsd.cpp
127                 marnav/nmea/rte.cpp
128                 marnav/nmea/sentence.cpp
129                 marnav/nmea/sfi.cpp
130                 marnav/nmea/split.cpp
131                 marnav/nmea/stalk.cpp
132                 marnav/nmea/stn.cpp
133                 marnav/nmea/string.cpp
134                 marnav/nmea/tag_block.cpp
135                 marnav/nmea/talker_id.cpp
136                 marnav/nmea/tds.cpp
137                 marnav/nmea/tfi.cpp
138                 marnav/nmea/time.cpp
139                 marnav/nmea/tll.cpp
140                 marnav/nmea/tpc.cpp
141                 marnav/nmea/tpr.cpp
142                 marnav/nmea/tpt.cpp
143                 marnav/nmea/ttm.cpp
144                 marnav/nmea/vbw.cpp
145                 marnav/nmea/vdm.cpp
146                 marnav/nmea/vdo.cpp
147                 marnav/nmea/vdr.cpp
148                 marnav/nmea/vhw.cpp
149                 marnav/nmea/vlw.cpp
150                 marnav/nmea/vpw.cpp
151                 marnav/nmea/vtg.cpp
152                 marnav/nmea/vwr.cpp
153                 marnav/nmea/waypoint.cpp
154                 marnav/nmea/wcv.cpp
155                 marnav/nmea/wnc.cpp
156                 marnav/nmea/wpl.cpp
157                 marnav/nmea/xdr.cpp
158                 marnav/nmea/xte.cpp
159                 marnav/nmea/xtr.cpp
160                 marnav/nmea/zda.cpp
161                 marnav/nmea/zdl.cpp
162                 marnav/nmea/zfo.cpp
163                 marnav/nmea/ztg.cpp
164                 marnav/seatalk/message.cpp
165                 marnav/seatalk/message_00.cpp
166                 marnav/seatalk/message_01.cpp
167                 marnav/seatalk/message_05.cpp
168                 marnav/seatalk/message_10.cpp
169                 marnav/seatalk/message_11.cpp
170                 marnav/seatalk/message_20.cpp
171                 marnav/seatalk/message_21.cpp
172                 marnav/seatalk/message_22.cpp
173                 marnav/seatalk/message_23.cpp
174                 marnav/seatalk/message_24.cpp
175                 marnav/seatalk/message_25.cpp
176                 marnav/seatalk/message_26.cpp
177                 marnav/seatalk/message_27.cpp
178                 marnav/seatalk/message_30.cpp
179                 marnav/seatalk/message_36.cpp
180                 marnav/seatalk/message_38.cpp
181                 marnav/seatalk/message_50.cpp
182                 marnav/seatalk/message_51.cpp
183                 marnav/seatalk/message_52.cpp
184                 marnav/seatalk/message_53.cpp
185                 marnav/seatalk/message_54.cpp
186                 marnav/seatalk/message_56.cpp
187                 marnav/seatalk/message_58.cpp
188                 marnav/seatalk/message_59.cpp
189                 marnav/seatalk/message_65.cpp
190                 marnav/seatalk/message_66.cpp
191                 marnav/seatalk/message_6c.cpp
192                 marnav/seatalk/message_86.cpp
193                 marnav/seatalk/message_87.cpp
194                 marnav/seatalk/message_89.cpp
195                 marnav/seatalk/seatalk.cpp
196                 marnav/utils/mmsi.cpp
197                 marnav/utils/mmsi_country.cpp
198         )
200 include(CheckSymbolExists)
201 if(APPLE)
202         check_symbol_exists(strtod_l xlocale.h HAVE_STRTOD_L)
203 else()
204         check_symbol_exists(strtod_l stdlib.h HAVE_STRTOD_L)
205 endif()
207 if(DEFINED HAVE_STRTOD_L)
208         target_sources(marnav PRIVATE marnav/nmea/io_double_strtodl.cpp)
209 else()
210         target_sources(marnav PRIVATE marnav/nmea/io_double_strstream.cpp)
211 endif()
213 install(
214         DIRECTORY
215                 ${PROJECT_SOURCE_DIR}/include/marnav/ais
216                 ${PROJECT_SOURCE_DIR}/include/marnav/geo
217                 ${PROJECT_SOURCE_DIR}/include/marnav/math
218                 ${PROJECT_SOURCE_DIR}/include/marnav/nmea
219                 ${PROJECT_SOURCE_DIR}/include/marnav/seatalk
220                 ${PROJECT_SOURCE_DIR}/include/marnav/units
221                 ${PROJECT_SOURCE_DIR}/include/marnav/utils
222         DESTINATION include/marnav
223         )
225 if(ENABLE_IO)
226         target_sources(marnav
227                 PRIVATE
228                         marnav/io/serial.cpp
229                         marnav/io/nmea_reader.cpp
230                         marnav/io/default_nmea_reader.cpp
231                         marnav/io/seatalk_reader.cpp
232                         marnav/io/default_seatalk_reader.cpp
233                 )
234         install(
235                 DIRECTORY ${PROJECT_SOURCE_DIR}/include/marnav/io
236                 DESTINATION include/marnav
237                 )
238 endif()
240 target_include_directories(marnav
241         PRIVATE
242                 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
243         PUBLIC
244                 $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
245                 $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
246                 $<INSTALL_INTERFACE:include>
247         )
249 target_compile_options(marnav
250         PRIVATE
251                 -pipe
252                 -ggdb
253                 -Wall
254                 -Wextra
255                 -pedantic-errors
256                 -Wold-style-cast
257                 -Wcast-align
258                 -Wcast-qual
259                 -Werror
260                 -Wdisabled-optimization
261                 -Wfloat-equal
262                 -Wformat=2
263                 -Wformat-security
264                 -Wformat-y2k
265                 -Wimport
266                 -Winit-self
267                 -Wmissing-field-initializers
268                 -Wmissing-format-attribute
269                 -Wmissing-include-dirs
270                 -Wmissing-noreturn
271                 -Wnon-virtual-dtor
272                 -Woverloaded-virtual
273                 -Wpacked
274                 -Wpointer-arith
275                 -Wredundant-decls
276                 -Wstrict-aliasing=2
277                 -Wswitch
278                 -Wunreachable-code
279                 -Wunused
280                 -Wunused-parameter
281                 -Wvariadic-macros
282                 -Wwrite-strings
283                 # explicitly disabled on purpose:
284                 -Wno-inline
285                 -Wno-conversion
286                 -Wno-shadow
287                 -Wno-sign-conversion
288                 -Wno-stack-protector
289                 -Wno-effc++
290                 -Wno-padded
291                 -Wno-long-long
292                 -Wno-unused-function
293                 -Wno-comment
294                 -Wno-format-nonliteral
295                 -Wno-switch-enum
296                 -Wno-switch-default
297         )
299 if(ENABLE_PROFILING)
300         target_compile_options(marnav
301                 PRIVATE
302                         -pg
303                 )
304 endif()
306 if(ENABLE_BENCHMARK)
307         target_compile_options(marnav
308                 PRIVATE
309                         -fno-omit-frame-pointer
310                 )
311 endif()
313 if(ENABLE_SANITIZER)
314         message(STATUS "Sanitizer: enabled")
315         target_compile_options(marnav
316                 PRIVATE
317                         -fsanitize=address
318                         -fsanitize=undefined
319                 )
321         target_link_libraries(marnav
322                 asan
323                 ubsan
324                 )
325 endif()
327 if(CMAKE_BUILD_TYPE MATCHES Coverage)
328         message(STATUS "Coverage: enabled")
329         target_compile_options(marnav
330                 PRIVATE
331                         --coverage
332                         -fprofile-arcs
333                         -ftest-coverage
334                         -fno-inline
335                         -fno-inline-small-functions
336                         -fno-default-inline
337                 )
338 endif()
340 set_target_properties(marnav
341         PROPERTIES VERSION "${PROJECT_VERSION}"
342         SOVERSION "${PROJECT_VERSION}"
343         )
345 # stuff for the config and config-version files
346 set(INCLUDE_INSTALL_DIR include)
347 set(LIB_INSTALL_DIR lib)
348 include(CMakePackageConfigHelpers)
350 set(targets_export_name ${PROJECT_NAME}-targets)
352 install(
353         TARGETS marnav
354         EXPORT ${targets_export_name}
355         LIBRARY DESTINATION ${LIB_INSTALL_DIR}
356         ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
357         RUNTIME DESTINATION bin
358         INCLUDES DESTINATION ${INCLUDE_INSTALL_DIR}
359         )
361 configure_package_config_file(
362         config.cmake.in
363         "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
364         INSTALL_DESTINATION "${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME}"
365         PATH_VARS INCLUDE_INSTALL_DIR
366         )
368 install(
369         EXPORT ${targets_export_name}
370         NAMESPACE "${PROJECT_NAME}::"
371         DESTINATION "${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME}"
372         )
374 write_basic_package_version_file(
375         "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
376         VERSION "${PROJECT_VERSION}" COMPATIBILITY SameMajorVersion)
378 install(
379         FILES
380                 "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
381                 "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
382         DESTINATION
383                 "${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME}"
384         )
387 if(ENABLE_TOOLS)
388         ### bin: nmeasum
389         add_executable(nmeasum)
390         target_sources(nmeasum PRIVATE nmeasum.cpp)
391         target_link_libraries(nmeasum PRIVATE marnav::marnav)
393         target_compile_options(nmeasum
394                 PRIVATE
395                         -pipe
396                         -ggdb
397                         -Wall
398                         -Wextra
399                         -pedantic-errors
400                 )
402         ### bin: nmeadump
403         if(ENABLE_IO)
404                 add_executable(nmeadump)
405                 target_sources(nmeadump PRIVATE nmeadump.cpp)
407                 target_compile_options(nmeadump
408                         PRIVATE
409                                 -pipe
410                                 -ggdb
411                                 -Wall
412                                 -Wextra
413                                 -pedantic-errors
414                         )
416                 target_link_libraries(nmeadump
417                         PRIVATE
418                                 marnav::marnav
419                                 cxxopts::cxxopts
420                                 fmt::fmt
421                         )
422         endif()
423 endif()