-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
298 lines (264 loc) · 10.5 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
project (arkmath C CXX)
# settings
cmake_minimum_required (VERSION 2.8)
set(PROJECT_VERSION_MAJOR "0")
set(PROJECT_VERSION_MINOR "2")
set(PROJECT_VERSION_PATCH "7")
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 library version
set(BOOSTNUMERICBINDINGS_REQUIRED_VERSION 20081116)
set(BOOST_REQUIRED_VERSION 1.4.2)
# md5 check sums
set(ARKOSG_MD5 0f074bb72d2ab61e7a710d177ad6feda)
set(BOOSTNUMERICBINDINGS_MD5 835c88497ba8d6fd745e3971c560a6a3)
# options
option(WITH_BUILD_DEPS "Build external dependencies." OFF)
option(WITH_BUILD_SHARED "Build shared library." OFF)
option(WITH_PREFER_STATIC "Prefer static linking." ON)
option(WITH_BUILD_TESTING "Build test programs." OFF)
option(WITH_LAPACK "Build with lapack library support." OFF)
option(WITH_WARNINGS "Enable warnings." OFF)
# variables
set(ROOT_THREAD TRUE CACHE INTERNAL "Is this the top level of the recursion?")
set(INSTALLED_TARGETS "")
# modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_SOURCE_DIR}/cmake/arkcmake)
include(DefineCMakeDefaults)
include(DefineCompilerFlags)
include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckLibraryExists)
#include(CheckTypeSize)
#include(CheckPrototypeExists)
#include(CheckCXXSourceCompiles)
#include(CheckCSourceCompiles)
include(ExternalProjectWithFilename)
include(BundleUtilities)
# spawn new cmake to build deps
if (WITH_BUILD_DEPS AND ROOT_THREAD)
execute_process(COMMAND ${CMAKE_COMMAND} "${CMAKE_SOURCE_DIR}"
"-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}"
"-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}"
"-DEP_BASE_DIR=${EP_BASE_DIR}"
"-DWITH_BUILD_DEPS=${WITH_BUILD_DEPS}"
"-DWITH_PREFER_STATIC=${WITH_PREFER_STATIC}"
"-DWITH_LAPACK=${WITH_LAPACK}"
"-DROOT_THREAD=FALSE"
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()
# external projects find path
if(NOT EP_BASE_DIR)
set(EP_BASE_DIR "${CMAKE_BINARY_DIR}/CMakeExternals")
endif()
list(APPEND CMAKE_FIND_ROOT_PATH ${EP_BASE_DIR})
# prefer static packages if building static library
message("** Finding libraries")
if (WITH_PREFER_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(WITH_LAPACK)
enable_language(Fortran)
find_package(LAPACK)
find_package(BoostNumericBindings ${BOOSTNUMERICBINDINGS_REQUIRED_VERSION} ${REQUIRED_IF_ROOT_THREAD})
endif()
if(WIN32)
find_package(Boost ${BOOST_REQUIRED_VERSION} REQUIRED COMPONENTS system-mt thread_win32-mt)
else()
find_package(Boost ${BOOST_REQUIRED_VERSION} REQUIRED COMPONENTS system-mt thread-mt)
endif()
# build dependencies
if (WITH_BUILD_DEPS AND (NOT ROOT_THREAD) )
message("** Configuring dependencies")
# add external projects
set(CMAKE_DEFAULT_ARGS
-DEP_BASE_DIR=${EP_BASE_DIR}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)
if (WITH_LAPACK AND (NOT BOOSTNUMERICBINDINGS_FOUND))
ExternalProjectWithFilename_Add(boost-numeric-bindings
URL http://mathema.tician.de/news.tiker.net/download/software/boost-numeric-bindings/boost-numeric-bindings-${BOOSTNUMERICBINDINGS_REQUIRED_VERSION}.tar.gz
URL_MD5 ${BOOSTNUMERICBINDINGS_MD5}
FILENAME boost-numeric-bindings-${BOOSTNUMERICBINDINGS_MD5}.tar.gz
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_DIR ${EP_BASE_DIR}/${CMAKE_INSTALL_PREFIX}
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory boost ${EP_BASE_DIR}/${CMAKE_INSTALL_PREFIX}/include/boost
)
endif()
# terminate non root cmake thread
return()
endif()
# configure
#check_include_files(string.h HAVE_STRING_H)
#check_function_exists(memcopy HAVE_MEMCOPY)
#check_symbol_exists(LC_MESSAGES "locale.h" HAVE_LC_MESSAGES)
#check_library_exists(arkosg attachNode "" HAVE_ARKOSG)
# config files
set(INSTALL_DATA_DIR "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}")
configure_file(config.h.in config.h)
install(FILES ${CMAKE_BINARY_DIR}/config.h DESTINATION include/${PROJECT_NAME} COMPONENT Runtime)
# build settings
if(APPLE)
set(CMAKE_OSX_ARCHITECTURES "i386;ppc;x86_64" CACHE STRING "Build architectures for OSX" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.5 -ftree-vectorize -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE)
endif()
include_directories(
${CMAKE_SOURCE_DIR}/src
${PROJECT_BINARY_DIR}/src
${BOOSTNUMERICBINDINGS_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
add_definitions(-DBOOST_THREAD_USE_LIB)
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()
# install data files
install(DIRECTORY "${PROJECT_SOURCE_DIR}/data" DESTINATION share/${PROJECT_NAME} COMPONENT Dev PATTERN "*.git*" EXCLUDE)
set(generalSources
src/GeoMag.cpp
src/utilities.cpp
)
set(generalHeaders
src/GeoMag.hpp
src/GpsIns.hpp
src/storage_adaptors.hpp
src/utilities.hpp
)
if (WITH_LAPACK)
list(APPEND generalSources src/GpsIns.cpp)
list(APPEND generalHeaders src/GpsIns.hpp)
endif()
file(GLOB gen_cppHeaders "src/gen_cpp/*.h*")
file(GLOB gen_fortranHeaders "src/gen_cpp/*.f*")
file(GLOB gen_sciHeaders "src/gen_sci/*.sci")
# link libraries
set(ARKMATH_LINK_LIBS
${Boost_LIBRARIES}
${LAPACK_LIBRARIES}
m
)
if (WITH_LAPACK)
list(APPEND ARKMATH_LINK_LIBS gfortran)
endif()
# static library
add_library(arkmathStatic STATIC ${generalSources})
add_dependencies(arkmathStatic boost-numeric-bindings)
set(STATIC_LIBNAME_SUFFIX "")
if (MSVC)
set(STATIC_LIBNAME_SUFFIX "static")
endif()
set_target_properties(arkmathStatic PROPERTIES
OUTPUT_NAME arkmath${STATIC_LIBNAME_SUFFIX}
VERSION ${LIBRARY_VERSION}
PUBLIC_HEADER ""
PRIVATE_HEADER ""
)
target_link_libraries(arkmathStatic ${ARKMATH_LINK_LIBS})
list(APPEND INSTALLED_TARGETS arkmathStatic)
# shared library
if (WITH_BUILD_SHARED)
add_library(arkmathShared STATIC ${generalSources})
add_dependencies(arkmathShared boost-numeric-bindings)
set_target_properties(arkmathShared PROPERTIES
OUTPUT_NAME arkmath
VERSION ${LIBRARY_VERSION}
SOVERSION ${LIBRARY_SOVERSION}
PUBLIC_HEADER ""
PRIVATE_HEADER ""
)
target_link_libraries(arkmathShared ${ARKMATH_LINK_LIBS})
list(APPEND INSTALLED_TARGETS arkmathShared)
endif()
# generated files/ headers install
install(FILES ${generalHeaders} DESTINATION include/${PROJECT_NAME} COMPONENT Dev)
install(FILES ${gen_cppHeaders} DESTINATION include/${PROJECT_NAME}/gen_cpp COMPONENT Dev)
install(FILES ${gen_fortranHeaders} DESTINATION include/${PROJECT_NAME}/gen_fortran COMPONENT Dev)
install(FILES ${gen_sciHeaders} DESTINATION include/${PROJECT_NAME}/gen_sciHeaders COMPONENT Dev)
# testing
if (WITH_BUILD_TESTING AND LAPACK_FOUND)
add_executable(ins ins.cpp)
target_link_libraries(ins arkmathStatic)
endif ()
# install
install(TARGETS ${INSTALLED_TARGETS}
RUNTIME DESTINATION "bin" COMPONENT Runtime
LIBRARY DESTINATION "lib" COMPONENT Runtime
ARCHIVE DESTINATION "lib" COMPONENT Dev
BUNDLE DESTINATION "/Applications" 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
)
### packaging
# set icns file containing icons
if (APPLE)
# set how it shows up in Info.plist
set(MACOSX_BUNDLE_ICON_FILE arkmath.icns)
# set where in the bundle to put the icns file
set_source_files_properties(cmake/arkmath.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
# include the icns file in the target
#list(APPEND ARKMATH_TEST_SRCS cmake/arkmath.icns)
endif(APPLE)
# set NSIS image
if (WIN32)
# nsis bug requuires atleast one file with 4 slashes to install correctly
set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}\\\\/cmake/arkmath-nsis.bmp")
endif(WIN32)
# add file extensions and set resource files
configure_file("COPYING" "COPYING.txt" COPYONLY)
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 math 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")
set(CPACK_PACKAGE_EXECUTABLES
#"cmd" "Command Line"
#"gui" "Gui"
)
include(CPack)
# pkgconfig
configure_file(pc.in ${PROJECT_NAME}.pc)
install(FILES
${PROJECT_BINARY_DIR}/${PROJECT_NAME}.pc
DESTINATION "lib/pkgconfig" COMPONENT Dev
)
# vim:sw=4:ts=4:expandtab