2022-07-30 12:24:03 -04:00
|
|
|
|
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
|
|
|
|
|
|
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)
|
|
|
|
|
set(GEODE_DISABLE_PRECOMPILED_HEADERS On)
|
|
|
|
|
endif()
|
|
|
|
|
|
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}")
|
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
|
|
|
|
endif()
|
|
|
|
|
|
2023-02-22 05:19:17 -05: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
|
|
|
|
|
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-12-12 10:42:56 -05:00
|
|
|
|
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
|
|
|
|
set(GEODE_ALWAYS_BUILD_CODEGEN ON)
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-11-16 09:41:14 -05:00
|
|
|
|
if (NOT DEFINED GEODE_DEBUG AND (CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo))
|
|
|
|
|
set(GEODE_DEBUG ON)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# define it in command line or your project system
|
|
|
|
|
if (GEODE_DEBUG)
|
2022-10-12 15:07:18 -04:00
|
|
|
|
target_compile_definitions(${PROJECT_NAME} INTERFACE -DGEODE_DEBUG)
|
|
|
|
|
endif()
|
|
|
|
|
|
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_CODEGEN_PATH ${CMAKE_CURRENT_BINARY_DIR}/codegenned)
|
|
|
|
|
set(GEODE_BIN_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
|
|
|
|
|
set(GEODE_LOADER_PATH ${CMAKE_CURRENT_SOURCE_DIR}/loader)
|
|
|
|
|
|
|
|
|
|
include(cmake/GeodeFile.cmake)
|
|
|
|
|
include(cmake/Platform.cmake)
|
2022-12-12 14:23:53 -05:00
|
|
|
|
include(cmake/CPM.cmake)
|
2022-07-30 12:24:03 -04:00
|
|
|
|
|
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)
|
|
|
|
|
target_compile_definitions(${PROJECT_NAME} INTERFACE -DFMT_CONSTEVAL=)
|
|
|
|
|
endif()
|
|
|
|
|
|
2023-02-20 12:41:22 -05:00
|
|
|
|
CPMAddPackage("gh:geode-sdk/json#cef9c64")
|
2023-02-08 09:37:37 -05:00
|
|
|
|
CPMAddPackage("gh:fmtlib/fmt#9.1.0")
|
|
|
|
|
CPMAddPackage("gh:gulrak/filesystem#3e5b930")
|
|
|
|
|
|
|
|
|
|
# Tulip hook (hooking)
|
|
|
|
|
if (PROJECT_IS_TOP_LEVEL AND NOT GEODE_BUILDING_DOCS)
|
|
|
|
|
set(TULIP_LINK_SOURCE ON)
|
|
|
|
|
endif()
|
2023-03-20 05:39:31 -04:00
|
|
|
|
CPMAddPackage("gh:geode-sdk/TulipHook#4369d05")
|
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
|
|
|
|
# Filesystem implementation in a separate target because i couldnt disable pch
|
|
|
|
|
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)
|
|
|
|
|
|
2022-11-12 09:16:46 -05:00
|
|
|
|
include(ExternalProject)
|
|
|
|
|
set(GEODE_CODEGEN_BINARY_OUT ${CMAKE_CURRENT_BINARY_DIR}/codegen)
|
|
|
|
|
ExternalProject_Add(CodegenProject
|
2022-12-31 07:33:15 -05:00
|
|
|
|
BUILD_ALWAYS ON
|
2022-11-12 09:16:46 -05:00
|
|
|
|
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/codegen
|
2023-02-09 12:01:52 -05:00
|
|
|
|
# manually set configure command as to not inherit generator used by geode,
|
|
|
|
|
# this should hopefully fix generator cache mismatch between different projects, however
|
|
|
|
|
# it causes a warning to be shown every time. if you know a better solution please tell us ok thx
|
|
|
|
|
CONFIGURE_COMMAND ${CMAKE_COMMAND} ${GEODE_CODEGEN_CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX:STRING=${GEODE_CODEGEN_BINARY_OUT} -S <SOURCE_DIR> -B <BINARY_DIR>
|
2023-02-19 11:24:39 -05:00
|
|
|
|
INSTALL_COMMAND ${CMAKE_COMMAND} --install <BINARY_DIR> --config $<CONFIGURATION>
|
2022-11-12 09:16:46 -05:00
|
|
|
|
)
|
2022-07-30 12:24:03 -04:00
|
|
|
|
|
2022-12-31 07:33:15 -05:00
|
|
|
|
|
|
|
|
|
file(GLOB CODEGEN_DEPENDS CONFIGURE_DEPENDS
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/bindings/*.bro
|
2022-12-31 07:48:05 -05:00
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/codegen/src/*.cpp
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/codegen/src/*.hpp
|
2022-11-12 09:16:46 -05:00
|
|
|
|
)
|
2022-07-30 12:24:03 -04:00
|
|
|
|
|
2022-10-21 19:17:08 -04:00
|
|
|
|
add_custom_command(
|
2022-12-31 07:33:15 -05:00
|
|
|
|
DEPENDS ${CODEGEN_DEPENDS}
|
2022-11-12 09:16:46 -05:00
|
|
|
|
DEPENDS CodegenProject
|
|
|
|
|
COMMAND ${GEODE_CODEGEN_BINARY_OUT}/Codegen ${GEODE_TARGET_PLATFORM} bindings ${GEODE_CODEGEN_PATH}
|
2022-10-21 19:17:08 -04:00
|
|
|
|
COMMAND echo codegen > ${GEODE_CODEGEN_PATH}/.stamp
|
2022-07-30 12:24:03 -04:00
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
|
COMMENT "Run Codegen"
|
2023-01-21 15:36:14 -05:00
|
|
|
|
OUTPUT ${GEODE_CODEGEN_PATH}/Geode/GeneratedSource.cpp ${GEODE_CODEGEN_PATH}/Geode/GeneratedAddress.cpp ${GEODE_CODEGEN_PATH}/.stamp
|
2022-07-30 12:24:03 -04:00
|
|
|
|
)
|
2022-10-21 19:17:08 -04:00
|
|
|
|
|
|
|
|
|
add_custom_target(CodegenRun
|
|
|
|
|
DEPENDS ${GEODE_CODEGEN_PATH}/.stamp
|
|
|
|
|
)
|
|
|
|
|
|
2022-07-30 12:24:03 -04:00
|
|
|
|
add_dependencies(${PROJECT_NAME} CodegenRun)
|
|
|
|
|
|
2022-08-08 14:18:09 -04:00
|
|
|
|
# Hacky way to supress the not generated error
|
2022-10-13 07:00:41 -04:00
|
|
|
|
if (NOT EXISTS ${GEODE_CODEGEN_PATH}/Geode/GeneratedSource.cpp)
|
2022-08-08 14:18:09 -04:00
|
|
|
|
make_directory(${GEODE_CODEGEN_PATH})
|
2022-10-13 07:03:50 -04:00
|
|
|
|
make_directory(${GEODE_CODEGEN_PATH}/Geode)
|
2022-10-13 07:00:41 -04:00
|
|
|
|
file(TOUCH ${GEODE_CODEGEN_PATH}/Geode/GeneratedSource.cpp)
|
2022-08-08 14:18:09 -04:00
|
|
|
|
endif()
|
|
|
|
|
|
2023-01-14 16:45:58 -05:00
|
|
|
|
if (NOT EXISTS ${GEODE_CODEGEN_PATH}/Geode/GeneratedAddress.cpp)
|
|
|
|
|
make_directory(${GEODE_CODEGEN_PATH})
|
|
|
|
|
make_directory(${GEODE_CODEGEN_PATH}/Geode)
|
|
|
|
|
file(TOUCH ${GEODE_CODEGEN_PATH}/Geode/GeneratedAddress.cpp)
|
|
|
|
|
endif()
|
|
|
|
|
|
2023-01-14 18:00:59 -05:00
|
|
|
|
add_library(GeodeCodegenSources ${GEODE_CODEGEN_PATH}/Geode/GeneratedSource.cpp ${GEODE_CODEGEN_PATH}/Geode/GeneratedAddress.cpp)
|
|
|
|
|
target_link_directories(GeodeCodegenSources PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/loader/include/link)
|
2023-03-29 08:23:57 -04:00
|
|
|
|
target_link_libraries(GeodeCodegenSources PRIVATE ghc_filesystem GeodeFilesystemImpl fmt TulipHookInclude mat-json)
|
2023-01-14 18:00:59 -05:00
|
|
|
|
target_include_directories(GeodeCodegenSources PRIVATE
|
|
|
|
|
${GEODE_CODEGEN_PATH}
|
|
|
|
|
${GEODE_LOADER_PATH}/include
|
|
|
|
|
${GEODE_LOADER_PATH}/include/Geode/cocos/include
|
|
|
|
|
${GEODE_LOADER_PATH}/include/Geode/cocos/extensions
|
|
|
|
|
${GEODE_LOADER_PATH}/include/Geode/fmod
|
|
|
|
|
)
|
|
|
|
|
target_compile_features(GeodeCodegenSources PUBLIC cxx_std_20)
|
2023-01-24 11:37:59 -05:00
|
|
|
|
if (NOT GEODE_DISABLE_PRECOMPILED_HEADERS)
|
|
|
|
|
target_precompile_headers(GeodeCodegenSources INTERFACE
|
|
|
|
|
"${GEODE_LOADER_PATH}/include/Geode/Bindings.hpp"
|
|
|
|
|
)
|
|
|
|
|
endif()
|
2022-07-30 12:24:03 -04:00
|
|
|
|
|
|
|
|
|
target_include_directories(${PROJECT_NAME} INTERFACE
|
2022-10-13 07:00:41 -04:00
|
|
|
|
${GEODE_CODEGEN_PATH}
|
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
|
|
|
|
|
)
|
|
|
|
|
target_link_directories(${PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/loader/include/link)
|
|
|
|
|
|
2023-02-08 09:37:37 -05:00
|
|
|
|
target_link_libraries(${PROJECT_NAME} INTERFACE ghc_filesystem fmt TulipHookInclude GeodeCodegenSources mat-json GeodeFilesystemImpl)
|
2022-07-30 12:24:03 -04:00
|
|
|
|
|
2022-08-08 14:18:09 -04:00
|
|
|
|
|
2022-07-30 12:24:03 -04:00
|
|
|
|
if (NOT EXISTS ${GEODE_BIN_PATH})
|
|
|
|
|
make_directory(${GEODE_BIN_PATH})
|
|
|
|
|
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)
|
|
|
|
|
elseif(EXISTS ${GEODE_PLATFORM_BIN_PATH})
|
|
|
|
|
target_link_libraries(${PROJECT_NAME} INTERFACE "${GEODE_PLATFORM_BIN_PATH}")
|
2022-10-14 16:44:33 -04:00
|
|
|
|
target_precompile_headers(${PROJECT_NAME} INTERFACE
|
2022-10-15 22:36:21 -04:00
|
|
|
|
"${GEODE_LOADER_PATH}/include/Geode/DefaultInclude.hpp"
|
2023-01-14 16:45:58 -05:00
|
|
|
|
"${GEODE_LOADER_PATH}/include/Geode/Geode.hpp"
|
2022-12-13 02:14:19 -05:00
|
|
|
|
# please stop adding modify here its not here because it makes windows compilation take longer than geode 1.0 release date
|
2022-10-14 16:42:35 -04:00
|
|
|
|
)
|
2022-07-30 12:24:03 -04:00
|
|
|
|
else()
|
2022-10-17 08:46:36 -04:00
|
|
|
|
message(FATAL_ERROR
|
2023-02-02 20:06:23 -05:00
|
|
|
|
"No valid loader binary to link to! Install prebuilts with `geode sdk install-binaries`, "
|
|
|
|
|
"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()
|