-
Notifications
You must be signed in to change notification settings - Fork 64
/
CMakeLists.txt
382 lines (305 loc) · 15.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
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
IF(WIN32)
CMAKE_MINIMUM_REQUIRED(VERSION 2.4.6 FATAL_ERROR)
ELSE()
IF(APPLE)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0 FATAL_ERROR)
ELSE()
CMAKE_MINIMUM_REQUIRED(VERSION 2.4.4 FATAL_ERROR)
ENDIF()
ENDIF()
if(COMMAND cmake_policy)
# Works around warnings libraries linked against that don't
# have absolute paths (e.g. -lpthreads)
cmake_policy(SET CMP0003 NEW)
# Works around warnings about escaped quotes in ADD_DEFINITIONS
# statements.
cmake_policy(SET CMP0005 NEW)
# cmake-2.6.1 introduces policy cmp0008 decide how to treat full path libraries that do not appear to be valid library file names
# quote from cvslog "Such libraries worked by accident in the VS IDE and Xcode generators in CMake 2.4 and below."
if(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 4 AND ${CMAKE_PATCH_VERSION} GREATER 0)
cmake_policy(SET CMP0008 OLD)
endif()
endif()
PROJECT(VirtualPlanetBuilder)
SET(VIRTUALPLANETBUILDER_MAJOR_VERSION 1)
SET(VIRTUALPLANETBUILDER_MINOR_VERSION 1)
SET(VIRTUALPLANETBUILDER_PATCH_VERSION 0)
SET(VIRTUALPLANETBUILDER_SOVERSION 30)
# set to 0 when not a release candidate, non zero means that any generated
# svn tags will be treated as release candidates of given number
SET(VIRTUALPLANETBUILDER_RELEASE_CANDIDATE 0)
SET(VIRTUALPLANETBUILDER_VERSION ${VIRTUALPLANETBUILDER_MAJOR_VERSION}.${VIRTUALPLANETBUILDER_MINOR_VERSION}.${VIRTUALPLANETBUILDER_PATCH_VERSION})
# We want to build SONAMES shared librariess
SET(VIRTUALPLANETBUILDER_SONAMES TRUE)
# We have some custom .cmake scripts not in the official distribution.
# Maybe this can be used override existing behavior if needed?
SET(CMAKE_MODULE_PATH "${VirtualPlanetBuilder_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
# Okay, here's the problem: On some platforms, linking against OpenThreads
# is not enough and explicit linking to the underlying thread library
# is also required (e.g. FreeBSD). But OpenThreads may be built with different
# backends (Pthreads, Sproc, Windows) so we don't know what the underlying
# thread library is because some platforms support multiple backends (e.g.
# IRIX supports Sproc and Pthreads). Linking all libraries won't work
# because the libraries may be incompatible.
# So the current solution is to attempt best guess linking and exempt certain
# cases. With IRIX, we're going to hope explicit linking to the underlying
# library is not necessary. We currently don't case for pthreads on Windows
# which might be an issue on things like Cygwin. This may need to be fixed.
FIND_PACKAGE(Threads)
IF(CMAKE_SYSTEM MATCHES IRIX)
# Erase CMAKE_THREAD_LIBS_INIT and hope it works
SET(CMAKE_THREAD_LIBS_INIT "" CACHE INTERNAL "")
ENDIF()
OPTION(VPB_MAINTAINER "Enable VirtualPlanetBuilder maintainer build methods, such as making svn branches, tags, updating ChangeLog." OFF)
IF (VPB_MAINTAINER)
SET(VIRTUALPLANETBUILDER_SVN "trunk")
#SET(VIRTUALPLANETBUILDER_SVN "branches")
SET(VIRTUALPLANETBUILDER_BRANCH VirtualPlanetBuilder-${VIRTUALPLANETBUILDER_MAJOR_VERSION}.${VIRTUALPLANETBUILDER_MINOR_VERSION})
#
# Provide target for tagging a release
#
SET(SVNCOMMAND svn)
SET(SVNTRUNKDIR http://svn.openscenegraph.org/VirtualPlanetBuilder/trunk)
SET(SVNTAGDIR http://svn.openscenegraph.org/VirtualPlanetBuilder/tags)
SET(SVNBRANCHDIR http://svn.openscenegraph.org/VirtualPlanetBuilder/branches)
IF (VIRTUALPLANETBUILDER_SVN STREQUAL "trunk")
SET(SVNSOURCEDIR ${SVNTRUNKDIR})
ELSE ()
SET(SVNSOURCEDIR ${SVNBRANCHDIR}/${VIRTUALPLANETBUILDER_BRANCH})
ENDIF()
IF (VIRTUALPLANETBUILDER_RELEASE_CANDIDATE EQUAL 0)
SET(RELEASE_NAME VirtualPlanetBuilder-${VIRTUALPLANETBUILDER_VERSION})
ELSE ()
SET(RELEASE_NAME VirtualPlanetBuilder-${VIRTUALPLANETBUILDER_VERSION}-rc${VIRTUALPLANETBUILDER_RELEASE_CANDIDATE})
ENDIF()
ADD_CUSTOM_TARGET(tag-test
COMMAND echo ${SVNCOMMAND} copy ${SVNSOURCEDIR} ${SVNTAGDIR}/${RELEASE_NAME} -m "Release ${RELEASE_NAME}"
)
ADD_CUSTOM_TARGET(tag-run
COMMAND ${SVNCOMMAND} copy ${SVNSOURCEDIR} ${SVNTAGDIR}/${RELEASE_NAME} -m "Release ${RELEASE_NAME}"
)
ADD_CUSTOM_TARGET(branch-test
COMMAND echo ${SVNCOMMAND} copy ${SVNSOURCEDIR} ${SVNBRANCHDIR}/${VIRTUALPLANETBUILDER_BRANCH} -m "Branch ${VIRTUALPLANETBUILDER_BRANCH}"
)
ADD_CUSTOM_TARGET(branch-run
COMMAND ${SVNCOMMAND} copy ${SVNSOURCEDIR} ${SVNBRANCHDIR}/${VIRTUALPLANETBUILDER_BRANCH} -m "Branch ${VIRTUALPLANETBUILDER_BRANCH}"
)
#
# Provide target for generating ChangeLog
#
SET(GENERATELOGS svn2cl)
ADD_CUSTOM_TARGET(ChangeLog
COMMAND ${SVNCOMMAND} update
COMMAND ${GENERATELOGS}
)
ENDIF()
# Find OpenGL
FIND_PACKAGE(OpenGL)
IF(UNIX)
# Not sure what this will do on Cygwin and Msys
# Also, remember OS X X11 is a user installed option so it may not exist.
FIND_PACKAGE(X11)
# Some Unicies need explicit linkage to the Math library or the build fails.
FIND_LIBRARY(MATH_LIBRARY m)
ENDIF()
# Make the headers visible to everything
INCLUDE_DIRECTORIES(
${VirtualPlanetBuilder_SOURCE_DIR}/include
${OPENGL_INCLUDE_DIR}
)
# Common global definitions
#ADD_DEFINITIONS(-D)
# Platform specific definitions
########################################################################################################
##### these were settings located in SetupCommon.cmake used in Luigi builds.... find out what are useful
########################################################################################################
#luigi#SET(CMAKE_VERBOSE_MAKEFILE TRUE)
#luigi#SET(CMAKE_SKIP_RPATH TRUE)
#luigi#SET(CMAKE_SKIP_RULE_DEPENDENCY TRUE)
#luigi#IF(UNIX)
#luigi# LIST_CONTAINS(contains "g++" ${CMAKE_CXX_COMPILER_LIST})
#luigi# IF (contains)
#luigi# MESSAGE(${MY_MESSAGE_DEFAULT} "${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} setting CMAKE_CXX_COMPILER to g++")
#luigi# SET(CMAKE_CXX_COMPILER "g++")
#luigi# SET(CMAKE_CXX_COMPILER_LOADED 2)
#luigi# SET(CMAKE_CXX_COMPILER_WORKS 2)
#luigi# ENDIF ()
#luigi# SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
#luigi# SET(CMAKE_CXX_FLAGS_DEBUG "-ggdb -gstabs")
#luigi#ENDIF()
########################################################################################################
# Common to all platforms:
SET(OSG_DIR "" CACHE PATH "set to base osg install path")
SET(3rdPartyRoot "" CACHE PATH "set to base 3rd party dependancy path")
SET(CMAKE_DEBUG_POSTFIX "d")
FIND_PACKAGE(OpenSceneGraph 3.0.0 REQUIRED osgDB osgFX osgUtil osgSim osgTerrain osgViewer osgGA osgText)
FIND_PACKAGE(GDAL)
################################################################################
# Create bin and lib directories if required
IF("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin ${CMAKE_BINARY_DIR}/lib)
ENDIF()
################################################################################
# Installation stuff
IF(UNIX AND NOT WIN32 AND NOT APPLE)
IF(CMAKE_SIZEOF_VOID_P MATCHES "8")
SET(LIB_POSTFIX "64" CACHE STRING "suffix for 32/64 dir placement")
MARK_AS_ADVANCED(LIB_POSTFIX)
ENDIF()
ENDIF()
IF(NOT DEFINED LIB_POSTFIX)
SET(LIB_POSTFIX "")
ENDIF()
# Here we apparantly do some funky stuff with making the bin/ and lib/
# folders which is probably needed to work around a very old CMake bug?
#SET(OUTPUT_BINDIR ${PROJECT_BINARY_DIR}/bin/${CMAKE_SYSTEM_NAME})
SET(OUTPUT_BINDIR ${PROJECT_BINARY_DIR}/bin)
MAKE_DIRECTORY(${OUTPUT_BINDIR})
SET(EXECUTABLE_OUTPUT_PATH ${OUTPUT_BINDIR})
#SET(OUTPUT_LIBDIR ${PROJECT_BINARY_DIR}/lib/${CMAKE_SYSTEM_NAME})
SET(OUTPUT_LIBDIR ${PROJECT_BINARY_DIR}/lib)
MAKE_DIRECTORY(${OUTPUT_LIBDIR})
SET(LIBRARY_OUTPUT_PATH ${OUTPUT_LIBDIR})
#SET(INSTALL_BINDIR VirtualPlanetBuilder/bin)
#SET(INSTALL_INCDIR VirtualPlanetBuilder/include)
#SET(INSTALL_LIBDIR VirtualPlanetBuilder/lib)
#SET(INSTALL_DOCDIR VirtualPlanetBuilder/doc)
################################################################################
# User Options
# Expose CMAKE_INCLUDE_PATH and CMAKE_LIBARY_PATH to the GUI so users
# may set these values without needing to manipulate the environment.
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} CACHE STRING "You may add additional search paths here. Use ; to separate multiple paths.")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} CACHE STRING "You may add additional search paths here. Use ; to separate multiple paths.")
# We are proposing that a new variable called CMAKE_PREFIX_PATH be introduced
# to CMake to compliment CMAKE_INCLUDE_PATH and CMAKE_LIBRARY_PATH.
# A formal feature request has been submited to CMake, Bug #4947.
# It is intended for those users who have common prefixes for their INCLUDE
# and LIBRARY locations. So if users have headers in /usr/local/include
# and libraries in /usr/local/lib, the common prefix is /usr/local.
# It should also cover the case where headers and libraries are
# in the same directory.
# Our proposal expects that FIND_* commands will automatically search for
# CMAKE_PREFIX_PATH right after CMAKE_INCLUDE_PATH or CMAKE_LIBRARY_PATH.
# Obviously, since CMake does not currently support this, we must write
# our Find*.cmake modules to explicitly support this. Otherwise, this variable
# will have no impact.
# This is unofficial so this may be removed or changed at anytime.
SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} CACHE STRING "(EXPERIMENTAL) You may add additional search paths here. Use ; to separate multiple paths.")
# This is for an advanced option to give aggressive warnings
# under different compilers. If yours is not implemented, this option
# will not be made available.
IF(CMAKE_COMPILER_IS_GNUCXX)
# To be complete, we might also do GNUCC flags,
# but everything here is C++ code.
# -Wshadow and -Woverloaded-virtual are also interesting flags, but OSG
# returns too many hits.
# FYI, if we do implement GNUCC, then -Wmissing-prototypes in another
# interesting C-specific flag.
# Also, there is a bug in gcc 4.0. Under C++, -pedantic will create
# errors instead of warnings for certain issues, including superfluous
# semicolons and commas, and the use of long long. -fpermissive seems
# to be the workaround.
SET(OSG_AGGRESSIVE_WARNING_FLAGS -Wall -Wparentheses -Wno-long-long -Wno-import -pedantic -Wreturn-type -Wmissing-braces -Wunknown-pragmas -Wunused -fpermissive)
# Previous included -Wformat=2 in OSG_AGGRESSIVE_WARNING_FLAGS but had to remove it due to standard library errors
ELSE()
IF(MSVC)
# FIXME: What are good aggressive warning flags for Visual Studio?
# And do we need to further subcase this for different versions of VS?
# CMake variables: MSVC60, MSVC70, MSVC71, MSVC80, CMAKE_COMPILER_2005
SET(OSG_AGGRESSIVE_WARNING_FLAGS /W4 /wd4706 /wd4127 /wd4100)
if(${MSVC_VERSION} STRGREATER 1600)
message("msvc2010 + build fix /FORCE:MULTIPLE")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /FORCE:MULTIPLE")
endif()
ELSE()
# CMake lacks an elseif, so other non-gcc, non-VS compilers need
# to be listed below. If unhandled, OSG_AGGRESSIVE_WARNING_FLAGS should
# remain unset.
ENDIF()
ENDIF()
# This part is for the CMake menu option to toggle the warnings on/off.
# This will only be made available if we set values for OSG_AGGRESSIVE_WARNING_FLAGS.
IF(OSG_AGGRESSIVE_WARNING_FLAGS)
IF (APPLE)
SET(DEFAULT_USE_AGGRESSIVE_WARNINGS OFF)
ELSE()
SET(DEFAULT_USE_AGGRESSIVE_WARNINGS ON)
ENDIF()
OPTION(OSG_USE_AGGRESSIVE_WARNINGS "Enable to activate aggressive warnings" ${DEFAULT_USE_AGGRESSIVE_WARNINGS})
MARK_AS_ADVANCED(OSG_USE_AGGRESSIVE_WARNINGS)
IF(OSG_USE_AGGRESSIVE_WARNINGS)
# Add flags defined by OSG_AGGRESSIVE_WARNING_FLAGS if they aren't already there
FOREACH(flag ${OSG_AGGRESSIVE_WARNING_FLAGS})
IF(NOT CMAKE_CXX_FLAGS MATCHES "${flag}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
ENDIF()
ENDFOREACH()
ELSE()
# Remove all flags considered aggresive
FOREACH(flag ${OSG_AGGRESSIVE_WARNING_FLAGS})
STRING(REGEX REPLACE "${flag}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
ENDFOREACH()
ENDIF()
ENDIF()
# Dynamic vs Static Linking
OPTION(DYNAMIC_VIRTUALPLANETBUILDER "Set to ON to build VIRTUALPLANETBUILDER for dynamic linking. Use OFF for static." ON)
IF (DYNAMIC_VIRTUALPLANETBUILDER)
SET(VIRTUALPLANETBUILDER_USER_DEFINED_DYNAMIC_OR_STATIC "SHARED")
ELSE ()
SET(VIRTUALPLANETBUILDER_USER_DEFINED_DYNAMIC_OR_STATIC "STATIC")
ENDIF()
INCLUDE(VpbMacroUtils)
# VPB Core
IF(NOT OSG_FOUND)
message(FATAL_ERROR "OSG was not found")
ENDIF()
IF(NOT GDAL_FOUND)
message(FATAL_ERROR "GDAL was not found")
ENDIF()
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(applications)
# Set defaults for Universal Binaries. We want 32-bit Intel/PPC on 10.4
# and 32/64-bit Intel/PPC on >= 10.5. Anything <= 10.3 doesn't support.
IF(APPLE)
# These are just defaults/recommendations, but how we want to build
# out of the box. But the user needs to be able to change these options.
# So we must only set the values the first time CMake is run, or we
# will overwrite any changes the user sets.
# FORCE is used because the options are not reflected in the UI otherwise.
# Seems like a good place to add version specific compiler flags too.
IF(NOT VPB_CONFIG_HAS_BEEN_RUN_BEFORE)
# This is really fragile, but CMake doesn't provide the OS system
# version information we need. (Darwin versions can be changed
# independently of OS X versions.)
# It does look like CMake handles the CMAKE_OSX_SYSROOT automatically.
IF(EXISTS /Developer/SDKs/10.5.sdk)
SET(CMAKE_OSX_ARCHITECTURES "ppc;i386;ppc64;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)
ELSE()
IF(EXISTS /Developer/SDKs/MacOSX10.4u.sdk)
SET(CMAKE_OSX_ARCHITECTURES "ppc;i386" CACHE STRING "Build architectures for OSX" FORCE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.4 -ftree-vectorize -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE)
ELSE(EXISTS /Developer/SDKs/MacOSX10.4u.sdk)
# No Universal Binary support
# Should break down further to set the -mmacosx-version-min,
# but the SDK detection is too unreliable here.
ENDIF()
ENDIF()
ENDIF()
OPTION(VPB_BUILD_APPLICATION_BUNDLES "Enable the building of applications and examples as OSX Bundles" OFF)
ENDIF()
# This needs to be run very last so other parts of the scripts can take
# advantage of this.
IF(NOT VPB_CONFIG_HAS_BEEN_RUN_BEFORE)
SET(VPB_CONFIG_HAS_BEEN_RUN_BEFORE 1 CACHE INTERNAL "Flag to track whether this is the first time running CMake or if CMake has been configured before")
ENDIF()
#-----------------------------------------------------------------------------
### uninstall target
#-----------------------------------------------------------------------------
CONFIGURE_FILE(
"${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
ADD_CUSTOM_TARGET(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")