Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefab #484

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions hellocardboard-android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,34 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.4.1)
cmake_minimum_required(VERSION 3.22.1)
project(hellocardboard_android VERSION 1.0.0 LANGUAGES CXX)

# C++ flags.
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
add_compile_options(-Wall -Wextra)

# Standard Android dependencies
find_library(android-lib android)
find_library(GLESv2-lib GLESv2)
find_library(GLESv3-lib GLESv3)
find_library(log-lib log)
find_library(ANDROID_LIB android)
find_library(GLESv2_LIB GLESv2)
find_library(GLESv3_LIB GLESv3)
find_library(LOG_LIB log)

# Cardboard SDK prefab
find_package(sdk REQUIRED CONFIG)

set(libs_dir ${CMAKE_CURRENT_SOURCE_DIR}/libraries)

# === Cardboard Sample ===
# Sources
file(GLOB native_srcs "src/main/jni/*.cc")
# Output binary
add_library(cardboard_jni SHARED ${native_srcs})
# Includes
target_include_directories(cardboard_jni PRIVATE ${libs_dir})
# Build
target_link_libraries(cardboard_jni
${android-lib}
${GLESv2-lib}
${GLESv3-lib}
${log-lib}
${libs_dir}/jni/${ANDROID_ABI}/libGfxPluginCardboard.so)
${ANDROID_LIB}
${GLESv2_LIB}
${GLESv3_LIB}
${LOG_LIB}
# This also adds include directories
sdk::GfxPluginCardboard)
27 changes: 3 additions & 24 deletions hellocardboard-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ android {
externalNativeBuild.cmake {
path "CMakeLists.txt"
}
buildFeatures {
prefab true
}
namespace 'com.google.cardboard'
}

Expand All @@ -49,27 +52,3 @@ dependencies {
implementation 'com.google.protobuf:protobuf-javalite:3.19.4'
implementation project(":sdk")
}

// The dependencies for NDK builds live inside the .aar files so they need to
// be extracted before NDK targets can link against.
task extractNdk(type: Copy) {
if (file("${project.rootDir}/sdk/build/outputs/aar/sdk-release.aar").exists()) {
copy {
from zipTree("${project.rootDir}/sdk/build/outputs/aar/sdk-release.aar")
into "libraries/"
include "jni/**/libGfxPluginCardboard.so"
}
copy {
from "${project.rootDir}/sdk/include/cardboard.h"
into "libraries/"
}
}
}

task deleteNdk(type: Delete) {
delete "libraries/jni"
delete "libraries/cardboard.h"
}

build.dependsOn(extractNdk)
clean.dependsOn(deleteNdk)
115 changes: 79 additions & 36 deletions sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,29 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.4.1)
cmake_minimum_required(VERSION 3.22.1)
project(cardboard_sdk VERSION 1.0.0 LANGUAGES CXX)

# C++ flags.
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
add_compile_options(-Wall -Wextra)

# If these are already defined, the existing value is used, rather then the default here.
option(CARDBOARDSDK_RENDERING_GLESv3 "Enable rendering with GLESv3" ON)
option(CARDBOARDSDK_RENDERING_VULKAN "Enable rendering with Vulkan" ON)
option(CARDBOARDSDK_UNITY_PLUGIN "Enable use as a Unity plugin" ON)

# Standard Android dependencies
find_library(android-lib android)
find_library(GLESv2-lib GLESv2)
find_library(log-lib log)
find_library(ANDROID_LIB android)
find_library(GLESv2_LIB GLESv2)
find_library(LOG_LIB log)

# #gles3 - Library is only needed if OpenGL ES 3.0 support is desired. Remove
# the following line if OpenGL ES 3.0 support is not needed.
find_library(GLESv3-lib GLESv3)
if(CARDBOARDSDK_RENDERING_GLESv3)
find_library(GLESv3_LIB GLESv3)
endif()

include_directories(.)

Expand All @@ -50,22 +58,27 @@ file(GLOB screen_params_srcs "screen_params/android/*.cc")
file(GLOB device_params_srcs "device_params/android/*.cc")
# Rendering Sources
file(GLOB rendering_opengl_srcs "rendering/opengl_*.cc")
# #vulkan This is required for Vulkan rendering. Remove the following two lines
# if Vulkan rendering is not needed.
file(GLOB rendering_vulkan_srcs "rendering/android/*.cc")
file(GLOB rendering_vulkan_wrapper_srcs "rendering/android/vulkan/*.cc")

# === Cardboard Unity JNI ===
file(GLOB cardboard_unity_jni_srcs "unity/android/*.cc")

# === Cardboard Unity Wrapper ===
file(GLOB cardboard_xr_unity_srcs
"unity/xr_unity_plugin/*.cc"
"unity/xr_unity_plugin/vulkan/*.cc"
)

# === Cardboard XR Provider for Unity ===
file(GLOB cardboard_xr_provider_srcs "unity/xr_provider/*.cc")
if(CARDBOARDSDK_RENDERING_VULKAN)
# #vulkan This is required for Vulkan rendering. Remove the following two lines
# if Vulkan rendering is not needed.
file(GLOB rendering_vulkan_srcs "rendering/android/*.cc")
file(GLOB rendering_vulkan_wrapper_srcs "rendering/android/vulkan/*.cc")
endif()

if(CARDBOARDSDK_UNITY_PLUGIN)
# === Cardboard Unity JNI ===
file(GLOB cardboard_unity_jni_srcs "unity/android/*.cc")

# === Cardboard Unity Wrapper ===
file(GLOB cardboard_xr_unity_srcs
"unity/xr_unity_plugin/*.cc"
"unity/xr_unity_plugin/vulkan/*.cc"
)

# === Cardboard XR Provider for Unity ===
file(GLOB cardboard_xr_provider_srcs "unity/xr_provider/*.cc")
endif()

# Output binary
add_library(GfxPluginCardboard SHARED
Expand All @@ -91,24 +104,54 @@ add_library(GfxPluginCardboard SHARED
# Cardboard XR Provider for Unity sources
${cardboard_xr_provider_srcs})

# Includes
target_include_directories(GfxPluginCardboard
PRIVATE ../third_party/unity_plugin_api)
if(CARDBOARDSDK_UNITY_PLUGIN)
# Includes
target_include_directories(GfxPluginCardboard
PRIVATE ../third_party/unity_plugin_api)
endif()

# #vulkan This is required for Vulkan rendering. Remove the following line if
# Vulkan rendering is not needed.
add_definitions(-DVK_USE_PLATFORM_ANDROID_KHR=1)
if(CARDBOARDSDK_RENDERING_VULKAN)
# #vulkan This is required for Vulkan rendering. Remove the following line if
# Vulkan rendering is not needed.
target_compile_definitions(GfxPluginCardboard PUBLIC VK_USE_PLATFORM_ANDROID_KHR=1)
endif()

# Build
target_link_libraries(GfxPluginCardboard
${android-lib}
${GLESv2-lib}
# #gles3 - Library is only needed if OpenGL ES 3.0 support is desired.
# Remove the following line if OpenGL ES 3.0 support is not needed.
${GLESv3-lib}
${log-lib}
# #vulkan - This is required for Vulkan rendering (it is required to load
# libvulkan.so at runtime). Remove the following line if Vulkan rendering
# is not needed
dl
PUBLIC
${ANDROID_LIB}
${GLESv2_LIB}
${LOG_LIB}
)

if(CARDBOARDSDK_RENDERING_VULKAN)
target_link_libraries(GfxPluginCardboard
PUBLIC
# #vulkan - This is required for Vulkan rendering (it is required to load
# libvulkan.so at runtime). Remove the following line if Vulkan rendering
# is not needed
dl
)
endif()

if(CARDBOARDSDK_RENDERING_GLESv3)
target_link_libraries(GfxPluginCardboard
PUBLIC
# #gles3 - Library is only needed if OpenGL ES 3.0 support is desired.
# Remove the following line if OpenGL ES 3.0 support is not needed.
${GLESv3_LIB}
)
endif()

set_property(
TARGET GfxPluginCardboard
APPEND_STRING
PROPERTY
LINK_FLAGS
" -Wl,--version-script=\"${CMAKE_CURRENT_SOURCE_DIR}/cardboard_api.lds\""
)
set_property(
TARGET GfxPluginCardboard
APPEND
PROPERTY LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cardboard_api.lds"
)
13 changes: 9 additions & 4 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ android {
minSdkVersion 26
targetSdkVersion 33
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
externalNativeBuild.cmake {
arguments "-DANDROID_STL=c++_static"
arguments "-DANDROID_STL=c++_shared"
}
defaultConfig {
consumerProguardFiles 'proguard-rules.pro'
Expand All @@ -49,6 +46,14 @@ android {
main.proto.srcDirs = ["${project.rootDir}/proto"]
main.proto.includes = ["cardboard_device.proto"]
}
buildFeatures {
prefabPublishing true
}
prefab {
GfxPluginCardboard {
headers "include"
}
}
namespace 'com.google.cardboard.sdk'
}

Expand Down