Skip to content

Commit

Permalink
Refactor the project structure
Browse files Browse the repository at this point in the history
- Consolidate all the vendors modules into a single `godotopenxr` module with multiple vendors product flavors to allow for vendor-specific customizations
- Add `GodotOpenXR.kt` to consolidate common java/kotlin logic for the OpenXR vendors plugin implementations
- Move native code from the `common` directory to the `godotopenxr/src/main/cpp` directory
  • Loading branch information
m4gr3d committed Sep 9, 2024
1 parent 50f1a08 commit c8c935a
Show file tree
Hide file tree
Showing 114 changed files with 336 additions and 692 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ local.properties

# Misc
.DS_Store
/common/src/gen/
/godotopenxr/src/gen/
12 changes: 6 additions & 6 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ opts.Update(env)

# Add common includes
env.Append(CPPPATH=[
"#common/src/main/cpp/include/",
"#godotopenxr/src/main/cpp/include/",
"#thirdparty/openxr/include/",
])

sources = []
sources += Glob("#common/src/main/cpp/*.cpp")
sources += Glob("#common/src/main/cpp/export/*.cpp")
sources += Glob("#common/src/main/cpp/extensions/*.cpp")
sources += Glob("#common/src/main/cpp/classes/*.cpp")
sources += Glob("#godotopenxr/src/main/cpp/*.cpp")
sources += Glob("#godotopenxr/src/main/cpp/export/*.cpp")
sources += Glob("#godotopenxr/src/main/cpp/extensions/*.cpp")
sources += Glob("#godotopenxr/src/main/cpp/classes/*.cpp")

if env["target"] in ["editor", "template_debug"]:
doc_data = env.GodotCPPDocData("#common/src/gen/doc_data.gen.cpp", source=Glob("doc_classes/*.xml"))
doc_data = env.GodotCPPDocData("#godotopenxr/src/gen/doc_data.gen.cpp", source=Glob("doc_classes/*.xml"))
sources.append(doc_data)

binary_path = '#demo/addons/godotopenxrvendors/.bin'
Expand Down
12 changes: 2 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ task clean(type: Delete) {
dependsOn 'cleanAddon'
dependsOn 'cleanBuildFromSamples'

dependsOn ':godotopenxrkhronos:clean'
dependsOn ':godotopenxrlynx:clean'
dependsOn ':godotopenxrmeta:clean'
dependsOn ':godotopenxrpico:clean'
dependsOn ':godotopenxr:clean'
}

/**
Expand All @@ -51,12 +48,7 @@ task cleanAddon(type: Delete) {
task buildPlugin {
// Generate the editor gdextension binaries
dependsOn ':buildSconsArtifacts'

dependsOn ":godotopenxrkhronos:build"
dependsOn ":godotopenxrlynx:build"
dependsOn ":godotopenxrmeta:build"
dependsOn ":godotopenxrpico:build"

dependsOn ":godotopenxr:build"
finalizedBy "copyBuildToSamples"
}

Expand Down
22 changes: 12 additions & 10 deletions config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ ext {
}

// Parse the release version from the gradle project properties (e.g: -Prelease_version=<version>)
ext.getReleaseVersion = { ->
final String defaultVersion = "3.0.0-dev-SNAPSHOT"
ext {
getReleaseVersion = { ->
final String defaultVersion = "3.1.0-dev-SNAPSHOT"

String releaseVersion = project.hasProperty("release_version") ? project.property("release_version") : defaultVersion
if (releaseVersion == null || releaseVersion.isEmpty()) {
releaseVersion = defaultVersion
}
String releaseVersion = project.hasProperty("release_version") ? project.property("release_version") : defaultVersion
if (releaseVersion == null || releaseVersion.isEmpty()) {
releaseVersion = defaultVersion
}

if (!releaseVersion.endsWithIgnoreCase("-stable") && !releaseVersion.endsWithIgnoreCase("-snapshot")) {
releaseVersion += "-SNAPSHOT"
}
if (!releaseVersion.endsWithIgnoreCase("-stable") && !releaseVersion.endsWithIgnoreCase("-snapshot")) {
releaseVersion += "-SNAPSHOT"
}

return releaseVersion
return releaseVersion
}
}
File renamed without changes.
21 changes: 8 additions & 13 deletions godotopenxrpico/CMakeLists.txt → godotopenxr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,34 @@ cmake_minimum_required(VERSION 3.22.1)
project(godotopenxrvendors LANGUAGES CXX)

## Common dependencies
include(${PROJECT_SOURCE_DIR}/../common/common.cmake)
include(${PROJECT_SOURCE_DIR}/src/main/common.cmake)

## khronos OpenXR loader library
find_package(OpenXR REQUIRED CONFIG)

## Setup the project sources
file(GLOB_RECURSE ANDROID_SOURCES ${PROJECT_SOURCE_DIR}/src/main/cpp/*.c**)
file(GLOB_RECURSE ANDROID_HEADERS ${PROJECT_SOURCE_DIR}/src/main/cpp/*.h**)
## Flavor dependencies
include(src/${FLAVOR}/${FLAVOR}.cmake)

add_library(${PROJECT_NAME}
SHARED
${ANDROID_SOURCES}
${ANDROID_HEADERS}
${COMMON_LIB_SOURCES}
${COMMON_LIB_HEADERS}
)
)

target_include_directories(${PROJECT_NAME}
SYSTEM PUBLIC
${GODOT_CPP_INCLUDE_DIRECTORIES}
${OPENXR_HEADERS_DIR}
${VENDOR_HEADERS_DIR}
${COMMON_LIB_HEADERS_DIR}
)
)

target_link_libraries(${PROJECT_NAME}
android
log
${GODOT-CPP}
OpenXR::openxr_loader
)
${OPENXR_LOADER}
)

# 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})

add_definitions(-DPICO_VENDOR_ENABLED)
74 changes: 67 additions & 7 deletions godotopenxrpico/build.gradle → godotopenxr/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

ext {
PUBLISH_ARTIFACT_ID = 'godot-openxr-vendors-pico'
PUBLISH_ARTIFACT_ID = 'godot-openxr-vendors'
}

apply from: "../scripts/publish-module.gradle"
Expand All @@ -30,7 +30,47 @@ android {
}
}

namespace = "org.godotengine.openxr.vendors.pico"
namespace = "org.godotengine.openxr.vendors"

flavorDimensions = ["vendor"]
productFlavors {
khronos {
dimension "vendor"
ndk {
//noinspection ChromeOsAbiSupport
abiFilters 'arm64-v8a', 'x86_64'
}
externalNativeBuild {
cmake {
arguments "-DFLAVOR=khronos"
}
}
}
lynx {
dimension "vendor"
externalNativeBuild {
cmake {
arguments "-DFLAVOR=lynx"
}
}
}
meta {
dimension "vendor"
externalNativeBuild {
cmake {
arguments "-DFLAVOR=meta"
}
}
}
pico {
dimension "vendor"
externalNativeBuild {
cmake {
arguments "-DFLAVOR=pico"
}
}
}
}

packagingOptions {
doNotStrip '**/*.so'
Expand All @@ -46,7 +86,22 @@ android {
}

publishing {
singleVariant("release") {
singleVariant("khronosRelease") {
withSourcesJar()
withJavadocJar()
}

singleVariant("lynxRelease") {
withSourcesJar()
withJavadocJar()
}

singleVariant("metaRelease") {
withSourcesJar()
withJavadocJar()
}

singleVariant("picoRelease") {
withSourcesJar()
withJavadocJar()
}
Expand All @@ -59,14 +114,19 @@ android {

prefab {
godotopenxrvendors {
headers "../common/src/main/cpp/include"
headers "src/main/cpp/include"
}
}
}

dependencies {
compileOnly libraries.godotAndroidLib
implementation "org.khronos.openxr:openxr_loader_for_android:$versions.openxrVersion"

// Khronos dependencies
khronosImplementation "org.khronos.openxr:openxr_loader_for_android:$versions.openxrVersion"

// Pico dependencies
picoImplementation "org.khronos.openxr:openxr_loader_for_android:$versions.openxrVersion"
}

task cleanAssets(type: Delete) {
Expand All @@ -80,13 +140,13 @@ task cleanCxx(type: Delete) {

task copyDebugAARToAddons(type: Copy) {
from 'build/outputs/aar'
include 'godotopenxrpico-debug.aar'
include 'godotopenxr-*-debug.aar'
into '../demo/addons/godotopenxrvendors/.bin/android/debug'
}

task copyReleaseAARToAddons(type: Copy) {
from 'build/outputs/aar'
include 'godotopenxrpico-release.aar'
include 'godotopenxr-*-release.aar'
into '../demo/addons/godotopenxrvendors/.bin/android/release'
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@

package org.godotengine.openxr.vendors.khronos

import android.util.Log
import org.godotengine.godot.Godot
import org.godotengine.godot.plugin.GodotPlugin
import org.godotengine.openxr.vendors.GodotOpenXR

/**
* \brief GodotOpenXRKhronos is the OpenXR Khronos plugin for Godot.
Expand All @@ -49,22 +48,11 @@ import org.godotengine.godot.plugin.GodotPlugin
* https://registry.khronos.org/OpenXR/specs/1.0/html/xrspec.html#android-runtime-category
*
*/
class GodotOpenXRKhronos(godot: Godot?) : GodotPlugin(godot) {
class GodotOpenXRKhronos(godot: Godot?) : GodotOpenXR(godot) {
companion object {
private val TAG = GodotOpenXRKhronos::class.java.simpleName

init {
try {
Log.v(TAG, "Loading godotopenxrvendors library")
System.loadLibrary("godotopenxrvendors")
} catch (e: UnsatisfiedLinkError) {
Log.e(TAG, "Unable to load godotopenxrvendors shared library")
}
}
}

override fun getPluginGDExtensionLibrariesPaths() = setOf("res://addons/godotopenxrvendors/plugin.gdextension")

override fun getPluginName(): String {
return "GodotOpenXRKhronos"
}
Expand Down
13 changes: 13 additions & 0 deletions godotopenxr/src/khronos/khronos.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.22.1)

## khronos OpenXR loader library
find_package(OpenXR REQUIRED CONFIG)

set(VENDOR_HEADERS_DIR "")
set(OPENXR_LOADER "OpenXR::openxr_loader")

## Setup the project sources
file(GLOB_RECURSE ANDROID_SOURCES ${CMAKE_CURRENT_LIST_DIR}/cpp/*.c**)
file(GLOB_RECURSE ANDROID_HEADERS ${CMAKE_CURRENT_LIST_DIR}/cpp/*.h**)

add_definitions(-DKHRONOS_VENDOR_ENABLED)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,17 @@

package org.godotengine.openxr.vendors.lynx

import android.util.Log
import org.godotengine.godot.Godot
import org.godotengine.godot.plugin.GodotPlugin
import org.godotengine.openxr.vendors.GodotOpenXR

/**
* \brief GodotOpenXRLynx is the OpenXR Lynx plugin for Godot.
*/
class GodotOpenXRLynx(godot: Godot?) : GodotPlugin(godot) {
class GodotOpenXRLynx(godot: Godot?) : GodotOpenXR(godot) {
companion object {
private val TAG = GodotOpenXRLynx::class.java.simpleName

init {
try {
Log.v(TAG, "Loading godotopenxrvendors library")
System.loadLibrary("godotopenxrvendors")
} catch (e: UnsatisfiedLinkError) {
Log.e(TAG, "Unable to load godotopenxrvendors shared library")
}
}
}

override fun getPluginGDExtensionLibrariesPaths() = setOf("res://addons/godotopenxrvendors/plugin.gdextension")

override fun getPluginName(): String {
return "GodotOpenXRLynx"
}
Expand Down
18 changes: 18 additions & 0 deletions godotopenxr/src/lynx/lynx.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.22.1)

## lynx OpenXR loader library
set(LYNX_OPENXR_LIB_PATH "${CMAKE_CURRENT_LIST_DIR}/../../../thirdparty/lynx_openxr_sdk/${ANDROID_ABI}/libopenxr_loader.so")
add_library(openxr_loader
SHARED
IMPORTED GLOBAL
)
set_target_properties(openxr_loader PROPERTIES IMPORTED_LOCATION ${LYNX_OPENXR_LIB_PATH})

set(VENDOR_HEADERS_DIR "")
set(OPENXR_LOADER "openxr_loader")

## Setup the project sources
file(GLOB_RECURSE ANDROID_SOURCES ${CMAKE_CURRENT_LIST_DIR}/cpp/*.c**)
file(GLOB_RECURSE ANDROID_HEADERS ${CMAKE_CURRENT_LIST_DIR}/cpp/*.h**)

add_definitions(-DLYNX_VENDOR_ENABLED)
File renamed without changes.
10 changes: 5 additions & 5 deletions common/common.cmake → godotopenxr/src/main/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ else ()
endif (CMAKE_BUILD_TYPE MATCHES Debug)

## godot-cpp library
set(GODOT_CPP_DIR "${CMAKE_CURRENT_LIST_DIR}/../thirdparty/godot-cpp")
set(GODOT_CPP_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../thirdparty/godot-cpp")
set(GODOT-CPP "godot-cpp")

# Use the godot-cpp prebuilt static binary
Expand All @@ -116,11 +116,11 @@ set_target_properties(${GODOT-CPP} PROPERTIES IMPORTED_LOCATION ${GODOT_CPP_STAT


## OpenXR headers
set(OPENXR_HEADERS_DIR "${CMAKE_CURRENT_LIST_DIR}/../thirdparty/openxr/include")
set(OPENXR_HEADERS_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../thirdparty/openxr/include")


# Common lib
set(COMMON_LIB_HEADERS_DIR ${CMAKE_CURRENT_LIST_DIR}/../common/src/main/cpp/include)
set(COMMON_LIB_HEADERS_DIR ${CMAKE_CURRENT_LIST_DIR}/cpp/include)

file(GLOB_RECURSE COMMON_LIB_SOURCES ${CMAKE_CURRENT_LIST_DIR}/../common/src/main/cpp/*.c**)
file(GLOB_RECURSE COMMON_LIB_HEADERS ${CMAKE_CURRENT_LIST_DIR}/../common/src/main/cpp/*.h**)
file(GLOB_RECURSE COMMON_LIB_SOURCES ${CMAKE_CURRENT_LIST_DIR}/cpp/*.c**)
file(GLOB_RECURSE COMMON_LIB_HEADERS ${CMAKE_CURRENT_LIST_DIR}/cpp/*.h**)
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ String OpenXREditorExportPlugin::_get_name() const {

String OpenXREditorExportPlugin::_get_android_aar_file_path(bool debug) const {
const String debug_label = debug ? "debug" : "release";
return "res://addons/godotopenxrvendors/.bin/android/" + debug_label + "/godotopenxr" + _vendor + "-" + debug_label + ".aar";
return "res://addons/godotopenxrvendors/.bin/android/" + debug_label + "/godotopenxr-" + _vendor + "-" + debug_label + ".aar";
}

String OpenXREditorExportPlugin::_get_android_maven_central_dependency() const {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit c8c935a

Please sign in to comment.