Skip to content

Commit

Permalink
Migrate the export scripts from gdscript to C++ via gdextension
Browse files Browse the repository at this point in the history
  • Loading branch information
m4gr3d committed Dec 4, 2023
1 parent 3e0f4e5 commit 3d9cdde
Show file tree
Hide file tree
Showing 61 changed files with 1,977 additions and 730 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/build-addon-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ jobs:
- name: Create Godot-CPP library
run: |
cd aar/thirdparty/godot-cpp
scons platform=${{ matrix.platform }} target=template_debug ${{ matrix.flags }}
scons platform=${{ matrix.platform }} target=template_release ${{ matrix.flags }}
scons platform=${{ matrix.platform }} target=template_debug arch=arm64
scons platform=${{ matrix.platform }} target=template_release arch=arm64
scons platform=${{ matrix.platform }} target=template_debug arch=x86_64
scons platform=${{ matrix.platform }} target=template_release arch=x86_64
cd ../../..
if: matrix.platform == 'android'
- name: Create Godot OpenXR Vendors AARs
Expand Down Expand Up @@ -130,7 +132,7 @@ jobs:
- name: Adding vendor licences
run: |
cp aar/godotopenxrmeta/LICENSE.txt asset/addons/godotopenxrvendors/meta/
cp aar/godotopenxrpico/src/main/jniLibs/arm64-v8a/README.md asset/addons/godotopenxrvendors/pico/LICENSE.md
cp aar/godotopenxrpico/libs/pico_openxr_sdk/arm64-v8a/README.md asset/addons/godotopenxrvendors/pico/LICENSE.md
cp aar/godotopenxrkhronos/LICENSE asset/addons/godotopenxrvendors/khronos/LICENSE
- name: Copying artifacts
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/mavencentral-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ jobs:
- name: Release build
run: |
cd thirdparty/godot-cpp
scons platform=android target=template_debug -j4
scons platform=android target=template_release -j4
scons platform=android target=template_debug arch=arm64
scons platform=android target=template_release arch=arm64
scons platform=android target=template_debug arch=x86_64
scons platform=android target=template_release arch=x86_64
cd ../..
./gradlew -Prelease_version=${{ github.ref_name }} build
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ local.properties
# Binaries
*.o
*.os
*.so
*.obj
*.bc
*.pyc
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change history for the Godot OpenXR loaders asset

## 2.1.0
- Migrate the export scripts from gdscript to C++ via gdextension

## 2.0.0
- Update to the new Godot 4.2 Android plugin packaging format
- Update the plugin to Godot v2 Android plugin
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ the end of the SCons command line where `N` is the number of CPU threads you hav
The example below uses 4 threads.
```
cd thirdparty/godot-cpp
scons target=template_debug -j4
scons target=template_release -j4
scons platform=android target=template_debug -j4
scons platform=android target=template_release -j4
scons platform=android target=template_debug arch=arm64 -j4
scons platform=android target=template_debug arch=arm32 -j4
scons platform=android target=template_debug arch=x86_64 -j4
scons platform=android target=template_debug arch=x86_32 -j4
scons platform=android target=template_release arch=arm64 -j4
scons platform=android target=template_release arch=arm32 -j4
scons platform=android target=template_release arch=x86_64 -j4
scons platform=android target=template_release arch=x86_32 -j4
```

When the command is completed, you should have static libraries stored in `thirdparty/godot-cpp/bin`
Expand Down Expand Up @@ -77,9 +81,6 @@ If you have build the asset from source, you need to create the `addons` folder
if it doesn't exist already, and then copy the content of the `demo/addons` folder to `addons`
in your project.

Once the asset is added to your project, navigate to `Project` -> `Project Settings...` -> `Plugins`
and enable the plugin.

### Configuring your export

Back in Godot open the `Project` menu and select `Export...`:
Expand Down
51 changes: 11 additions & 40 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,18 @@ env = SConscript("thirdparty/godot-cpp/SConstruct")
opts = Variables('custom.py')
opts.Update(env)

# Add source files.
# Add common includes
env.Append(CPPPATH=[
# Meta includes
"godotopenxrmeta/src/main/cpp",
"godotopenxrmeta/src/main/cpp/include",
"godotopenxrmeta/libs/ovr_openxr_mobile_sdk/OpenXR/Include",
# Common includes
"thirdparty/openxr/include/",
"#common/src/main/cpp",
"#thirdparty/openxr/include/",
])

# Meta source files
sources = Glob("godotopenxrmeta/src/main/cpp/*.cpp")
common_objects = []
common_objects.append(env.SharedObject(Glob("#common/src/main/cpp/export/*.cpp")))

meta_binary_path = 'demo/addons/godotopenxrvendors/meta/.bin'
meta_project_name = 'godotopenxrmeta'

# Create the library target
if env["platform"] == "android":
print("Use gradle to generate the Android binaries")
Exit(255)
elif env["platform"] == "macos":
meta_library = env.SharedLibrary(
"{0}/lib{1}.{2}.{3}.framework/{1}.{2}.{3}".format(
meta_binary_path,
meta_project_name,
env["platform"],
env["target"],
),
source=sources,
)
else:
meta_library = env.SharedLibrary(
"{}/lib{}.{}.{}.{}{}".format(
meta_binary_path,
meta_project_name,
env["platform"],
env["target"],
env["arch"],
env["SHLIBSUFFIX"],
),
source=sources,
)

Default(meta_library)
SConscript([
"godotopenxrmeta/SConstruct",
"godotopenxrpico/SConstruct",
"godotopenxrlynx/SConstruct",
"godotopenxrkhronos/SConstruct",
], 'env common_objects')
70 changes: 70 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ else ()
set(GODOT_CPP_LIB_ABI "arm64")
endif ()

# Default android platform is android-21
if (NOT ANDROID_PLATFORM)
set(ANDROID_PLATFORM "android-21")
endif (NOT ANDROID_PLATFORM)

if (NOT (ANDROID_STL STREQUAL "c++_shared"))
set(ANDROID_STL "c++_shared")
endif (NOT (ANDROID_STL STREQUAL "c++_shared"))

# Default build type is Debug
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
Expand All @@ -32,9 +41,63 @@ else ()
set(OPENXR_MOBILE_LIB_BUILD_TYPE Release)
endif (CMAKE_BUILD_TYPE MATCHES Debug)

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

if (NOT DEFINED BITS)
set(BITS 32)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BITS 64)
endif (CMAKE_SIZEOF_VOID_P EQUAL 8)
endif (NOT DEFINED BITS)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)


project(common LANGUAGES CXX)

add_definitions(-DANDROID)

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")

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)

## godot-cpp library
set(GODOT_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../thirdparty/godot-cpp")
set(GODOT-CPP "godot-cpp")
Expand All @@ -56,3 +119,10 @@ set_target_properties(${GODOT-CPP} PROPERTIES IMPORTED_LOCATION ${GODOT_CPP_STAT

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


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

file(GLOB_RECURSE COMMON_LIB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../common/src/main/cpp/*.c**)
file(GLOB_RECURSE COMMON_LIB_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../common/src/main/cpp/*.h**)
Loading

0 comments on commit 3d9cdde

Please sign in to comment.