-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
356 lines (319 loc) · 12.1 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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
project (arkosg CXX C)
# settings
cmake_minimum_required (VERSION 2.8)
set(PROJECT_VERSION_MAJOR "0")
set(PROJECT_VERSION_MINOR "3")
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.1.0")
# third party libraries
set(BOOST_REQUIRED_VERSION "1.42.0")
set(QT_REQUIRED_VERSION "4.6.3")
# options
option(WITH_BUILD_DEPS "Build dependencies." OFF)
option(WITH_PREFER_STATIC "Build preferring static linking." ON)
option(WITH_BUILD_TESTS "Build a test application with QT" OFF)
option(WITH_BUILD_SHARED "Build shared library." OFF)
option(WITH_BUNDLE "Build executables." OFF)
option(WITH_WARNINGS "Enable warnings." OFF)
# variables
set(ROOT_THREAD TRUE CACHE INTERNAL "Is this the top level of the recursion?")
# 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)
# 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}"
"-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")
# static libraries
if (WITH_PREFER_STATIC)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME 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
find_package(Qt4 ${QT_REQUIRED_VERSION} REQUIRED)
find_package(OpenGL REQUIRED)
find_package(OpenSceneGraph ${OPENSCENEGRAPH_REQUIRED_VERSION} REQUIRED COMPONENTS osgViewer osgUtil osgDB osgGA osgManipulator)
if(NOT MSVC)
find_package(OsgPlugin ${OPENSCENEGRAPH_REQUIRED_VERSION} ${REQUIRED_IF_ROOT_THREAD} COMPONENTS ac rgb)
endif()
if(MSVC)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost ${BOOST_REQUIRED_VERSION} REQUIRED COMPONENTS thread system)
elseif(MINGW)
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()
# 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}
)
# none currently
# 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 Dev)
# build settings
set(QT_USE_QTOPENGL TRUE)
add_definitions(-DBOOST_THREAD_USE_LIB)
if (WITH_PREFER_STATIC OR MINGW)
add_definitions(-DOSG_LIBRARY_STATIC)
endif()
if(APPLE)
set(CMAKE_OSX_ARCHITECTURES "i386;ppc;x86_64" CACHE STRING "Build architectures for OSX" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "-framework cocoa -framework carbon")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden")
endif()
if (MSVC)
add_definitions( -D_USE_MATH_DEFINES)
endif()
include( ${QT_USE_FILE})
add_definitions(-DUSE_QT4)
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()
include_directories(
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src
${CMAKE_BINARY_DIR}
${OPENSCENEGRAPH_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${QT_INCLUDE_DIRS}
${OPENGL_INCLUDE_DIR}
)
link_directories(
${OPENSCENEGRAPH_LIBRARY_DIRS}
${QT_LIBRARY_DIR}
)
# install data files
install(DIRECTORY "data/images" DESTINATION share/${PROJECT_NAME} COMPONENT Runtime PATTERN "*.git*" EXCLUDE)
install(DIRECTORY "data/models" DESTINATION share/${PROJECT_NAME} COMPONENT Runtime PATTERN "*.git*" EXCLUDE)
# arkosg library
set(ARKOSG_SRCS
src/osgUtils.cpp
src/Viewer.cpp
src/terrain.cpp
)
set(ARKOSG_HDRS
src/osgUtils.hpp
src/Viewer.hpp
src/terrain_coords.h
src/terrain_normals.h
src/terrain_texcoords.h
)
if(QT_FOUND)
list(APPEND ARKOSG_SRCS
src/QOSGAdapterWidget.cpp
)
list(APPEND ARKOSG_HDRS
src/QOSGAdapterWidget.hpp
)
endif()
# install headers
install(FILES ${ARKOSG_HDRS} DESTINATION include/arkosg COMPONENT Dev)
# link libraries
set(ARKOSG_LINK_LIBRARIES
${Boost_LIBRARIES}
${OSGPLUGIN_LIBRARIES}
${OPENSCENEGRAPH_LIBRARIES}
${OPENGL_LIBRARIES}
${QT_LIBRARIES}
)
if(MINGW)
list(APPEND ARKOSG_LINK_LIBRARIES
lcms
lzma
)
endif()
# static library
add_library(arkosgStatic STATIC ${ARKOSG_SRCS} ${ARKOSG_HDRS})
set(ARKOSG_STATIC_LIBNAME "arkosg")
if (MSVC)
set(ARKOSG_STATIC_LIBNAME "arkosgStatic")
endif()
set_target_properties(arkosgStatic PROPERTIES
OUTPUT_NAME ${ARKOSG_STATIC_LIBNAME}
VERSION ${LIBRARY_VERSION}
)
install(TARGETS arkosgStatic
ARCHIVE DESTINATION "lib" COMPONENT Runtime
)
if (MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /FORCE:Multiple")
# for some strange reason /EHsc needs to be set twice
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
SET_TARGET_PROPERTIES(arkosgStatic PROPERTIES COMPILER_FLAGS "/EHsc")
endif()
# shared library
if (WITH_BUILD_SHARED)
add_library(arkosgShared SHARED ${ARKOSG_SRCS} ${ARKOSG_HDRS})
set_target_properties(arkosgShared PROPERTIES
OUTPUT_NAME arkosg
VERSION ${LIBRARY_VERSION}
SOVERSION ${LIBRARY_SOVERSION}
FRAMEWORK ON
)
target_link_libraries(arkosgShared ${ARKOSG_LINK_LIBRARIES})
install(TARGETS arkosgShared
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/arkosg" COMPONENT Runtime
PUBLIC_HEADER DESTINATION "include/arkosg" COMPONENT Runtime
RESOURCE DESTINATION "share/arkosg" COMPONENT Runtime
)
endif()
# test
if (WITH_BUILD_TESTS)
set(ARKOSG_TEST_MOC_SCRS
test/MainWindow.hpp
)
qt4_wrap_cpp(ARKOSG_TEST_MOC ${ARKOSG_TEST_MOC_SCRS})
set(ARKOSG_TEST_UI_SRCS
test/MainWindow.ui
)
qt4_wrap_ui(ARKOSG_TEST_UI ${ARKOSG_TEST_UI_SRCS})
set(ARKOSG_TEST_RES_SRCS
)
qt4_add_resources(ARKOSG_TEST_RES ${ARKOSG_TEST_RES_SRCS})
set(ARKOSG_TEST_SRC
test/MainWindow.cpp
test/main.cpp
${ARKOSG_TEST_MOC}
${ARKOSG_TEST_UI}
${ARKOSG_TEST_RES}
)
if (MSVC)
add_executable(arkosgTest ${ARKOSG_TEST_SRC})
else()
add_executable(arkosgTest WIN32 MACOSX_BUNDLE ${ARKOSG_TEST_SRC})
endif()
target_link_libraries(arkosgTest arkosgStatic ${ARKOSG_LINK_LIBRARIES})
install(TARGETS arkosgTest
RUNTIME DESTINATION "bin" COMPONENT Runtime
BUNDLE DESTINATION "/Applications" COMPONENT Runtime
)
if(APPLE)
add_custom_command(TARGET arkosgTest POST_BUILD COMMAND macdeployqt ${CMAKE_BINARY_DIR}/arkosgTest.app)
add_custom_command(TARGET arkosgTest POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory /opt/local/lib/Resources/qt_menu.nib ${CMAKE_BINARY_DIR}/arkosgTest.app/Contents/Resources/qt_menu.nib)
endif()
endif()
### packaging
# bundle dependencies
if (WITH_BUILD_TESTS AND WITH_BUNDLE)
set(APPS "\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/arkosgTest") # paths to executables
INSTALL(CODE "
set(DIRS \"${QT_LIBRARY_DIR}\") # directories to search for prerequisites
message(STATUS \"DIRS: \${DIRS}\")
file(GLOB_RECURSE QTPLUGINS
\"${QT_PLUGINS_DIR}/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
include(BundleUtilities)
fixup_bundle(\"${APPS}\" \"\${QTPLUGINS}\" \"\${DIRS}\")
" COMPONENT Runtime)
endif()
# set icns file containing icons
if (APPLE)
# set how it shows up in Info.plist
set(MACOSX_BUNDLE_ICON_FILE arkosg.icns)
# set where in the bundle to put the icns file
set_source_files_properties(cmake/arkosg.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
# include the icns file in the target
list(APPEND ARKOSG_TEST_SRCS cmake/arkosg.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/arkosg-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 osg 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_DEBIAN_PACKAGE_DEPENDS "libstdc++6, libgcc1, libc6, libgl1-mesa-glx")
if (WITH_BUILD_TESTS)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libqtcore4, libqtgui4, libxcb1, libqt4-opengl")
endif()
set(CPACK_PACKAGE_EXECUTABLES
#"cmd" "Command Line"
#"gui" "Gui"
)
if (WITH_BUILD_TESTS)
list(APPEND CPACK_PACKAGE_EXECUTABLES "arkosgTest" "test")
endif()
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