From 330f128dd3e05435b052807c53dd5d95879f8209 Mon Sep 17 00:00:00 2001 From: maelstrom Date: Wed, 23 Jul 2025 03:06:18 +0200 Subject: [PATCH] refactor(cmake): (Thanks @FloofyPlasma!) replaced vcpkg with CPM --- client/CMakeLists.txt | 7 ++----- client/deps.cmake | 12 ++++++++++++ cmake/CPM.cmake | 23 +++++++++++++++++++++++ cmake/FindStb.cmake | 30 ------------------------------ core/CMakeLists.txt | 23 +++-------------------- core/deps.cmake | 24 ++++++++++++++++++++++++ core/src/luaapis.h | 6 +++++- deps.txt | 1 - patches/std_chrono.patch | 12 ++++++++++++ 9 files changed, 81 insertions(+), 57 deletions(-) create mode 100644 client/deps.cmake create mode 100644 cmake/CPM.cmake delete mode 100644 cmake/FindStb.cmake create mode 100644 core/deps.cmake create mode 100644 patches/std_chrono.patch diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 6a255a3..259fdb1 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,8 +1,5 @@ -find_package(SDL2 REQUIRED) -include_directories(${SDL2_INCLUDE_DIRS}) - -find_package(glfw3 REQUIRED) +include(${CMAKE_CURRENT_SOURCE_DIR}/deps.cmake) add_executable(client "src/main.cpp") -target_link_libraries(client PRIVATE ${SDL2_LIBRARIES} openblocks glfw) +target_link_libraries(client PRIVATE openblocks glfw) add_dependencies(client openblocks) \ No newline at end of file diff --git a/client/deps.cmake b/client/deps.cmake new file mode 100644 index 0000000..912d2ce --- /dev/null +++ b/client/deps.cmake @@ -0,0 +1,12 @@ +# Declare/fetch packages + +include(FetchContent) +FetchContent_Declare( + glfw3 + GIT_REPOSITORY https://github.com/glfw/glfw + GIT_TAG 3.4 +) + +FetchContent_MakeAvailable(glfw3) + +# Find/include packages \ No newline at end of file diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake new file mode 100644 index 0000000..cb8d274 --- /dev/null +++ b/cmake/CPM.cmake @@ -0,0 +1,23 @@ +set(CPM_DOWNLOAD_VERSION 0.42.0) +# Patch support is broken in CPM upstream atm, so we have to use a fork +set(CPM_HASH_SUM "f7d92592a257d184fd8de6fb496a711ce393676ed68999b96043aab2e5e6f9e6") +# set(CPM_HASH_SUM "2020b4fc42dba44817983e06342e682ecfc3d2f484a581f11cc5731fbe4dce8a") + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +file(DOWNLOAD + https://raw.githubusercontent.com/BohdanBuinich/CPM.cmake/refs/heads/feat/fix_patch_command/cmake/CPM.cmake + # https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} +) + +include(${CPM_DOWNLOAD_LOCATION}) \ No newline at end of file diff --git a/cmake/FindStb.cmake b/cmake/FindStb.cmake deleted file mode 100644 index f77b1e7..0000000 --- a/cmake/FindStb.cmake +++ /dev/null @@ -1,30 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. -# Copyright Stefano Sinigardi - -#.rst: -# FindStb -# ------------ -# -# Find the Stb include headers. -# -# Result Variables -# ^^^^^^^^^^^^^^^^ -# -# This module defines the following variables: -# -# ``Stb_FOUND`` -# True if Stb library found -# -# ``Stb_INCLUDE_DIR`` -# Location of Stb headers -# - -include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) -include(${CMAKE_ROOT}/Modules/SelectLibraryConfigurations.cmake) - -if(NOT Stb_INCLUDE_DIR) - find_path(Stb_INCLUDE_DIR NAMES stb_image.h PATHS ${Stb_DIR} PATH_SUFFIXES include stb include/stb) -endif() - -find_package_handle_standard_args(Stb DEFAULT_MSG Stb_INCLUDE_DIR) -mark_as_advanced(Stb_INCLUDE_DIR) \ No newline at end of file diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 6882117..55fe855 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -1,21 +1,4 @@ -find_package(OpenGL REQUIRED COMPONENTS OpenGL) - -find_package(GLEW REQUIRED) -include_directories(${GLEW_INCLUDE_DIRS}) - -find_package(OpenGL) -find_package(glm CONFIG REQUIRED) -find_package(ReactPhysics3D REQUIRED) -find_package(pugixml 1.15 REQUIRED) -find_package(Freetype) - -find_package(Stb REQUIRED) -include_directories(${Stb_INCLUDE_DIR}) - -# PkgConfig packages -find_package(PkgConfig REQUIRED) -pkg_check_modules(LUAJIT REQUIRED luajit) -link_directories(${LUAJIT_LIBRARY_DIRS}) +include(${CMAKE_CURRENT_SOURCE_DIR}/deps.cmake) ### Autogen file(GLOB_RECURSE AUTOGEN_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/src" "src/objects/*.h" "src/datatypes/*.h" "src/enum/*.h") @@ -51,8 +34,8 @@ list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/src/version.cpp) add_library(openblocks STATIC ${SOURCES}) set_target_properties(openblocks PROPERTIES OUTPUT_NAME "openblocks") target_link_directories(openblocks PUBLIC ${LUAJIT_LIBRARY_DIRS}) -target_link_libraries(openblocks ${GLEW_LIBRARIES} ${LUAJIT_LIBRARIES} OpenGL::GL ReactPhysics3D::ReactPhysics3D pugixml::pugixml Freetype::Freetype) -target_include_directories(openblocks PUBLIC "src" "../include" ${LUAJIT_INCLUDE_DIRS}) +target_link_libraries(openblocks libglew_static reactphysics3d pugixml::pugixml Freetype::Freetype glm::glm libluajit ${LuaJIT_LIBRARIES}) +target_include_directories(openblocks PUBLIC "src" "../include" ${ReactPhysics3D_SOURCE_DIR}/include ${LUAJIT_INCLUDE_DIRS} ${stb_SOURCE_DIR} ${glew_SOURCE_DIR}/include) add_dependencies(openblocks autogen_build autogen) # Windows-specific dependencies diff --git a/core/deps.cmake b/core/deps.cmake new file mode 100644 index 0000000..76752f9 --- /dev/null +++ b/core/deps.cmake @@ -0,0 +1,24 @@ + +include(CPM) + +CPMAddPackage("gh:Perlmint/glew-cmake#glew-cmake-2.2.0") +CPMAddPackage("gh:g-truc/glm#1.0.1") +CPMAddPackage(NAME reactphysics3d GITHUB_REPOSITORY "DanielChappuis/reactphysics3d" VERSION 0.10.2 PATCHES ${CMAKE_SOURCE_DIR}/patches/std_chrono.patch) +# https://github.com/StereoKit/StereoKit/blob/0be056efebcee5e58ad1438f4cf6dfdb942f6cf9/CMakeLists.txt#L205 +set_property(TARGET reactphysics3d PROPERTY POSITION_INDEPENDENT_CODE ON) +CPMAddPackage("gh:zeux/pugixml@1.15") + +CPMAddPackage( + NAME freetype + GIT_REPOSITORY https://github.com/aseprite/freetype2.git + GIT_TAG VER-2-10-0 + VERSION 2.10.0 +) + +if (freetype_ADDED) + add_library(Freetype::Freetype ALIAS freetype) +endif() + +CPMAddPackage("gh:nothings/stb#8cfb1605c02aee9fb6eb5d8ea559017745bd9a16") # 2.14 +CPMAddPackage("gh:WohlSoft/LuaJIT#a5da8f4a31972b74254f00969111b8b7a07cf584") # v2.1 +set(LUAJIT_INCLUDE_DIRS ${LuaJIT_SOURCE_DIR}/src) \ No newline at end of file diff --git a/core/src/luaapis.h b/core/src/luaapis.h index 1dfa1de..fcc49c7 100644 --- a/core/src/luaapis.h +++ b/core/src/luaapis.h @@ -6,6 +6,8 @@ extern "C" { #include } +LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); + inline const char* x_luaL_udatatname (lua_State *L, int ud) { void *p = lua_touserdata(L, ud); if (p != NULL) { @@ -16,4 +18,6 @@ inline const char* x_luaL_udatatname (lua_State *L, int ud) { return str; } return NULL; -} \ No newline at end of file +} + +#define LUA_OK 0 \ No newline at end of file diff --git a/deps.txt b/deps.txt index ad0a1a1..5cb97ff 100644 --- a/deps.txt +++ b/deps.txt @@ -2,7 +2,6 @@ opengl (Linux: glvnd, Windows: [built-in/none]) glfw glew glm -sdl2 stb qt6 reactphysics3d diff --git a/patches/std_chrono.patch b/patches/std_chrono.patch new file mode 100644 index 0000000..9dcdb55 --- /dev/null +++ b/patches/std_chrono.patch @@ -0,0 +1,12 @@ +diff --git a/include/reactphysics3d/utils/DefaultLogger.h b/include/reactphysics3d/utils/DefaultLogger.h +index 1088d1e..8360f07 100644 +--- a/include/reactphysics3d/utils/DefaultLogger.h ++++ b/include/reactphysics3d/utils/DefaultLogger.h +@@ -37,6 +37,7 @@ + #include + #include + #include ++#include + + /// ReactPhysics3D namespace + namespace reactphysics3d {