-
Notifications
You must be signed in to change notification settings - Fork 58
/
CMakeLists.txt
251 lines (221 loc) · 10.3 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
cmake_minimum_required(VERSION 3.5)
project(SlicerVirtualReality)
#-----------------------------------------------------------------------------
# Extension meta-information
set(EXTENSION_HOMEPAGE "https://github.com/KitwareMedical/SlicerVirtualReality")
set(EXTENSION_CATEGORY "Virtual Reality")
set(EXTENSION_CONTRIBUTORS "Jean-Baptiste Vimort (Kitware), Jean-Christophe Fillion-Robin (Kitware), Csaba Pinter (PerkLab, Queen's University), Adam Rankin (VASST Lab, Robarts Research Institute, Western University)")
set(EXTENSION_DESCRIPTION "Allows user to interact with a Slicer scene using virtual reality.")
set(EXTENSION_ICONURL "https://raw.githubusercontent.com/KitwareMedical/SlicerVirtualReality/master/SlicerVirtualReality.png")
set(EXTENSION_SCREENSHOTURLS "https://www.slicer.org/slicerWiki/images/4/49/SlicerVirtualReality_Screenshot1.png https://www.slicer.org/slicerWiki/images/0/04/SlicerVirtualReality_Screenshot2.png")
set(EXTENSION_DEPENDS "NA") # Specified as a space separated string, a list or 'NA' if any
#-----------------------------------------------------------------------------
set(EXTENSION_BUILD_SUBDIRECTORY inner-build)
set(SUPERBUILD_TOPLEVEL_PROJECT inner)
#-----------------------------------------------------------------------------
# Extension dependencies
find_package(Slicer REQUIRED)
include(${Slicer_USE_FILE})
mark_as_superbuild(Slicer_DIR)
find_package(Git REQUIRED)
mark_as_superbuild(GIT_EXECUTABLE)
#-----------------------------------------------------------------------------
# Options
# OpenVR
set(_default ON)
set(_reason)
if(NOT DEFINED SlicerVirtualReality_HAS_OPENVR_SUPPORT AND APPLE)
set(_default OFF)
set(_reason " (OpenVR not supported on macOS)")
endif()
option(SlicerVirtualReality_HAS_OPENVR_SUPPORT "Build OpenVR XR backend" ${_default})
mark_as_superbuild(SlicerVirtualReality_HAS_OPENVR_SUPPORT)
message(STATUS "")
message(STATUS "Setting SlicerVirtualReality_HAS_OPENVR_SUPPORT to ${SlicerVirtualReality_HAS_OPENVR_SUPPORT}${_reason}")
message(STATUS "")
# OpenXR
set(_default ON)
if(NOT DEFINED SlicerVirtualReality_HAS_OPENXR_SUPPORT AND APPLE)
set(_default OFF)
set(_reason " (OpenXR not supported on macOS)")
endif()
option(SlicerVirtualReality_HAS_OPENXR_SUPPORT "Build OpenXR XR backend" ${_default})
mark_as_superbuild(SlicerVirtualReality_HAS_OPENXR_SUPPORT)
message(STATUS "")
message(STATUS "Setting SlicerVirtualReality_HAS_OPENXR_SUPPORT to ${SlicerVirtualReality_HAS_OPENXR_SUPPORT}${_reason}")
message(STATUS "")
# OpenXRRemoting
set(_default OFF)
set(_reason)
if(NOT DEFINED SlicerVirtualReality_HAS_OPENXRREMOTING_SUPPORT)
if(WIN32)
if(NOT SlicerVirtualReality_HAS_OPENXR_SUPPORT)
set(_default OFF)
set(_reason " (OpenXR support was disabled)")
else()
set(_default ON)
set(_reason " (OpenXRRemoting is supported on Windows)")
endif()
else()
set(_default OFF)
set(_reason " (OpenXRRemoting is not supported on this platform)")
endif()
endif()
option(SlicerVirtualReality_HAS_OPENXRREMOTING_SUPPORT "Build OpenXR Remoting support" ${_default})
mark_as_superbuild(SlicerVirtualReality_HAS_OPENXRREMOTING_SUPPORT)
message(STATUS "")
message(STATUS "Setting SlicerVirtualReality_HAS_OPENXRREMOTING_SUPPORT to ${SlicerVirtualReality_HAS_OPENXRREMOTING_SUPPORT}${_reason}")
message(STATUS "")
#-----------------------------------------------------------------------------
# SuperBuild setup
option(${EXTENSION_NAME}_SUPERBUILD "Build ${EXTENSION_NAME} and the projects it depends on." ON)
mark_as_advanced(${EXTENSION_NAME}_SUPERBUILD)
if(${EXTENSION_NAME}_SUPERBUILD)
include("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuildPrerequisites.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild.cmake")
return()
endif()
#-----------------------------------------------------------------------------
# Extension modules
add_subdirectory(VirtualReality)
## NEXT_MODULE
#-----------------------------------------------------------------------------
set(SlicerVirtualReality_CUSTOM_CONFIG "####### Expanded from \@SlicerVirtualReality_CUSTOM_CONFIG\@ #######
set(vtkRenderingVR_DIR \"${vtkRenderingVR_DIR}\")
find_package(vtkRenderingVR REQUIRED)
set(SlicerVirtualReality_HAS_OPENVR_SUPPORT ${SlicerVirtualReality_HAS_OPENVR_SUPPORT})
if(SlicerVirtualReality_HAS_OPENVR_SUPPORT)
set(vtkRenderingOpenVR_DIR \"${vtkRenderingOpenVR_DIR}\")
find_package(vtkRenderingOpenVR REQUIRED)
endif()
set(SlicerVirtualReality_HAS_OPENXR_SUPPORT ${SlicerVirtualReality_HAS_OPENXR_SUPPORT})
if(SlicerVirtualReality_HAS_OPENXR_SUPPORT)
set(vtkRenderingOpenXR_DIR \"${vtkRenderingOpenXR_DIR}\")
find_package(vtkRenderingOpenXR REQUIRED)
endif()
set(SlicerVirtualReality_HAS_OPENXRREMOTING_SUPPORT ${SlicerVirtualReality_HAS_OPENXRREMOTING_SUPPORT})
if(SlicerVirtualReality_HAS_OPENXRREMOTING_SUPPORT)
set(vtkRenderingOpenXRRemoting_DIR \"${vtkRenderingOpenXRRemoting_DIR}\")
find_package(vtkRenderingOpenXRRemoting REQUIRED)
endif()
##################################################
")
include(${Slicer_EXTENSION_GENERATE_CONFIG})
#-----------------------------------------------------------------------------
if(NOT APPLE)
set(_platform)
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
# Install OpenVR
if(SlicerVirtualReality_HAS_OPENVR_SUPPORT)
# ${OpenVR_LIBRARY} contains import library which does not have to be installed.
# Instead, the dll must be added to the package.
install(FILES ${OpenVR_LIBRARY_PATHS_LAUNCHER_BUILD}/openvr_api.dll
DESTINATION ${Slicer_THIRDPARTY_LIB_DIR}
COMPONENT RuntimeLibraries
)
endif()
# Install OpenXR (CMake < 3.21)
if(SlicerVirtualReality_HAS_OPENXR_SUPPORT AND CMAKE_VERSION VERSION_LESS "3.21")
# ${OpenXR_LIBRARY} contains import library which does not have to be installed.
# Instead, the dll must be added to the package.
set(_library "${OpenXR-SDK_LIBRARY_PATHS_LAUNCHER_BUILD}/openxr_loader.dll")
# Since the launcher settings include the placeholder <CMAKE_CFG_INTDIR>, let's
# replace if with the corresponding generator expression.
string(REPLACE "<CMAKE_CFG_INTDIR>" "$<CONFIG>" _library ${_library})
install(FILES ${_library}
DESTINATION ${Slicer_THIRDPARTY_LIB_DIR}
COMPONENT RuntimeLibraries
)
endif()
else()
# Install OpenVR
if(SlicerVirtualReality_HAS_OPENVR_SUPPORT)
install(FILES ${OpenVR_LIBRARY}
DESTINATION ${Slicer_THIRDPARTY_LIB_DIR}
COMPONENT RuntimeLibraries
)
endif()
# Install OpenXR (CMake < 3.21)
if(SlicerVirtualReality_HAS_OPENXR_SUPPORT AND CMAKE_VERSION VERSION_LESS "3.21")
find_package(OpenXR REQUIRED)
string(TOUPPER ${CMAKE_BUILD_TYPE} _config)
get_target_property(_imported_library OpenXR::openxr_loader IMPORTED_LOCATION_${_config})
if(_imported_library)
install(FILES ${_imported_library}
DESTINATION ${Slicer_INSTALL_THIRDPARTY_LIB_DIR}
COMPONENT RuntimeLibraries
)
message(STATUS "Adding install rule for ${_imported_library}")
else()
message(WARNING "Failed to retrieve OpenXR library imported location: OpenXR library will not be installed.")
endif()
endif()
endif()
# Install OpenXR (CMake >= 3.21)
if(SlicerVirtualReality_HAS_OPENXR_SUPPORT AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.21")
find_package(OpenXR REQUIRED)
install(IMPORTED_RUNTIME_ARTIFACTS OpenXR::openxr_loader
RUNTIME DESTINATION ${Slicer_INSTALL_THIRDPARTY_BIN_DIR} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${Slicer_INSTALL_THIRDPARTY_LIB_DIR} COMPONENT RuntimeLibraries
)
endif()
endif()
#-----------------------------------------------------------------------------
set(EXTENSION_CPACK_INSTALL_CMAKE_PROJECTS)
# vtkRenderingVR
list(APPEND EXTENSION_CPACK_INSTALL_CMAKE_PROJECTS "${vtkRenderingVR_DIR};vtkRenderingVR;runtime;/")
if(Slicer_USE_PYTHONQT)
list(APPEND EXTENSION_CPACK_INSTALL_CMAKE_PROJECTS "${vtkRenderingVR_DIR};vtkRenderingVR;python;/")
endif()
# vtkRenderingOpenVR
if(SlicerVirtualReality_HAS_OPENVR_SUPPORT)
list(APPEND EXTENSION_CPACK_INSTALL_CMAKE_PROJECTS "${vtkRenderingOpenVR_DIR};vtkRenderingOpenVR;runtime;/")
if(Slicer_USE_PYTHONQT)
list(APPEND EXTENSION_CPACK_INSTALL_CMAKE_PROJECTS "${vtkRenderingOpenVR_DIR};vtkRenderingOpenVR;python;/")
endif()
endif()
# vtkRenderingOpenXR
if(SlicerVirtualReality_HAS_OPENXR_SUPPORT)
list(APPEND EXTENSION_CPACK_INSTALL_CMAKE_PROJECTS "${vtkRenderingOpenXR_DIR};vtkRenderingOpenXR;runtime;/")
if(Slicer_USE_PYTHONQT)
list(APPEND EXTENSION_CPACK_INSTALL_CMAKE_PROJECTS "${vtkRenderingOpenXR_DIR};vtkRenderingOpenXR;python;/")
endif()
endif()
# vtkRenderingOpenXRRemoting
if(SlicerVirtualReality_HAS_OPENXRREMOTING_SUPPORT)
list(APPEND EXTENSION_CPACK_INSTALL_CMAKE_PROJECTS "${vtkRenderingOpenXRRemoting_DIR};vtkRenderingOpenXRRemoting;runtime;/")
if(Slicer_USE_PYTHONQT)
list(APPEND EXTENSION_CPACK_INSTALL_CMAKE_PROJECTS "${vtkRenderingOpenXRRemoting_DIR};vtkRenderingOpenXRRemoting;python;/")
endif()
# OpenXRRemoting: RemotingXR.json and companion files are copied or installed along side the
# vtkRenderingRemotingOpenXR library so that "vtkOpenXRManagerRemoteConnection::Initialize()"
# can locate the files and set the XR_RUNTIME_JSON env. variable
set(OpenXRRemoting_FILES )
if(WIN32)
set(OpenXRRemoting_FILES
Microsoft.Holographic.AppRemoting.OpenXr.dll
Microsoft.Holographic.AppRemoting.OpenXr.SU.dll
PerceptionDevice.dll
RemotingXR.json
)
endif()
set(_dest ${CMAKE_BINARY_DIR}/${Slicer_THIRDPARTY_BIN_DIR})
foreach(file IN LISTS OpenXRRemoting_FILES)
# Copy
message(STATUS "Copying ${file} to ${_dest}")
file(COPY ${OpenXRRemoting_BIN_DIR}/${file}
DESTINATION ${_dest}
USE_SOURCE_PERMISSIONS
)
# Install
install(FILES ${OpenXRRemoting_BIN_DIR}/${file}
DESTINATION ${Slicer_INSTALL_THIRDPARTY_LIB_DIR}
COMPONENT RuntimeLibraries
)
endforeach()
endif()
set(${EXTENSION_NAME}_CPACK_INSTALL_CMAKE_PROJECTS "${EXTENSION_CPACK_INSTALL_CMAKE_PROJECTS}" CACHE STRING "List of external projects to install" FORCE)
#-----------------------------------------------------------------------------
list(APPEND CPACK_INSTALL_CMAKE_PROJECTS "${CMAKE_BINARY_DIR};${EXTENSION_NAME};ALL;/")
list(APPEND CPACK_INSTALL_CMAKE_PROJECTS "${${EXTENSION_NAME}_CPACK_INSTALL_CMAKE_PROJECTS}")
include(${Slicer_EXTENSION_CPACK})