From e2e73c4934c8fe1c2a7b091777bceb42995614d6 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Thu, 2 Jun 2022 21:18:58 +0100 Subject: [PATCH] meta: updated build system with gint install, README --- CMakeLists.txt | 94 ++++++++++++++++++++++++++++++++++----------- README.md | 49 +++++++++++++++++++++++ azur/CMakeLists.txt | 22 ++++++++--- 3 files changed, 136 insertions(+), 29 deletions(-) create mode 100644 README.md diff --git a/CMakeLists.txt b/CMakeLists.txt index adad8e1..d1fee6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,27 +1,43 @@ cmake_minimum_required(VERSION 3.19) -project(Facets VERSION 0.1) +project(AzurEngine VERSION 0.1) -# TODO: Set AZUR_DEBUG based on CMake Debug/Release setting -set(AZUR_DEBUG ON) +#--- +# Configuration +# +# -DCMAKE_BUILD_TYPE +# Debug Debug build with -O0 -g +# Release Release build with -Os [default] +# +# -DAZUR_PLATFORM +# gint Build for gint for fx-CG +# linux Build for Linux with SDL and OpenGL 3.3 +# emscripten Build for Emscripten with SDL and OpenGL ES 2.0 +# +# -DCMAKE_INSTALL_PREFIX +#--- + +if("${CMAKE_BUILD_TYPE}" STREQUAL "") + set("${CMAKE_BUILD_TYPE}" Release) +endif() + +# Debug build +if("${CMAKE_BUILD_TYPE}" STREQUAL Debug) + set(AZUR_DEBUG TRUE) +else() + set(AZUR_DEBUG FALSE) +endif() # When using [fxsdk build-cg], assume gint if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) - set(FACETS_PLATFORM gint) + set(AZUR_PLATFORM gint) endif() -# General options -add_compile_options(-Wall -Wextra -O2 - -fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/=) +# Default install paths +set(LIBDIR "lib") +set(INCDIR "include") -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) - -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -# gint - -if(FACETS_PLATFORM STREQUAL gint) +# Target configuration: gint +if("${AZUR_PLATFORM}" STREQUAL "gint") set(AZUR_PLATFORM_GENERIC TRUE) set(AZUR_TOOLKIT_GINT TRUE) set(AZUR_GRAPHICS_GINT_CG TRUE) @@ -31,11 +47,21 @@ if(FACETS_PLATFORM STREQUAL gint) find_package(LibProf 2.4 REQUIRED) link_libraries(LibProf::LibProf Gint::Gint) + + # Default to the fxSDK install path + if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${FXSDK_COMPILER_INSTALL}" CACHE PATH "..." FORCE) + endif() + + # The fxSDK install path has a slightly different structure + if(CMAKE_INSTALL_PREFIX STREQUAL "${FXSDK_COMPILER_INSTALL}") + set(LIBDIR ".") + set(INCDIR "include") + endif() endif() -# linux - -if(FACETS_PLATFORM STREQUAL linux) +# Target configuration: linux +if(AZUR_PLATFORM STREQUAL linux) set(AZUR_PLATFORM_GENERIC TRUE) set(AZUR_TOOLKIT_SDL TRUE) set(AZUR_GRAPHICS_OPENGL_3_3 TRUE) @@ -50,9 +76,8 @@ if(FACETS_PLATFORM STREQUAL linux) link_libraries(PkgConfig::sdl2_image PkgConfig::sdl2 PkgConfig::opengl -lm) endif() -# emscripten - -if(FACETS_PLATFORM STREQUAL emscripten) +# Platform configuration: emscripten +if(AZUR_PLATFORM STREQUAL emscripten) set(AZUR_PLATFORM_EMSCRIPTEN TRUE) set(AZUR_TOOLKIT_SDL TRUE) set(AZUR_GRAPHICS_OPENGL_ES_2_0 TRUE) @@ -63,9 +88,31 @@ if(FACETS_PLATFORM STREQUAL emscripten) add_link_options(${PORTS} -O3) endif() +if(AZUR_GRAPHICS_OPENGL_3_3 OR AZUR_GRAPHICS_OPENGL_ES_2_0) + set(AZUR_GRAPHICS_OPENGL TRUE) +endif() + +#--- +# Compile options #--- -if(NOT FACETS_PLATFORM STREQUAL gint) +add_compile_options( + -Wall -Wextra + $,-O0,-Os> + $<$:-g> + -fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/=) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED TRUE) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) + +#--- +# Subdirectory selection +#--- + +if(NOT AZUR_PLATFORM STREQUAL gint) # This provides GL3W on desktop add_subdirectory(gl3w-builds) # This provides Dear ImGui @@ -74,4 +121,5 @@ if(NOT FACETS_PLATFORM STREQUAL gint) add_subdirectory(glm-builds) endif() +add_subdirectory(libnum) add_subdirectory(azur) diff --git a/README.md b/README.md new file mode 100644 index 0000000..e03fac1 --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +# Azur: Lephe's game engine + +Azur is a game engine for the fx-CG series of graphing calculators that also supports standard PC (SDL2 / OpenGL) and web (emscripten / SDL2 / WebGL) builds. + +Azur aims to implement real-world game engine mechanics such as ECS, animation and visual effects, physics, and state serialization. It doesn't try to be super fancy with them, but it does try to get the structure right. + +## Projects in this repository + +The following are Azur libraries: + +* **libnum** is a C++ fixed-point math library. It provides various sizes of fixed-point values with support for arithmetic, but also some math functions, geometry/linear algebra, and is planned to support numerical algorithms in the future. +* **libazrp** is C library that implements Azur's Rendering Pipeline. On fx-CG, Azur uses a very unique rendering method that sacrifices some generality for a significant boost in performance, and this system has uses beyond games. (TODO: Currently still in the `azur/` folder) +* **azur** is of course the engine itself. + +The following external projects are Azur by some of Azur's features, and maintained as submodules in `3rdparty/`: + +* [**gl3w**](https://github.com/skaslev/gl3w) is a minimalist OpenGL loader, which is used in Azur's OpenGL backend to load the core profile. +* [**GLM**](https://glm.g-truc.net/0.9.9/index.html) is math library for graphics, which is interoperable with OpenGL shaders. In the future I hope to use libnum everywhere, but GLM is still useful in OpenGL-related code. +* [**Dear ImGui**](https://github.com/ocornut/imgui) is a GUI library that integrates fantastically with OpenGL. In the future, I plan to provide debugging and introspection for Azur's OpenGL backend using ImGui. + +## Building + +**Building for fx-CG** + +Use the [fxSDK toolchain](https://gitea.planet-casio.com/Lephenixnoir/fxsdk). + +``` +% fxsdk build-cg +``` + +**Building for Linux** + +``` +% cmake -B build-linux -DAZUR_PLATFORM=linux -DCMAKE_INSTALL_PREFIX="$HOME/.local" +% make -C build-linux +``` + +**Building for emscripten** + +You will need the [emscripten toolchain](https://emscripten.org/). + +``` +% emcmake cmake -B build-emscripten -D AZUR_PLATFORM=emscripten +% make -C build-emscripten +``` + +## History note + +Back in 2021 I made a single repository for this engine, along with other programs that I intended to write with it. At the time I didn't intend to distribute the engine in any serious fashion, but that changed after people expressed interest in playing with [After Burner](https://www.planet-casio.com/Fr/programmes/programme4238-1-after-burner-lephenixnoir-jeux-add-ins.html). I split the repository in May 2022 with `git filter-branch`, and edited the history so old commits can still be built, but don't expect that to work out-of-the-box. diff --git a/azur/CMakeLists.txt b/azur/CMakeLists.txt index 7815a75..168445c 100644 --- a/azur/CMakeLists.txt +++ b/azur/CMakeLists.txt @@ -7,11 +7,6 @@ set(SOURCES src/log.c) set(ASSETS) -# All flavours of OpenGL -if(AZUR_GRAPHICS_OPENGL_3_3 OR AZUR_GRAPHICS_OPENGL_ES_2_0) - set(AZUR_GRAPHICS_OPENGL TRUE) -endif() - # SDL/OpenGL rendering if(AZUR_TOOLKIT_SDL AND AZUR_GRAPHICS_OPENGL) list(APPEND SOURCES @@ -61,7 +56,8 @@ add_library(azur STATIC ${SOURCES}) # File preloading on emscripten if(AZUR_PLATFORM_EMSCRIPTEN) set_target_properties(azur PROPERTIES - INTERFACE_LINK_OPTIONS "SHELL:--preload-file ${CMAKE_CURRENT_SOURCE_DIR}/glsl@/azur/glsl" + INTERFACE_LINK_OPTIONS + "SHELL:--preload-file ${CMAKE_CURRENT_SOURCE_DIR}/glsl@/azur/glsl" LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/glsl") # Add assets to link dependencies @@ -81,3 +77,17 @@ target_include_directories(azur PUBLIC "${PROJECT_SOURCE_DIR}/include" PUBLIC "${PROJECT_BINARY_DIR}/include" ) + +#--- +# Install +#--- + +# Library file: libazur.a +install(TARGETS azur DESTINATION ${LIBDIR}) +# Headers: azur/*.h +install(DIRECTORY include/ DESTINATION ${INCDIR} FILES_MATCHING PATTERN "*.h") +# Generated header: azur/config.h +install(FILES "${PROJECT_BINARY_DIR}/include/azur/config.h" + DESTINATION ${INCDIR}/azur) +# CMake module loading the library: TODO +# install(FILES cmake/FindAzur.cmake DESTINATION "${FXSDK_CMAKE_MODULE_PATH}")