forked from GodotVR/godot_oculus_mobile
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
151 lines (119 loc) · 5.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
cmake_minimum_required(VERSION 3.6)
# Default android abi is arm64-v8a
if (NOT ANDROID_ABI)
set(ANDROID_ABI "arm64-v8a")
endif (NOT ANDROID_ABI)
# Default android platform is android-23
if (NOT ANDROID_PLATFORM)
set(ANDROID_PLATFORM "android-23")
endif (NOT ANDROID_PLATFORM)
# Default build type is Debug
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif (NOT CMAKE_BUILD_TYPE)
if (CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-D_DEBUG)
set(VRAPI_LIB_BUILD_TYPE Debug)
else ()
add_definitions(-DNDEBUG)
set(VRAPI_LIB_BUILD_TYPE Release)
endif (CMAKE_BUILD_TYPE MATCHES Debug)
if (NOT (ANDROID_STL STREQUAL "c++_shared"))
set(ANDROID_STL "c++_shared")
endif (NOT (ANDROID_STL STREQUAL "c++_shared"))
# Check if ANDROID_NDK is set.
if (NOT ANDROID_NDK)
# Set to ANDROID_NDK_HOME environment variable if it's set.
if (DEFINED ENV{ANDROID_NDK_HOME})
set(ANDROID_NDK $ENV{ANDROID_NDK_HOME})
else (DEFINED ENV{ANDROID_NDK_HOME})
message(WARNING "ANDROID_NDK_HOME is not set")
endif (DEFINED ENV{ANDROID_NDK_HOME})
endif (NOT ANDROID_NDK)
# Check if CMAKE_TOOLCHAIN_FILE is set.
if (NOT CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "${ANDROID_NDK}/build/cmake/android.toolchain.cmake")
endif (NOT CMAKE_TOOLCHAIN_FILE)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
project(godot_ovrmobile)
# Set the default output directory.
if (NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/release/addons/${CMAKE_PROJECT_NAME}/libs/${ANDROID_ABI}")
endif (NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
# Create the default output directory if necessary.
if (NOT (EXISTS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}))
file(MAKE_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
endif (NOT (EXISTS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}))
###############################################################################
## PROJECT SETUP
## The variables below should be updated based on the setup instructions
## in the project README.
# Sets the path to the VrApi containing directory. Update this variable if the api is in another location.
set(OVR_ROOT_DIR "${CMAKE_SOURCE_DIR}/ovr_sdk_mobile")
set(OVR_MRC_DIR "${CMAKE_SOURCE_DIR}/ovr_sdk_mobile/OVRMrcShimLib")
set(OVR_MRC_HEADERS_DIR "${OVR_MRC_DIR}/Include")
# Location to the Godot headers directory. The default location is "${CMAKE_SOURCE_DIR}/godot_headers"
set(GODOT_HEADERS_DIR "${CMAKE_SOURCE_DIR}/godot_headers")
###############################################################################
set(OVR_HEADERS_DIR "${OVR_ROOT_DIR}/VrApi/Include" CACHE STRING "")
set(GODOT_COMPILE_FLAGS)
set(GODOT_LINKER_FLAGS)
set(GODOT_LINKER_FLAGS "-Wl")
set(GODOT_COMPILE_FLAGS "-fPIC -g -Wwrite-strings")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wchar-subscripts -Wcomment -Wdisabled-optimization")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wformat -Wformat=2 -Wformat-security -Wformat-y2k")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wimport -Winit-self -Winline -Winvalid-pch")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wlong-long -Wmissing-braces -Wmissing-format-attribute")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wpointer-arith")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wredundant-decls -Wreturn-type -Wsequence-point")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wswitch -Wswitch-enum -Wtrigraphs")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wuninitialized -Wunknown-pragmas -Wunreachable-code -Wunused-label")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wunused-value -Wvariadic-macros -Wvolatile-register-var -Wno-error=attributes")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -fno-omit-frame-pointer -O0")
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wno-ignored-attributes")
endif ()
if (CMAKE_BUILD_TYPE MATCHES Debug)
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -fno-omit-frame-pointer -O0")
else ()
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -O3")
endif (CMAKE_BUILD_TYPE MATCHES Debug)
# OVR library
set(VRAPI_LIB_PATH "${OVR_ROOT_DIR}/VrApi/Libs/Android/${ANDROID_ABI}/${VRAPI_LIB_BUILD_TYPE}/libvrapi.so")
add_library(vrapi SHARED IMPORTED GLOBAL)
set_target_properties(vrapi PROPERTIES IMPORTED_LOCATION ${VRAPI_LIB_PATH})
set(OVR_MRC_LIB_PATH "${OVR_MRC_DIR}/Lib/${ANDROID_ABI}/libOVRMrcLib.so")
# Get Sources
file(GLOB_RECURSE SOURCES src/*.c**)
file(GLOB_RECURSE HEADERS src/*.h**)
add_library(${PROJECT_NAME}
SHARED
${SOURCES} ${HEADERS})
target_include_directories(${PROJECT_NAME}
PRIVATE
src
)
# Put godot headers as SYSTEM PUBLIC to exclude warnings from irrelevant headers
target_include_directories(${PROJECT_NAME}
SYSTEM PUBLIC
${GODOT_HEADERS_DIR}
${OVR_HEADERS_DIR}
${OVR_MRC_HEADERS_DIR}
)
target_link_libraries(${PROJECT_NAME}
android
log
EGL
GLESv3
vrapi)
# Add the compile flags
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${GODOT_COMPILE_FLAGS})
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS ${GODOT_LINKER_FLAGS})
# Copy the VrApi shared library to the output directory.
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${VRAPI_LIB_PATH} $<TARGET_FILE_DIR:${PROJECT_NAME}>)
set(BITS 32)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BITS 64)
endif (CMAKE_SIZEOF_VOID_P EQUAL 8)