Skip to content

Commit

Permalink
add gdextension mode for osp
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamakaio committed Jun 24, 2024
1 parent ef2a4c2 commit 49ee950
Show file tree
Hide file tree
Showing 73 changed files with 1,285 additions and 200 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@
[submodule "3rdparty/JoltPhysics"]
path = 3rdparty/JoltPhysics
url = https://github.com/jrouwe/JoltPhysics.git
[submodule "3rdparty/godot-cpp"]
path = 3rdparty/godot-cpp
url = https://github.com/godotengine/godot-cpp
62 changes: 42 additions & 20 deletions 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ if(NOT OSP_USE_SYSTEM_SDL)
SET(SDL_VIRTUAL_JOYSTICK ON CACHE BOOL "" FORCE)

SET(LIBSAMPLERATE ON CACHE BOOL "" FORCE)
SET(LIBSAMPLERATE_SHARED ON CACHE BOOL "" FORCE)
SET(LIBSAMPLERATE_SHARED OFF CACHE BOOL "" FORCE)

SET(SDL_EVENTS ON CACHE BOOL "" FORCE)
SET(SDL_THREADS ON CACHE BOOL "" FORCE)

# This assumes you want to have SDL as a static library. If not, set SDL_STATIC
# to OFF instead.
SET(SDL_DLOPEN ON CACHE BOOL "" FORCE)
SET(SDL_SHARED ON CACHE BOOL "" FORCE)
SET(SDL_STATIC OFF CACHE BOOL "" FORCE)
SET(SDL_DLOPEN OFF CACHE BOOL "" FORCE)
SET(SDL_SHARED OFF CACHE BOOL "" FORCE)
SET(SDL_STATIC ON CACHE BOOL "" FORCE)

SET(SDL2_DISABLE_SDL2MAIN ON CACHE BOOL "" FORCE)
SET(SDL2_DISABLE_INSTALL ON CACHE BOOL "" FORCE)
Expand Down Expand Up @@ -191,6 +191,16 @@ SET(MAGNUM_WITH_SHADERS ON CACHE BOOL "" FORCE)
SET(MAGNUM_WITH_SHADERTOOLS OFF CACHE BOOL "" FORCE)
SET(MAGNUM_WITH_TESTSUITE OFF CACHE BOOL "" FORCE)
SET(MAGNUM_WITH_TEXT OFF CACHE BOOL "" FORCE)
SET(MAGNUM_WITH_GL ON CACHE BOOL "" FORCE)
SET(MAGNUM_TARGET_GL ON CACHE BOOL "" FORCE)

IF (OSP_BUILD_GDEXTENSION)
SET(MAGNUM_WITH_SDL2APPLICATION OFF CACHE BOOL "" FORCE)
SET(MAGNUM_WITH_SHADERS OFF CACHE BOOL "" FORCE)
SET(MAGNUM_WITH_GL OFF CACHE BOOL "" FORCE)
SET(MAGNUM_TARGET_GL OFF CACHE BOOL "" FORCE)
ENDIF()

ADD_SUBDIRECTORY(magnum EXCLUDE_FROM_ALL)

SET(MAGNUM_WITH_TINYGLTFIMPORTER ON CACHE BOOL "" FORCE)
Expand All @@ -208,32 +218,44 @@ ADD_SUBDIRECTORY(toml11 EXCLUDE_FROM_ALL)
SET(SPDLOG_ENABLE_PCH ON CACHE BOOL "" FORCE)
# Not yet supported by github runners
# SET(SPDLOG_USE_STD_FORMAT ON CACHE BOOL "" FORCE)
SET(SPDLOG_BUILD_PIC ON CACHE BOOL "" FORCE)
ADD_SUBDIRECTORY(spdlog EXCLUDE_FROM_ALL)
ADD_SUBDIRECTORY(longeronpp EXCLUDE_FROM_ALL)

# For Windows: Prevent overriding the parent project's compiler/linker settings
SET(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
ADD_SUBDIRECTORY(googletest EXCLUDE_FROM_ALL)

SET(FT_DISABLE_ZLIB ON CACHE BOOL "" FORCE)
SET(FT_DISABLE_BZIP2 ON CACHE BOOL "" FORCE)
SET(FT_DISABLE_PNG ON CACHE BOOL "" FORCE)
SET(FT_DISABLE_HARFBUZZ ON CACHE BOOL "" FORCE)
SET(FT_DISABLE_BROTLI ON CACHE BOOL "" FORCE)
SET(SKIP_INSTALL_ALL ON CACHE BOOL "" FORCE)
SET(SKIP_INSTALL_LIBRARIES ON CACHE BOOL "" FORCE)
SET(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE)
ADD_SUBDIRECTORY(freetype EXCLUDE_FROM_ALL)

INSTALL(TARGETS freetype
EXPORT RmlUiTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# SET(FT_DISABLE_ZLIB ON CACHE BOOL "" FORCE)
# SET(FT_DISABLE_BZIP2 ON CACHE BOOL "" FORCE)
# SET(FT_DISABLE_PNG ON CACHE BOOL "" FORCE)
# SET(FT_DISABLE_HARFBUZZ ON CACHE BOOL "" FORCE)
# SET(FT_DISABLE_BROTLI ON CACHE BOOL "" FORCE)
# SET(SKIP_INSTALL_ALL ON CACHE BOOL "" FORCE)
# SET(SKIP_INSTALL_LIBRARIES ON CACHE BOOL "" FORCE)
# SET(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
# ADD_SUBDIRECTORY(freetype EXCLUDE_FROM_ALL)

# INSTALL(TARGETS freetype
# EXPORT RmlUiTargets
# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
# ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
# )

SET(RML_SKIP_INSTALL ON CACHE BOOL "" FORCE)
SET(CUSTOM_CONFIGURATION ON CACHE BOOL "" FORCE)
#ADD_SUBDIRECTORY(RmlUi EXCLUDE_FROM_ALL)
SET(ENABLE_ALL_WARNINGS OFF CACHE BOOL "" FORCE)
SET(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
ADD_SUBDIRECTORY(JoltPhysics/Build EXCLUDE_FROM_ALL)
target_compile_options(Jolt PRIVATE "-fPIC")

SET( GODOT_CPP_SYSTEM_HEADERS ON CACHE BOOL "" FORCE )

ADD_SUBDIRECTORY( godot-cpp EXCLUDE_FROM_ALL)

SET_TARGET_PROPERTIES( godot-cpp
PROPERTIES
CXX_VISIBILITY_PRESET hidden # visibility needs to be the same as the main library
)
1 change: 0 additions & 1 deletion 3rdparty/RmlUi
Submodule RmlUi deleted from 40edf1
1 change: 1 addition & 0 deletions 3rdparty/godot-cpp
Submodule godot-cpp added at 98c143
37 changes: 33 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,35 @@ IF(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" AND NOT CMAKE_SYSTEM_VERSION)
SET(CMAKE_SYSTEM_VERSION "10.0.18362.0" CACHE INTERNAL "" FORCE)
ENDIF()

#build universally on macOS
if ( APPLE )
set( CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "" )
endif()

# Set project name
PROJECT(OSP-MAGNUM CXX)

# From: https://crascit.com/2016/04/09/using-ccache-with-cmake/
find_program( CCACHE_PROGRAM ccache )

if ( CCACHE_PROGRAM )
# get version information
execute_process(
COMMAND "${CCACHE_PROGRAM}" --version
OUTPUT_VARIABLE CCACHE_VERSION
)

string( REGEX MATCH "[^\r\n]*" CCACHE_VERSION ${CCACHE_VERSION} )

message( STATUS "Using ccache: ${CCACHE_PROGRAM} (${CCACHE_VERSION})" )

# Turn on ccache for all targets
set( CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" )
set( CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" )

unset( CCACHE_VERSION )
endif()

# Setup things for the test subdir below
# Has to be in toplevel CMakeLists.txt or ctest gets mad.
enable_testing()
Expand All @@ -56,7 +82,7 @@ OPTION(OSP_ENABLE_COMPILER_WARNINGS "Build with the majority of compiler warning
OPTION(OSP_ENABLE_IWYU "Build with warnings from IWYU turned on" OFF)
OPTION(OSP_ENABLE_CLANG_TIDY "Build with warnings from clang-tidy turned on" OFF)
OPTION(OSP_USE_SYSTEM_SDL "Build with SDL that you provide if turned on, compiles SDL if turned off. Off by default" OFF)

OPTION(OSP_BUILD_GDEXTENSION "Build the GDExtension for osp instead of the standalone binary" OFF)
# If the environment has these set, pull them into proper variables.
SET(CLANG_COMPILE_FLAGS ${CLANG_COMPILE_FLAGS})
SET(GCC_COMPILE_FLAGS ${GCC_COMPILE_FLAGS})
Expand Down Expand Up @@ -158,9 +184,12 @@ ADD_SUBDIRECTORY(3rdparty)
ADD_SUBDIRECTORY(src)

# Unit Tests
ADD_SUBDIRECTORY(test)

IF (NOT OSP_BUILD_GDEXTENSION)
ADD_SUBDIRECTORY(test)
ENDIF()
# Set OSP as default startup project in Visual Studio
set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT osp-magnum)
# Set execution directory of osp-magnum so that we don't have to copy the files
set_property(TARGET osp-magnum PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
if (NOT OSP_BUILD_GDEXTENSION)
set_property(TARGET osp-magnum PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
endif()
103 changes: 16 additions & 87 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##
# Open Space Program
# Copyright © 2019-2020 Open Space Program Project
# Copyright © 2019-2024 Open Space Program Project
#
# MIT License
#
Expand All @@ -23,103 +23,32 @@
# SOFTWARE.
##

find_package(Magnum REQUIRED
GL
Shaders
MeshTools
Primitives
#SceneGraph
Trade
Sdl2Application
AnyImageImporter
)

find_package(MagnumPlugins REQUIRED
TinyGltfImporter
StbImageImporter)
# TODO put that in the right place.

set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads)
if(NOT Threads_FOUND)
message(FATAL_ERROR "Can't find a thread library to use!")
endif()

add_library(osp-magnum-deps INTERFACE)
add_custom_target(compile-osp-magnum-deps)

# TODO: This list shouldn't be required, but there appears to be a bug in cmake where
# the add_custom_target() command, pointing to an INTERFACE dependency, doesn't
# result in the dependencies of the interface building.
# See: https://gitlab.kitware.com/cmake/cmake/-/issues/23569
SET(OSP_MAGNUM_DEPS_LIBS
Threads::Threads
EnTT::EnTT
Corrade::Main
Magnum::Application
Magnum::GL
Magnum::Magnum
Magnum::MeshTools
Magnum::Primitives
#Magnum::SceneGraph
Magnum::Shaders
Magnum::Trade
Magnum::AnyImageImporter
MagnumPlugins::TinyGltfImporter
MagnumPlugins::StbImageImporter
toml11
spdlog
longeron
Jolt)
target_link_libraries(osp-magnum-deps INTERFACE ${OSP_MAGNUM_DEPS_LIBS})
add_dependencies(compile-osp-magnum-deps ${OSP_MAGNUM_DEPS_LIBS})

add_executable(osp-magnum)

target_compile_features(osp-magnum PUBLIC cxx_std_20)
#compile as position-independant to avoid link errors on static link
add_compile_options("-fPIC")

target_include_directories(osp-magnum PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(adera)
add_subdirectory(osp)
add_subdirectory(planet-a)
add_subdirectory(ospjolt)
add_subdirectory(testapp)

# Link it to the interface library that describes the dependencies
target_link_libraries(osp-magnum PRIVATE osp-magnum-deps)
if(OSP_BUILD_GDEXTENSION)

# Gather paths to OSP headers and sources
file(GLOB_RECURSE CPP_FILES CONFIGURE_DEPENDS *.cpp)
file(GLOB_RECURSE H_FILES CONFIGURE_DEPENDS *.h)
target_sources(osp-magnum PRIVATE "${CPP_FILES}" "${H_FILES}")
add_subdirectory(gdextension)

# Add shaders to IDE project
set(SHADERS_DIR "../bin/OSPData/adera/Shaders")
file (GLOB_RECURSE SHADER_FILES CONFIGURE_DEPENDS
"${SHADERS_DIR}/*.vert"
"${SHADERS_DIR}/*.frag"
"${SHADERS_DIR}/*.comp"
)
# For some reason, source_group() requires all files to be added to the executable
target_sources(osp-magnum PRIVATE "${SHADER_FILES}")
else()

# Segregate headers, shaders into filters
source_group("Shader Files" FILES ${SHADER_FILES})
source_group("Header Files" FILES ${H_FILES})
add_subdirectory(testapp_magnum)
add_subdirectory(osp_drawing_gl)
add_subdirectory(adera_drawing_gl)

# Enforce conformance mode for osp-magnum
target_compile_options(osp-magnum PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/permissive->)

set_target_properties(osp-magnum PROPERTIES
EXPORT_COMPILE_COMMANDS TRUE
INSTALL_RPATH "$ORIGIN/lib"
C_EXTENSIONS OFF
C_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)

# Copy root/bin to build/bin after building
add_custom_command(TARGET osp-magnum
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/../bin" "${CMAKE_BINARY_DIR}/$<CONFIG>"
VERBATIM
)
endif()

add_custom_target(run-osp-magnum
COMMAND $<TARGET_FILE:osp-magnum>
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIG>)
57 changes: 57 additions & 0 deletions src/adera/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
##
# Open Space Program
# Copyright © 2019-2024 Open Space Program Project
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
##

find_package(Magnum REQUIRED
Trade
AnyImageImporter
)

find_package(MagnumPlugins REQUIRED
TinyGltfImporter
StbImageImporter)

SET(DEPS_LIBS
EnTT::EnTT
Corrade::Main
Magnum::Magnum
Magnum::Trade
longeron
spdlog
OpenSpaceProgram)

add_library(Adera STATIC)

target_compile_features(Adera PUBLIC cxx_std_20)

# Link it to the interface library that describes the dependencies
target_link_libraries(Adera PRIVATE ${DEPS_LIBS})

# Gather paths to OSP headers and sources
file(GLOB_RECURSE CPP_FILES CONFIGURE_DEPENDS *.cpp)
file(GLOB_RECURSE H_FILES CONFIGURE_DEPENDS *.h)
target_sources(Adera PRIVATE "${CPP_FILES}" "${H_FILES}")

# Enforce conformance mode for adera
target_compile_options(Adera PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/permissive->)
Loading

0 comments on commit 49ee950

Please sign in to comment.