-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
328 lines (292 loc) · 10.7 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
project (arkcomm C CXX)
# settings
cmake_minimum_required (VERSION 2.8)
set(PROJECT_VERSION_MAJOR "0")
set(PROJECT_VERSION_MINOR "2")
set(PROJECT_VERSION_PATCH "0")
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
set(PROJECT_CONTACT_EMAIL [email protected])
set(PROJECT_CONTACT_VENDOR arkTools)
set(LIBRARY_VERSION ${PROJECT_VERSION})
set(LIBRARY_SOVERSION "0.0.0")
# third party libraries
set(BOOST_REQUIRED_VERSION 1.4.2)
set(SIMGEAR_REQUIRED_VERSION 2.7.0)
set(MAVLINK_REQUIRED_VERSION 1.0.4)
# tags
set(SIMGEAR_TAG 9ab31e0d88ef2a09f6a8dd33837ba547366151fa)
set(MAVLINK_TAG 112cad9a4f6dddd0e65472fdc2a0956ab39da0e6)
# options
option(WITH_BUILD_DEPS "Build dependencies." ON)
option(WITH_BUILD_STATIC "Prefer static linking." ON)
option(WITH_MAVLINK "Build with mavlink support." ON)
option(WITH_FLIGHTGEAR "Build with flightgear support." ON)
option(WITH_BUILD_SHARED "Build the shared library." OFF)
option(WITH_BUILD_TESTS "Build tests." OFF)
option(WITH_WARNINGS "Enable warnings." OFF)
set(RECURSE_OPTIONS_LIST
WITH_BUILD_DEPS
WITH_BUILD_STATIC
WITH_MAVLINK
WITH_FLIGHTGEAR
WITH_BUILD_SHARED
WITH_BUILD_TESTS
WITH_WARNINGS
CMAKE_TOOLCHAIN_FILE
CMAKE_INSTALL_PREFIX
EP_BASE_DIR
)
# variables
set(ROOT_THREAD TRUE CACHE INTERNAL "Is this the top level of the recursion?")
if (MINGW)
set(INSTALL_DATA_DIR "C:/Program Files/${PROJECT_NAME} ${PROJECT_VERSION}/share/${PROJECT_NAME}")
endif()
# modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_SOURCE_DIR}/cmake/arkcmake)
include(DefineCMakeDefaults)
include(DefineCompilerFlags)
include(BundleUtilities)
include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckLibraryExists)
#include(CheckTypeSize)
#include(CheckPrototypeExists)
#include(CheckCXXSourceCompiles)
#include(CheckCSourceCompiles)
include(ExternalProjectWithFilename)
# external projects find path
if(NOT EP_BASE_DIR)
set(EP_BASE_DIR "${CMAKE_BINARY_DIR}/CMakeExternals")
endif()
set_property(DIRECTORY PROPERTY EP_BASE ${EP_BASE_DIR})
set(EP_INSTALL_DIR "${EP_BASE_DIR}/Install")
list(APPEND CMAKE_FIND_ROOT_PATH ${EP_INSTALL_DIR})
# spawn new cmake to build deps
if (WITH_BUILD_DEPS AND ROOT_THREAD)
set(CMAKE_RECURSE_ARGS "-DROOT_THREAD=FALSE")
foreach(OPT ${RECURSE_OPTIONS_LIST})
list(APPEND CMAKE_RECURSE_ARGS "-D${OPT}=${${OPT}}")
endforeach()
execute_process(COMMAND ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR} ${CMAKE_RECURSE_ARGS}
RESULT_VARIABLE ERROR)
if (ERROR)
message(FATAL_ERROR "error, recursing loop returned error code: ${ERROR}")
endif()
message("** Making dependencies")
execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} "-j4" "-f${CMAKE_BINARY_DIR}/Makefile")
message("** Configuring ${PROJECT_NAME}")
endif()
# prefer static packages if building static library
message("** Finding libraries")
if (WITH_BUILD_STATIC)
set(BOOST_USE_STATIC_LIBS ON)
# prefer static libs
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
endif()
# find libraries with cmake modules
set(REQUIRED_IF_ROOT_THREAD)
if (ROOT_THREAD)
set(REQUIRED_IF_ROOT_THREAD "REQUIRED")
endif()
if (WIN32)
find_package(Boost ${BOOST_REQUIRED_VERSION} REQUIRED COMPONENTS thread_win32-mt system-mt)
else()
find_package(Boost ${BOOST_REQUIRED_VERSION} REQUIRED COMPONENTS thread-mt system-mt)
endif()
if (WITH_FLIGHTGEAR)
find_package(SimGear ${SIMGEAR_REQUIRED_VERSION} ${REQUIRED_IF_ROOT_THREAD} COMPONENTS
#nasal
#bucket
#route
io
serial
#math
#props
structure
#timing
#xml
#misc
threads
debug
#magvar
)
endif()
find_package(Threads REQUIRED)
find_package(MAVLink ${MAVLINK_REQUIRED_VERSION} ${REQUIRED_IF_ROOT_THREAD})
# build dependencies
if (WITH_BUILD_DEPS AND (NOT ROOT_THREAD) )
message("** Configuring dependencies")
# add external projects
set(CMAKE_EP_DEFAULT_ARGS
-DEP_BASE_DIR=${EP_BASE_DIR}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)
if (WITH_MAVLINK AND (NOT MAVLINK_FOUND))
ExternalProjectWithFilename_Add(mavlink
URL http://nodeload.github.com/mavlink/mavlink/zip/${MAVLINK_TAG}
FILENAME mavlink-${MAVLINK_TAG}.zip
CMAKE_ARGS ${CMAKE_EP_DEFAULT_ARGS}
INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} DESTDIR=${EP_INSTALL_DIR} install
INSTALL_DIR ${EP_INSTALL_DIR}
)
endif()
if (WITH_FLIGHTGEAR AND (NOT SIMGEAR_FOUND))
ExternalProjectWithFilename_Add(simgear
URL http://gitorious.org/fg/jgopperts-simgear/archive-tarball/${SIMGEAR_TAG}
FILENAME jgoppert-jgopperts-simgear-${SIMGEAR_TAG}.tar.gz
CMAKE_ARGS ${CMAKE_EP_DEFAULT_ARGS} "-DCMAKE_FIND_ROOT=/opt/local" "-DSIMGEAR_HEADLESS=ON" "-DENABLE_TESTS=OFF"
INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} DESTDIR=${EP_INSTALL_DIR} install
INSTALL_DIR ${E_INSTALL_DIR}
)
endif()
return()
endif()
# configure
#check_include_files(string.h HAVE_STRING_H)
#check_symbol_exists(LC_MESSAGES "locale.h" HAVE_LC_MESSAGES)
#check_library_exists(arkosg attachNode "" HAVE_ARKOSG)
# config files
configure_file(config.h.in config.h)
install(FILES ${CMAKE_BINARY_DIR}/config.h DESTINATION include/${PROJECT_NAME} COMPONENT Dev)
# build settings
if (MINGW)
add_definitions(-D_WIN32_WINNT=0x0501)
add_definitions(-DBOOST_THREAD_USE_LIB)
elseif(APPLE)
set(CMAKE_OSX_ARCHITECTURES "i386;ppc;x86_64" CACHE STRING "Build architectures for OSX" FORCE)
endif()
if (WITH_WARNINGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pedantic")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wshadow -Wmissing-prototypes -Wdeclaration-after-statement")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused -Wfloat-equal -Wpointer-arith -Wwrite-strings -Wformat-security")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-format-attribute")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wshadow")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused -Wfloat-equal -Wpointer-arith -Wwrite-strings -Wformat-security")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-format-attribute")
endif()
# project wide flags
include_directories(src ${CMAKE_BINARY_DIR})
include_directories(${Boost_INCLUDE_DIRS} ${MAVLINK_INCLUDE_DIRS} ${SIMGEAR_INCLUDE_DIRS})
# librarys
set(arkcommLibs ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
if (MINGW)
list(APPEND arkcommLibs ws2_32)
endif()
set(arkcommSources
src/AsyncSerial.cpp
)
add_executable(CommTest
src/CommTest.cpp
src/protocol.cxx
)
target_link_libraries(CommTest ${SIMGEAR_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
set(arkcommHeaders
src/AsyncSerial.hpp)
if (WITH_FLIGHTGEAR)
list(APPEND arkcommSources
src/FlightGearComm.cpp
src/flightGearUtils.cpp
)
list(APPEND arkcommHeaders
src/FlightGearComm.hpp
src/flightGearUtils.hpp
src/net_ctrls.hxx
src/net_fdm.hxx
)
list(APPEND arkcommLibs
${SIMGEAR_LIBRARIES}
)
endif()
# static library
add_library(arkcommStatic STATIC ${arkcommSources})
add_dependencies(arkcommStatic mavlink simgear)
set_target_properties(arkcommStatic PROPERTIES
OUTPUT_NAME arkcomm
VERSION ${LIBRARY_VERSION}
)
target_link_libraries(arkcommStatic ${arkcommLibs})
install(TARGETS arkcommStatic
ARCHIVE DESTINATION "lib" COMPONENT Dev
)
# shared library
if (BUILD_SHARED)
add_library(arkcommShared SHARED ${arkcommSources})
add_dependencies(arkcommShared mavlink simgear)
set_target_properties(arkcommShared PROPERTIES
OUTPUT_NAME arkcomm
VERSION ${LIBRARY_VERSION}
SOVERSION ${LIBRARY_SOVERSION}
FRAMEWORK ON
PUBLIC_HEADERS ${ARKCOMM_PUBLIC_HDRS}
PRIVATE_HEADERS ${ARKCOMM_PRIVATE_HDRS}
)
target_link_libraries(arkcommShared arkcommStatic ${arkcommLibs})
install(TARGETS arkcommShared
LIBRARY DESTINATION "lib" COMPONENT Runtime
FRAMEWORK DESTINATION "/Library/Frameworks" COMPONENT Runtime
# where to put files on non-mac computers, mac overrides and uses default
PRIVATE_HEADER DESTINATION "include/jsbsim" COMPONENT Runtime
PUBLIC_HEADER DESTINATION "include/jsbsim" COMPONENT Runtime
RESOURCE DESTINATION "share/jsbsim" COMPONENT Runtime
)
endif()
# flightgear multiplayer library
if (WITH_FLIGHTGEAR)
#include_directories(thirdParty thirdParty/flightgear/MultiPlayer thirdParty/flightgear src)
#add_library(fgMultiPlayer STATIC
#thirdParty/flightgear/MultiPlayer/mpmessages.hxx
#thirdParty/flightgear/MultiPlayer/tiny_xdr.cxx
#thirdParty/flightgear/MultiPlayer/tiny_xdr.hxx
#src/multiplaymgr.hxx
#src/multiplaymgr.cxx
#src/multiplay.hxx
#src/multiplay.cxx
#)
#add_dependencies(fgMultiPlayer simgear)
#target_link_libraries(fgMultiPlayer ${SIMGEAR_LIBRARIES})
endif()
# test programs
if (WITH_BUILD_TESTS)
if (MAVLINK_FOUND)
add_executable(mavlinkHilState test/mavlinkHilState.cpp)
target_link_libraries(mavlinkHilState arkcommStatic ${arkcommLIBS})
endif()
if (WITH_FLIGHTGEAR)
add_executable(fgMultiPlayerTest test/fgMultiPlayer.cpp)
target_link_libraries(fgMultiPlayerTest fgMultiPlayer ${SIMGEAR_LIBRARIES})
endif()
endif()
# install headers
install(FILES ${arkcommHeaders} DESTINATION include/arkcomm COMPONENT Dev)
# packaging
if (WIN32)
# set NSIS image
set(CPACK_PACKAGE_ICON "\\\\/cmake/jsbsim-nsis.bmp")
endif(WIN32)
configure_file("COPYING" "COPYING.txt" COPYONLY) # add file extensions and set resource files
configure_file("README" "README.txt" COPYONLY)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_BINARY_DIR}/COPYING.txt")
set(CPACK_RESOURCE_FILE_README "${CMAKE_BINARY_DIR}/README.txt")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CPACK_RESOURCE_FILE_README}")
set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/cmake/WELCOME.txt")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "arktools communication library")
set(CPACK_PACKAGE_VENDOR ${PROJECT_CONTACT_VENDOR})
set(CPACK_PACKAGE_CONTACT "${PROJECT_CONTACT_EMAIL}")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_SET_DESTDIR TRUE)
set(CPACK_COMPONENTS_GROUPING "ALL_COMPONENTS_IN_ONE")
include(CPack)
# pkgconfig
configure_file(pc.cmake arkcomm.pc)
install(FILES
${PROJECT_BINARY_DIR}/arkcomm.pc
DESTINATION lib/pkgconfig COMPONENT Dev
)
# vim:sw=4:ts=4:expandtab