2024-02-07 02:54:16 -05:00
|
|
|
cmake_minimum_required(VERSION 3.25 FATAL_ERROR)
|
|
|
|
|
2024-02-11 13:58:46 -05:00
|
|
|
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT Embedded)
|
|
|
|
cmake_policy(SET CMP0141 NEW)
|
|
|
|
|
|
|
|
if (NOT DEFINED CMAKE_C_COMPILER_LAUNCHER AND NOT DEFINED ENV{CMAKE_C_COMPILER_LAUNCHER} OR
|
|
|
|
NOT DEFINED CMAKE_CXX_COMPILER_LAUNCHER AND NOT DEFINED ENV{CMAKE_CXX_COMPILER_LAUNCHER})
|
|
|
|
message(STATUS "Looking for ccache/sccache")
|
|
|
|
find_program(GEODE_CCACHE NAMES sccache ccache)
|
|
|
|
if (NOT GEODE_CCACHE)
|
|
|
|
message(STATUS "Looking for ccache/sccache - not found")
|
|
|
|
message(NOTICE "Not using a caching compiler (ccache/sccache). "
|
|
|
|
"It is recommended to install one to improve build times.")
|
|
|
|
message(NOTICE "Recommended sccache, check its README for installation instructions, "
|
|
|
|
"normally you can just use your usual package manager (e.g. 'scoop install sccache').")
|
|
|
|
else()
|
|
|
|
message(STATUS "Looking for ccache/sccache - found")
|
|
|
|
message(NOTICE "Compiler launcher not set but ccache/sccache was found. "
|
|
|
|
"Setting compiler launcher to that")
|
|
|
|
set(CMAKE_C_COMPILER_LAUNCHER ${GEODE_CCACHE})
|
|
|
|
set(CMAKE_CXX_COMPILER_LAUNCHER ${GEODE_CCACHE})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (DEFINED ENV{GEODE_CI})
|
|
|
|
message(STATUS "Building in CI")
|
|
|
|
endif()
|
|
|
|
|
2022-10-10 14:00:32 -04:00
|
|
|
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build libraries static" FORCE)
|
2022-12-13 15:39:45 -05:00
|
|
|
|
2023-01-24 11:37:59 -05:00
|
|
|
# Docs flags
|
|
|
|
if (GEODE_BUILDING_DOCS)
|
|
|
|
set(GEODE_DISABLE_CLI_CALLS On)
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS On)
|
2024-01-04 07:47:08 -05:00
|
|
|
set(GEODE_DONT_BUILD_TEST_MODS On)
|
2023-01-24 11:37:59 -05:00
|
|
|
endif()
|
|
|
|
|
2024-02-03 06:40:44 -05:00
|
|
|
option(GEODE_USE_BREAKPAD "Enables the use of the Breakpad library for crash dumps." ON)
|
2024-02-02 04:40:07 -05:00
|
|
|
|
2022-12-13 15:39:45 -05:00
|
|
|
# Read version
|
2022-10-11 04:37:46 -04:00
|
|
|
file(READ VERSION GEODE_VERSION)
|
2022-10-11 16:38:01 -04:00
|
|
|
string(STRIP "${GEODE_VERSION}" GEODE_VERSION)
|
2022-10-05 08:41:05 -04:00
|
|
|
|
2022-12-13 15:39:45 -05:00
|
|
|
# Check if version has a tag like v1.0.0-alpha
|
|
|
|
string(FIND ${GEODE_VERSION} "-" GEODE_VERSION_HAS_TAG)
|
2023-02-22 05:19:17 -05:00
|
|
|
if (NOT ${GEODE_VERSION_HAS_TAG} EQUAL "-1")
|
|
|
|
string(REGEX MATCH "[a-z]+(\.[0-9]+)?$" GEODE_VERSION_TAG ${GEODE_VERSION})
|
2022-12-13 15:39:45 -05:00
|
|
|
string(SUBSTRING "${GEODE_VERSION}" 0 ${GEODE_VERSION_HAS_TAG} GEODE_VERSION)
|
2023-02-22 05:19:17 -05:00
|
|
|
string(FIND ${GEODE_VERSION_TAG} "." GEODE_VERSION_TAG_HAS_NUMBER)
|
|
|
|
|
|
|
|
# Extract tag type and number from tag
|
|
|
|
if (NOT ${GEODE_VERSION_TAG_HAS_NUMBER} EQUAL "-1")
|
|
|
|
string(SUBSTRING "${GEODE_VERSION_TAG}" 0 ${GEODE_VERSION_TAG_HAS_NUMBER} GEODE_VERSION_TAG_TYPE)
|
|
|
|
math(EXPR GEODE_VERSION_TAG_HAS_NUMBER "${GEODE_VERSION_TAG_HAS_NUMBER} + 1")
|
|
|
|
string(SUBSTRING "${GEODE_VERSION_TAG}" ${GEODE_VERSION_TAG_HAS_NUMBER} -1 GEODE_VERSION_TAG_NUMBER)
|
|
|
|
else()
|
|
|
|
set(GEODE_VERSION_TAG_TYPE "${GEODE_VERSION_TAG}")
|
|
|
|
set(GEODE_VERSION_TAG_NUMBER "")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Capitalize first letter of tag type
|
|
|
|
string(SUBSTRING ${GEODE_VERSION_TAG_TYPE} 0 1 FIRST_LETTER)
|
|
|
|
string(TOUPPER ${FIRST_LETTER} FIRST_LETTER)
|
|
|
|
string(REGEX REPLACE "^.(.*)" "${FIRST_LETTER}\\1" GEODE_VERSION_TAG_TYPE "${GEODE_VERSION_TAG_TYPE}")
|
2023-08-03 17:35:03 -04:00
|
|
|
|
|
|
|
message(STATUS "Version: ${GEODE_VERSION}, tag: ${GEODE_VERSION_TAG} (type: ${GEODE_VERSION_TAG_TYPE}, number: ${GEODE_VERSION_TAG_NUMBER})")
|
2022-12-13 15:39:45 -05:00
|
|
|
else()
|
|
|
|
set(GEODE_VERSION_TAG "")
|
2023-02-22 05:19:17 -05:00
|
|
|
set(GEODE_VERSION_TAG_TYPE "")
|
|
|
|
set(GEODE_VERSION_TAG_NUMBER "")
|
2022-12-13 15:39:45 -05:00
|
|
|
|
2023-08-03 17:35:03 -04:00
|
|
|
message(STATUS "Version: ${GEODE_VERSION}")
|
|
|
|
endif()
|
2022-12-13 15:39:45 -05:00
|
|
|
|
2024-02-05 02:48:17 -05:00
|
|
|
include(cmake/CPM.cmake)
|
|
|
|
|
2024-02-11 13:58:46 -05:00
|
|
|
if (NOT DEFINED CPM_SOURCE_CACHE)
|
|
|
|
message(NOTICE "Not using CPM cache (CPM_SOURCE_CACHE). "
|
|
|
|
"It is recommended to use it to improve configure times.")
|
|
|
|
endif()
|
|
|
|
|
2024-02-05 02:48:17 -05:00
|
|
|
# Allow users to have their own copy of bindings that can be overwritten with a CMake option.
|
|
|
|
# If the option is not provided, by default just clone bindings with CPM and use that
|
|
|
|
if (DEFINED ENV{GEODE_BINDINGS_REPO_PATH})
|
|
|
|
set(temp $ENV{GEODE_BINDINGS_REPO_PATH})
|
|
|
|
# this is so stupid i hate windows paths
|
|
|
|
string(REPLACE "\\" "/" GEODE_BINDINGS_REPO_PATH ${temp})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (NOT GEODE_BINDINGS_REPO_PATH)
|
|
|
|
message(STATUS
|
|
|
|
"No override path for bindings provided, using CPM to clone default. "
|
|
|
|
"If you would like to use a separate clone of the bindings repo "
|
|
|
|
"(for example in order to be able to efficiently change and "
|
|
|
|
"contribute new bindings) then set GEODE_BINDINGS_REPO_PATH to where you have "
|
|
|
|
"cloned the repository (system environment variables are supported)."
|
|
|
|
)
|
|
|
|
CPMAddPackage(NAME "bindings"
|
|
|
|
GITHUB_REPOSITORY "geode-sdk/bindings"
|
|
|
|
GIT_TAG "main"
|
|
|
|
DOWNLOAD_ONLY YES
|
|
|
|
NO_CACHE YES
|
|
|
|
)
|
|
|
|
set(GEODE_BINDINGS_REPO_PATH ${bindings_SOURCE_DIR})
|
|
|
|
else()
|
|
|
|
message(STATUS "Using ${GEODE_BINDINGS_REPO_PATH} for bindings repo")
|
|
|
|
endif()
|
|
|
|
|
2022-10-05 08:41:05 -04:00
|
|
|
project(geode-sdk VERSION ${GEODE_VERSION} LANGUAGES CXX C)
|
2022-07-30 12:24:03 -04:00
|
|
|
|
|
|
|
add_library(${PROJECT_NAME} INTERFACE)
|
|
|
|
|
2022-10-11 04:37:46 -04:00
|
|
|
# Rerun CMake on VERSION file change
|
|
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES CMAKE_CONFIGURE_DEPENDS VERSION)
|
|
|
|
|
2022-07-30 12:24:03 -04:00
|
|
|
target_compile_definitions(${PROJECT_NAME} INTERFACE -DPROJECT_NAME=${CMAKE_PROJECT_NAME})
|
|
|
|
|
|
|
|
set(GEODE_BIN_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
|
|
|
|
set(GEODE_LOADER_PATH ${CMAKE_CURRENT_SOURCE_DIR}/loader)
|
2023-04-03 03:43:52 -04:00
|
|
|
set(GEODE_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
2022-07-30 12:24:03 -04:00
|
|
|
|
|
|
|
include(cmake/Platform.cmake)
|
2023-10-08 09:38:17 -04:00
|
|
|
include(cmake/GeodeFile.cmake)
|
2022-07-30 12:24:03 -04:00
|
|
|
|
2024-01-08 14:48:21 -05:00
|
|
|
if (NOT DEFINED GEODE_GD_VERSION)
|
|
|
|
if (${GEODE_TARGET_PLATFORM} STREQUAL "Win32")
|
2024-01-17 12:09:08 -05:00
|
|
|
set(GEODE_GD_VERSION 2.204)
|
2024-01-22 09:59:18 -05:00
|
|
|
set(GEODE_COMP_GD_VERSION 22040)
|
2024-01-22 09:44:30 -05:00
|
|
|
elseif (${GEODE_TARGET_PLATFORM} STREQUAL "Android32" OR ${GEODE_TARGET_PLATFORM} STREQUAL "Android64")
|
|
|
|
set(GEODE_GD_VERSION 2.205)
|
2024-01-22 09:59:18 -05:00
|
|
|
set(GEODE_COMP_GD_VERSION 22050)
|
2024-01-08 14:48:21 -05:00
|
|
|
else()
|
|
|
|
set(GEODE_GD_VERSION 2.200)
|
2024-01-22 09:59:18 -05:00
|
|
|
set(GEODE_COMP_GD_VERSION 22000)
|
2024-01-08 14:48:21 -05:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2024-01-22 09:58:22 -05:00
|
|
|
target_compile_definitions(${PROJECT_NAME} INTERFACE GEODE_GD_VERSION=${GEODE_GD_VERSION} GEODE_COMP_GD_VERSION=${GEODE_COMP_GD_VERSION})
|
2024-01-08 14:48:21 -05:00
|
|
|
|
2024-01-09 14:59:57 -05:00
|
|
|
if (WIN32)
|
|
|
|
# This allows you to compile in debug mode
|
|
|
|
add_compile_definitions(_HAS_ITERATOR_DEBUGGING=0)
|
|
|
|
add_definitions(-D_HAS_ITERATOR_DEBUGGING=0)
|
2024-02-11 13:58:46 -05:00
|
|
|
target_link_libraries(${PROJECT_NAME} INTERFACE delayimp)
|
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
|
|
|
|
CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
|
|
|
|
# target x86 on windows with clang
|
|
|
|
add_compile_options(--target=i686-windows-msvc)
|
|
|
|
add_link_options(--target=i686-windows-msvc)
|
|
|
|
endif()
|
2024-01-09 14:59:57 -05:00
|
|
|
endif()
|
2024-01-08 14:48:21 -05:00
|
|
|
|
2024-01-03 18:08:05 -05:00
|
|
|
set(MAT_JSON_AS_INTERFACE ON)
|
2024-02-04 17:08:01 -05:00
|
|
|
CPMAddPackage("gh:geode-sdk/json#7e4dfae")
|
2023-12-29 18:59:06 -05:00
|
|
|
CPMAddPackage("gh:fmtlib/fmt#10.1.1")
|
2023-05-01 06:57:46 -04:00
|
|
|
CPMAddPackage("gh:gulrak/filesystem#3e5b930")
|
|
|
|
|
2023-05-24 15:17:58 -04:00
|
|
|
target_compile_definitions(${PROJECT_NAME} INTERFACE MAT_JSON_DYNAMIC=1)
|
|
|
|
|
2023-02-17 13:41:10 -05:00
|
|
|
# this is needed for cross compilation on linux,
|
|
|
|
# since fmtlib will fail to compile otherwise
|
|
|
|
if (GEODE_DISABLE_FMT_CONSTEVAL)
|
2023-05-01 06:57:46 -04:00
|
|
|
message(VERBOSE "Disabling FMT_CONSTEVAL")
|
|
|
|
target_compile_definitions(fmt PUBLIC -DFMT_CONSTEVAL=)
|
2023-02-17 13:41:10 -05:00
|
|
|
endif()
|
|
|
|
|
2023-02-08 09:37:37 -05:00
|
|
|
# Tulip hook (hooking)
|
|
|
|
if (PROJECT_IS_TOP_LEVEL AND NOT GEODE_BUILDING_DOCS)
|
|
|
|
set(TULIP_LINK_SOURCE ON)
|
|
|
|
endif()
|
2023-08-02 10:34:36 -04:00
|
|
|
set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "" FORCE)
|
2024-02-12 08:01:19 -05:00
|
|
|
|
|
|
|
# Allow users to have their own copy of TulipHook that can be overwritten with a CMake option.
|
|
|
|
# If the option is not provided, by default just clone TulipHook with CPM and use that
|
|
|
|
if (DEFINED ENV{GEODE_TULIPHOOK_REPO_PATH})
|
|
|
|
set(temp $ENV{GEODE_TULIPHOOK_REPO_PATH})
|
|
|
|
# this is so stupid i hate windows paths
|
|
|
|
string(REPLACE "\\" "/" GEODE_TULIPHOOK_REPO_PATH ${temp})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (DEFINED GEODE_TULIPHOOK_REPO_PATH)
|
|
|
|
message(STATUS "Using ${GEODE_TULIPHOOK_REPO_PATH} for TulipHook")
|
|
|
|
add_subdirectory(${GEODE_TULIPHOOK_REPO_PATH} ${GEODE_TULIPHOOK_REPO_PATH}/build)
|
|
|
|
else()
|
|
|
|
CPMAddPackage("gh:geode-sdk/TulipHook#9dc223d")
|
|
|
|
endif()
|
2023-08-02 10:34:36 -04:00
|
|
|
set(CMAKE_WARN_DEPRECATED ON CACHE BOOL "" FORCE)
|
|
|
|
|
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
check_cxx_compiler_flag(-Wno-everything SUPPORTS_W_NO_EVERYTHING)
|
|
|
|
if (SUPPORTS_W_NO_EVERYTHING)
|
2024-02-11 13:58:46 -05:00
|
|
|
# Silence warnings from dependencies
|
2023-08-05 14:25:33 -04:00
|
|
|
if (TARGET capstone)
|
|
|
|
target_compile_options(capstone PRIVATE -Wno-everything)
|
2023-08-02 11:27:38 -04:00
|
|
|
endif()
|
2023-08-02 10:34:36 -04:00
|
|
|
endif()
|
2023-02-08 09:37:37 -05:00
|
|
|
|
2022-07-30 12:24:03 -04:00
|
|
|
target_sources(${PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/entry.cpp)
|
|
|
|
|
2023-02-08 09:37:37 -05:00
|
|
|
add_library(GeodeFilesystemImpl ${CMAKE_CURRENT_SOURCE_DIR}/FilesystemImpl.cpp)
|
2023-02-08 10:30:12 -05:00
|
|
|
target_compile_features(GeodeFilesystemImpl PUBLIC cxx_std_20)
|
2023-02-08 09:37:37 -05:00
|
|
|
target_link_libraries(GeodeFilesystemImpl PUBLIC ghc_filesystem)
|
|
|
|
|
2024-02-05 02:48:17 -05:00
|
|
|
add_subdirectory(${GEODE_BINDINGS_REPO_PATH} ${CMAKE_BINARY_DIR}/bindings)
|
2023-12-20 07:23:21 -05:00
|
|
|
|
2024-02-04 14:45:52 -05:00
|
|
|
target_include_directories(GeodeBindings PUBLIC
|
2022-07-30 12:24:03 -04:00
|
|
|
${GEODE_LOADER_PATH}/include
|
2022-10-17 08:46:36 -04:00
|
|
|
${GEODE_LOADER_PATH}/include/Geode/cocos/include
|
2022-07-30 12:24:03 -04:00
|
|
|
${GEODE_LOADER_PATH}/include/Geode/cocos/extensions
|
|
|
|
${GEODE_LOADER_PATH}/include/Geode/fmod
|
|
|
|
)
|
2024-02-04 14:45:52 -05:00
|
|
|
target_link_directories(GeodeBindings PUBLIC ${GEODE_LOADER_PATH}/include/link)
|
|
|
|
target_link_libraries(GeodeBindings PUBLIC ghc_filesystem fmt TulipHookInclude mat-json GeodeFilesystemImpl)
|
2024-02-07 05:02:51 -05:00
|
|
|
target_link_libraries(${PROJECT_NAME} INTERFACE GeodeBindings)
|
2022-08-08 14:18:09 -04:00
|
|
|
|
2022-07-30 12:24:03 -04:00
|
|
|
if (NOT EXISTS ${GEODE_BIN_PATH})
|
2024-02-03 12:28:47 -05:00
|
|
|
file(MAKE_DIRECTORY ${GEODE_BIN_PATH})
|
2022-07-30 12:24:03 -04:00
|
|
|
endif()
|
|
|
|
|
2022-12-08 22:15:10 -05:00
|
|
|
if (NOT EXISTS ${GEODE_BIN_PATH}/${PROJECT_VERSION} AND EXISTS ${GEODE_BIN_PATH}/nightly/)
|
|
|
|
set(GEODE_LINK_NIGHTLY 1)
|
|
|
|
endif()
|
2022-07-30 12:24:03 -04:00
|
|
|
|
2022-10-03 01:06:27 -04:00
|
|
|
if (${GEODE_LINK_NIGHTLY})
|
2022-07-30 12:24:03 -04:00
|
|
|
set(GEODE_PLATFORM_BIN_PATH ${GEODE_BIN_PATH}/nightly/${GEODE_PLATFORM_BINARY})
|
|
|
|
else()
|
|
|
|
set(GEODE_PLATFORM_BIN_PATH ${GEODE_BIN_PATH}/${PROJECT_VERSION}/${GEODE_PLATFORM_BINARY})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (PROJECT_IS_TOP_LEVEL)
|
2022-08-08 14:18:09 -04:00
|
|
|
add_subdirectory(loader)
|
2022-07-30 12:24:03 -04:00
|
|
|
target_link_libraries(${PROJECT_NAME} INTERFACE geode-loader)
|
2024-02-11 13:58:46 -05:00
|
|
|
if (SUPPORTS_W_NO_EVERYTHING)
|
|
|
|
target_compile_options(geode-loader PRIVATE -Wno-inconsistent-missing-override)
|
|
|
|
endif()
|
2022-07-30 12:24:03 -04:00
|
|
|
elseif(EXISTS ${GEODE_PLATFORM_BIN_PATH})
|
|
|
|
target_link_libraries(${PROJECT_NAME} INTERFACE "${GEODE_PLATFORM_BIN_PATH}")
|
|
|
|
else()
|
2022-10-17 08:46:36 -04:00
|
|
|
message(FATAL_ERROR
|
2024-02-11 13:58:46 -05:00
|
|
|
"No valid loader binary to link to! Install pre-built binaries with `geode sdk install-binaries`, "
|
2023-02-02 20:06:23 -05:00
|
|
|
"or build Geode from source and add `set(GEODE_LINK_NIGHTLY ON)` to your CMakeLists.txt "
|
2022-12-08 17:28:05 -05:00
|
|
|
"in the line before calling add_subdirectory for Geode."
|
2022-10-17 08:46:36 -04:00
|
|
|
)
|
2022-07-30 12:24:03 -04:00
|
|
|
endif()
|