forked from chai3d/chai3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
255 lines (219 loc) · 11 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
# Software License Agreement (BSD License)
# Copyright (c) 2003-2016, CHAI3D.
# (www.chai3d.org)
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
#
# * Neither the name of CHAI3D nor the names of its contributors may
# be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# $Author: seb $
# $Date: 2016-11-01 19:39:15 +0100 (Tue, 01 Nov 2016) $
# $Rev: 2152 $
#
# configuration
#
cmake_minimum_required (VERSION 3.0.0)
project (CHAI3D)
# version info
file (READ ${PROJECT_SOURCE_DIR}/src/version VERSION)
STRING (REGEX REPLACE ".*MAJOR=([0-9]+).*" "\\1" MAJOR_VERSION "${VERSION}")
STRING (REGEX REPLACE ".*MINOR=([0-9]+).*" "\\1" MINOR_VERSION "${VERSION}")
STRING (REGEX REPLACE ".*RELEASE=([0-9]+).*" "\\1" RELEASE_VERSION "${VERSION}")
set (PROJECT_VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${RELEASE_VERSION})
# platform detection
if (${CMAKE_SYSTEM_NAME} MATCHES Windows)
set (OS "win")
if (${CMAKE_CL_64})
set (ARCH "x64")
else ()
set (ARCH "Win32")
endif ()
elseif (${CMAKE_SYSTEM_NAME} MATCHES Linux)
set (OS "lin")
if (${CMAKE_SIZEOF_VOID_P} EQUAL 8)
set (ARCH "x86_64")
else ()
set (ARCH "i686")
endif ()
elseif (${CMAKE_SYSTEM_NAME} MATCHES Darwin)
set (OS "mac")
set (ARCH "x86_64")
endif ()
# enforce build type
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Release CACHE STRING "Setting build mode to Release" FORCE)
endif()
# output location
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/${OS}-${ARCH})
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/bin/${OS}-${ARCH})
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${PROJECT_SOURCE_DIR}/bin/${OS}-${ARCH})
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/bin/${OS}-${ARCH})
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_SOURCE_DIR}/bin/${OS}-${ARCH})
# OpenGL dependency
find_package (OpenGL REQUIRED)
include_directories (OPENGL_INCLUDE_DIR)
# on non-Windows, DHD dependency
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES Windows)
include_directories (${PROJECT_SOURCE_DIR}/external/DHD/include)
if(${CMAKE_GENERATOR} STREQUAL Xcode)
set (DHD_LIBRARY_DIRS ${PROJECT_SOURCE_DIR}/external/DHD/lib/${OS})
else()
set (DHD_LIBRARY_DIRS ${PROJECT_SOURCE_DIR}/external/DHD/lib/${OS}-${ARCH})
endif()
link_directories (${DHD_LIBRARY_DIRS})
endif ()
# Windows global build options
if (${CMAKE_SYSTEM_NAME} MATCHES Windows)
# VisualStudio compiler
if (MSVC)
add_definitions (-D_CRT_SECURE_NO_DEPRECATE)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP")
if (${CMAKE_CL_64})
add_definitions (-DWIN64)
else ()
add_definitions (-DWIN32)
endif ()
# MinGW compiler
elseif (MINGW)
add_definitions (-DWIN32)
add_definitions (-DHAVE_GCC_DESTRUCTOR)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wno-deprecated -std=c++0x")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -Wno-deprecated")
endif ()
# Linux global build options
elseif (${CMAKE_SYSTEM_NAME} MATCHES Linux)
add_definitions (-DLINUX)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -march=native -Wno-deprecated -std=c++0x")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -march=native -Wno-deprecated")
# Mac OS X global build options
elseif (${CMAKE_SYSTEM_NAME} MATCHES Darwin)
add_definitions (-DMACOSX)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -Wno-deprecated -std=c++0x -stdlib=libc++")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -Wno-deprecated")
endif ()
#
# static library
#
# header search path
include_directories (${PROJECT_SOURCE_DIR}/src)
include_directories (${PROJECT_SOURCE_DIR}/external/Eigen)
include_directories (${PROJECT_SOURCE_DIR}/external/glew/include)
include_directories (${PROJECT_SOURCE_DIR}/external/giflib/include)
include_directories (${PROJECT_SOURCE_DIR}/external/lib3ds/include)
include_directories (${PROJECT_SOURCE_DIR}/external/libjpeg/include)
include_directories (${PROJECT_SOURCE_DIR}/external/libpng/include)
include_directories (${PROJECT_SOURCE_DIR}/external/openal/include)
include_directories (${PROJECT_SOURCE_DIR}/external/openal/OpenAL32/Include)
include_directories (${PROJECT_SOURCE_DIR}/external/openal/Alc)
include_directories (${PROJECT_SOURCE_DIR}/external/pugixml/include)
include_directories (${PROJECT_SOURCE_DIR}/external/theoraplayer/include/theoraplayer)
include_directories (${PROJECT_SOURCE_DIR}/external/theoraplayer/external/ogg/include)
include_directories (${PROJECT_SOURCE_DIR}/external/theoraplayer/external/theora/include)
include_directories (${PROJECT_SOURCE_DIR}/external/theoraplayer/external/vorbis/include)
include_directories (${PROJECT_SOURCE_DIR}/external/theoraplayer/external/vorbis/lib)
include_directories (${PROJECT_SOURCE_DIR}/external/theoraplayer/src/Theora)
# static library source files
file (GLOB_RECURSE source RELATIVE ${CHAI3D_SOURCE_DIR} ${CHAI3D_SOURCE_DIR}/src/*.cpp ${CHAI3D_SOURCE_DIR}/src/*.h)
# static library external dependencies source files
file (GLOB_RECURSE source_eigen RELATIVE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/external/Eigen/Eigen/*)
file (GLOB_RECURSE source_gif RELATIVE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/external/giflib/*.c ${PROJECT_SOURCE_DIR}/external/giflib/*.h)
file (GLOB_RECURSE source_glew RELATIVE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/external/glew/*.c ${PROJECT_SOURCE_DIR}/external/glew/*.h)
file (GLOB_RECURSE source_3ds RELATIVE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/external/lib3ds/*.c ${PROJECT_SOURCE_DIR}/external/lib3ds/*.h)
file (GLOB_RECURSE source_jpeg RELATIVE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/external/libjpeg/*.c ${PROJECT_SOURCE_DIR}/external/libjpeg/*.h)
file (GLOB_RECURSE source_png RELATIVE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/external/libpng/*.c ${PROJECT_SOURCE_DIR}/external/libpng/*.h)
file (GLOB_RECURSE source_pugixml RELATIVE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/external/pugixml/*.c ${PROJECT_SOURCE_DIR}/external/pugixml/*.h)
file (GLOB_RECURSE source_openal RELATIVE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/external/openal/*.c ${PROJECT_SOURCE_DIR}/external/openal/*.h)
file (GLOB_RECURSE source_theora RELATIVE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/external/theoraplayer/*.c ${PROJECT_SOURCE_DIR}/external/theoraplayer/*.cpp ${PROJECT_SOURCE_DIR}/external/theoraplayer/*.h)
# platform-specific source files adjustments
if (${CMAKE_SYSTEM_NAME} MATCHES Windows)
file (GLOB_RECURSE source_theora_exclude RELATIVE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/external/theoraplayer/external/theora/lib/x86/*.c)
else ()
file (GLOB_RECURSE source_theora_exclude RELATIVE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/external/theoraplayer/external/theora/lib/x86_vc/*.c)
endif ()
list (REMOVE_ITEM source_theora ${source_theora_exclude})
# group source files (MSVC likes this)
foreach (FILE ${source} ${source_eigen} ${source_gif} ${source_glew} ${source_3ds} ${source_jpeg} ${source_png} ${source_pugixml} ${source_openal} ${source_theora})
get_filename_component (PARENT_DIR "${FILE}" PATH)
string (REGEX REPLACE "(\\./)?(src|include)/?" "" GROUP "${PARENT_DIR}")
string (REPLACE "/" "\\" GROUP "${GROUP}")
source_group ("${GROUP}" FILES "${FILE}")
endforeach ()
# build flags
add_definitions (${PROJECT_DEFINITIONS} -DGLEW_STATIC -DAL_ALEXT_PROTOTYPES -DAL_BUILD_LIBRARY -DAL_LIBTYPE_STATIC -D__THEORA -D_LIB)
# static library
add_library (chai3d STATIC ${source} ${source_eigen} ${source_gif} ${source_glew} ${source_3ds} ${source_jpeg} ${source_png} ${source_pugixml} ${source_openal} ${source_theora})
# library exports
set (CHAI3D_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src" "${PROJECT_SOURCE_DIR}/external/Eigen" "${PROJECT_SOURCE_DIR}/external/glew/include" "${OPENGL_INCLUDE_DIR}")
set (CHAI3D_LIBRARIES chai3d ${OPENGL_LIBRARIES})
set (CHAI3D_DEFINITIONS ${PROJECT_DEFINITIONS})
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES Windows)
set (CHAI3D_LIBRARIES ${CHAI3D_LIBRARIES} drd)
set (CHAI3D_LIBRARY_DIRS ${CHAI3D_LIBRARY_DIRS} ${DHD_LIBRARY_DIRS})
else ()
set (CHAI3D_LIBRARIES ${CHAI3D_LIBRARIES} winmm)
endif ()
if (${OS} MATCHES lin)
set (CHAI3D_LIBRARIES ${CHAI3D_LIBRARIES} usb-1.0 rt pthread dl)
elseif (${OS} MATCHES mac)
set (CHAI3D_LIBRARIES ${CHAI3D_LIBRARIES} "-framework CoreFoundation" "-framework IOKit" "-framework CoreServices" "-framework CoreAudio" "-framework AudioToolbox" "-framework AudioUnit")
endif ()
set (CHAI3D_SOURCE_DIR ${PROJECT_SOURCE_DIR})
#
# optional extras
#
# GLFW
if (EXISTS ${PROJECT_SOURCE_DIR}/extras/GLFW)
add_subdirectory (${PROJECT_SOURCE_DIR}/extras/GLFW)
endif ()
#
# executables
#
# examples
if (EXISTS ${PROJECT_SOURCE_DIR}/examples)
add_subdirectory (${PROJECT_SOURCE_DIR}/examples)
endif ()
# utilities
if (EXISTS ${PROJECT_SOURCE_DIR}/utils)
add_subdirectory (${PROJECT_SOURCE_DIR}/utils)
endif ()
#
# export package
#
# export package for use from the build tree
export (TARGETS chai3d FILE ${PROJECT_BINARY_DIR}/CHAI3DTargets.cmake)
export (PACKAGE CHAI3D)
# package definitions
set (CONF_INCLUDE_DIRS ${CHAI3D_INCLUDE_DIRS})
set (CONF_LIBRARIES ${CHAI3D_LIBRARIES})
set (CONF_LIBRARY_DIRS ${CHAI3D_LIBRARY_DIRS})
set (CONF_DEFINITIONS ${CHAI3D_DEFINITIONS})
set (CONF_SOURCE_DIR ${CHAI3D_SOURCE_DIR})
# package configuration and version files
configure_file (CHAI3DConfig.cmake.in "${PROJECT_BINARY_DIR}/CHAI3DConfig.cmake" @ONLY)
configure_file (CHAI3DConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/CHAI3DConfigVersion.cmake" @ONLY)