-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
254 lines (212 loc) · 8.25 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
# -----------------------------------------------------------------------------
# SimpleOculusRift
# -----------------------------------------------------------------------------
# Processing Wrapper for the Oculus Rift library
# http://github.com/xohm/SimpleOculusRift
# --------------------------------------------------------------------------
# prog: Max Rheiner / Interaction Design / zhdk / http://iad.zhdk.ch/
# date: 06/24/2014 (m/d/y)
# ----------------------------------------------------------------------------
#
# this envVar should be set:
# OPEN_NI_INCLUDE < set this on osx: export OPEN_NI_INCLUDE=...path
# OPEN_NI_LIB
# JAVA_HOME
#
# -----------------------------------------------------------------------------
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
INCLUDE(CheckIncludeFiles)
PROJECT(SimpleOculusRift)
IF(NOT MACH_ARCH)
# default 64bit
SET(MACH_ARCH "64")
ENDIF()
# -----------------------------------------------------------------------------
# check swig
FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})
# -----------------------------------------------------------------------------
# check java/jni
FIND_PACKAGE(Java REQUIRED)
FIND_PACKAGE(JNI REQUIRED)
INCLUDE_DIRECTORIES(${JAVA_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${JAVA_INCLUDE_PATH2})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
# -----------------------------------------------------------------------------
# java tools
IF(WIN32)
SET(JAVA_RUNTIME2 $ENV{JAVA_HOME}/bin/java)
SET(JAVA_ARCHIVE2 $ENV{JAVA_HOME}/bin/jar)
SET(JAVA_COMPILE2 $ENV{JAVA_HOME}/bin/javac)
SET(JAVA_DOC $ENV{JAVA_HOME}/bin/javadoc)
ELSE()
# unix
SET(JAVA_RUNTIME2 java)
SET(JAVA_ARCHIVE2 jar)
SET(JAVA_COMPILE2 javac)
SET(JAVA_DOC javadoc)
ENDIF()
# -----------------------------------------------------------------------------
# boost
FIND_PACKAGE(Boost REQUIRED)
IF(Boost_INCLUDE_DIRS MATCHES "Boost_INCLUDE_DIR-NOTFOUND")
MESSAGE("Boost should be set, for example:")
MESSAGE("> cmake -DBOOST_ROOT=/usr/??? ..")
ELSE()
INCLUDE_DIRECTORIES ( ${Boost_INCLUDE_DIRS} )
LINK_DIRECTORIES ( ${Boost_LIBRARY_DIRS} )
IF(APPLE)
# osx
set(Boost_LIBRARIES "boost_system-mt")
ELSEIF(UNIX)
# unix/linux,shared libs of boost should be installed
#set(Boost_LIBRARIES "boost_thread.a")
set(Boost_LIBRARIES "boost_system")
ELSE()
# windows will find the right libs by itself
LINK_DIRECTORIES ( ${BOOST_LIBRARYDIR} )
ENDIF()
ENDIF()
# -----------------------------------------------------------------------------
# oculus rift
INCLUDE_DIRECTORIES(${OCULUSRIFT_DIR}/LibOVR/Include)
IF(APPLE)
# osx
LINK_DIRECTORIES(${OCULUSRIFT_DIR}/LibOVR/Lib/MacOS/Release)
ELSEIF(UNIX)
# unix/linux,shared libs of boost should be installed
LINK_DIRECTORIES(${OCULUSRIFT_DIR}/LibOVR/Lib/Linux/Release/x86_64)
ELSE()
# windows will find the right libs by itself
LINK_DIRECTORIES ( ${xxxxxxxx} )
ENDIF()
SET(LIBS ${LIBS} ovr)
# Oculus SDK dependencies for Mac OSX:
IF (APPLE)
FIND_LIBRARY (CORE_FOUNDATION CoreFoundation)
FIND_LIBRARY (CORE_GRAPHICS CoreGraphics)
FIND_LIBRARY (IOKIT IOKit)
ENDIF()
# -----------------------------------------------------------------------------
# glew
SET(LIBS ${LIBS} GLEW)
FIND_PACKAGE(OpenGL REQUIRED)
# -----------------------------------------------------------------------------
# swig
SET(CMAKE_SWIG_FLAGS -package SimpleOculusRift)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
###############################################################################
# set local libraries
LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/lib)
SET(CMAKE_SKIP_RPATH NO)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
IF(APPLE)
# osx
SET(CMAKE_INSTALL_RPATH "/$ORIGIN/./osx")
ELSEIF(UNIX)
IF(${MACH_ARCH} MATCHES "64")
SET(CMAKE_INSTALL_RPATH "$ORIGIN/linux64")
ELSE()
SET(CMAKE_INSTALL_RPATH "/$ORIGIN/./linux32")
ENDIF()
ELSEIF(WIN32)
# no rpath on windows
#SET(CMAKE_INSTALL_RPATH "/$ORIGIN")
ENDIF()
# -----------------------------------------------------------------------------
# processing wrappers
SET(P5_WRAPPER ${CMAKE_CURRENT_SOURCE_DIR}/src/p5_src/)
SET(P5_WRAPPER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/p5_src/SimpleOculusRift.java)
# processing core lib
# shoud use find_program
IF(WIN32)
SET(P5_JAR "C:/Program Files (x86)/processing-1.2.1/lib/core.jar")
ELSEIF(APPLE)
IF(NOT DEFINED P5_JAR)
SET(P5_JAR "/Applications/Processing.app/Contents/Resources/Java/core.jar")
ENDIF()
ELSE()
# unix/linux
# SET(P5_JAR "/?")
IF(NOT DEFINED P5_JAR)
MESSAGE("Set P5_JAR to the folder where Processing installed the core.jar file, for example:")
MESSAGE(FATAL_ERROR "> cmake -DP5_JAR=/usr/???/core.jar ..")
ENDIF()
ENDIF()
# -----------------------------------------------------------------------------
# eigen 3d template lib
IF(DEFINED EIGEN3D_INCLUDE)
INCLUDE_DIRECTORIES(${EIGEN3D_INCLUDE})
ELSE()
# check if the envvar is set
SET(EIGEN3D_INCLUDE $ENV{EIGEN3D_INCLUDE})
IF(DEFINED EIGEN3D_INCLUDE)
INCLUDE_DIRECTORIES(${EIGEN3D_INCLUDE})
ELSE()
MESSAGE("EIGEN3D_INCLUDE should be set, for example:")
MESSAGE("> cmake -DEIGEN3D_INCLUDE=/usr/??? ..")
ENDIF()
ENDIF()
SET(SWIG_SOURCES
src/SimpleOculusRiftMain.i
src/ContextWrapper.cpp
src/ocululsRiftShader.cpp
)
SET_SOURCE_FILES_PROPERTIES(${SWIG_SOURCES} PROPERTIES CPLUSPLUS ON)
# set the folder where the swig files should land
SET(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}/swig_src)
MAKE_DIRECTORY(${CMAKE_CURRENT_BINARY_DIR}/src)
IF(APPLE)
SET(LIBS ${LIBS} ${CORE_FOUNDATION} ${CORE_GRAPHICS} ${IOKIT} ${OPENGL_LIBRARIES} "-framework ApplicationServices")
ELSEIF(UNIX)
SET(LIBS ${LIBS} udev pthread GL X11 Xinerama)
ENDIF()
SWIG_ADD_MODULE(SimpleOculusRift Java ${SWIG_SOURCES})
SWIG_LINK_LIBRARIES(SimpleOculusRift ${JAVA_LIBRARIES} ${Boost_LIBRARIES} ${LIBS})
SET(CMAKE_SHARED_LINKER_FLAGS "-fPIC")
# set the arch extension for the lib
IF(NOT APPLE)
IF(${MACH_ARCH} MATCHES "64")
#64bit
message("set 64bit extension")
SET(NEW_SUFFIX "64")
ELSE()
# 32bit
message("set 32bit extension")
SET(NEW_SUFFIX "32")
ENDIF()
IF(WIN32)
SET(NEW_SUFFIX ${NEW_SUFFIX}.dll)
ELSE()
# unix linux
SET(NEW_SUFFIX ${NEW_SUFFIX}.so)
ENDIF()
SET_TARGET_PROPERTIES(SimpleOculusRift PROPERTIES SUFFIX ${NEW_SUFFIX})
ENDIF()
# only for linux
IF(UNIX)
IF(${MACH_ARCH} MATCHES "32")
SET_TARGET_PROPERTIES(SimpleOculusRift PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
ENDIF()
ENDIF()
ADD_CUSTOM_COMMAND(TARGET SimpleOculusRift
POST_BUILD
COMMAND cmake -E echo "-----------------------------"
COMMAND cmake -E echo "Compiling Java files..."
COMMAND cmake -E make_directory ./SimpleOculusRift
COMMAND cmake -E make_directory ${CMAKE_SWIG_OUTDIR}
#COMMAND cmake -E copy_directory ${P5_WRAPPER} ${CMAKE_SWIG_OUTDIR}
# cmake copy doesn't support wildcards, otherwise it just copies the hidden folder of svn, etc.
# doesn't works on windows backslash
COMMAND cp "${P5_WRAPPER}*.java" "${CMAKE_SWIG_OUTDIR}"
#COMMAND cmake -E copy ${P5_WRAPPER_FILE} ${CMAKE_SWIG_OUTDIR}
COMMAND ${JAVA_COMPILE2} -classpath ${P5_JAR} ${CMAKE_SWIG_OUTDIR}/*.java -d ./
COMMAND cmake -E echo "-----------------------------"
COMMAND cmake -E echo "Creating jar file..."
COMMAND ${JAVA_ARCHIVE2} cvf SimpleOculusRift.jar SimpleOculusRift
COMMAND cmake -E echo "-----------------------------"
COMMAND cmake -E echo "Creating doc files..."
COMMAND cmake -E make_directory ./doc
#COMMAND ${JAVA_DOC} -quiet -author -public -nodeprecated -nohelp -d ./doc -version ${P5_WRAPPER}/*.java -version ${CMAKE_SWIG_OUTDIR}/ContextWrapper.java)
COMMAND ${JAVA_DOC} -classpath ${P5_JAR} -quiet -author -public -nodeprecated -nohelp -d ./doc -version ${CMAKE_SWIG_OUTDIR}/*.java)