diff --git a/hellocardboard-android/CMakeLists.txt b/hellocardboard-android/CMakeLists.txt index 8a19995..8c02f8c 100644 --- a/hellocardboard-android/CMakeLists.txt +++ b/hellocardboard-android/CMakeLists.txt @@ -12,7 +12,8 @@ # 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) @@ -20,24 +21,25 @@ 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) diff --git a/hellocardboard-android/build.gradle b/hellocardboard-android/build.gradle index 882ea92..061e6c2 100644 --- a/hellocardboard-android/build.gradle +++ b/hellocardboard-android/build.gradle @@ -36,6 +36,9 @@ android { externalNativeBuild.cmake { path "CMakeLists.txt" } + buildFeatures { + prefab true + } namespace 'com.google.cardboard' } @@ -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) diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index c70925b..c397622 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -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(.) @@ -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 @@ -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" ) diff --git a/sdk/build.gradle b/sdk/build.gradle index 4955ae7..2c540e4 100644 --- a/sdk/build.gradle +++ b/sdk/build.gradle @@ -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' @@ -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' }