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-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
project ( geode-sdk VERSION ${ GEODE_VERSION } LANGUAGES CXX C )
2022-07-30 12:24:03 -04:00
set ( CMAKE_CXX_STANDARD 20 )
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
2022-10-11 16:56:12 -04:00
if ( PROJECT_IS_TOP_LEVEL AND APPLE )
2022-10-04 06:32:40 -04:00
set ( CMAKE_BUILD_TYPE Debug )
endif ( )
2022-07-30 12:24:03 -04:00
add_library ( ${ PROJECT_NAME } INTERFACE )
2022-10-12 15:07:18 -04:00
if ( CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo )
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 } )
2022-10-12 17:22:43 -04:00
if ( GEODE_DEBUG )
target_compile_definitions ( ${ PROJECT_NAME } INTERFACE GEODE_DEBUG )
endif ( )
2022-07-30 12:24:03 -04:00
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 )
target_sources ( ${ PROJECT_NAME } INTERFACE ${ CMAKE_CURRENT_SOURCE_DIR } /entry.cpp )
add_subdirectory ( codegen )
add_custom_target ( CodegenRun ALL
C O M M A N D C o d e g e n $ { G E O D E _ T A R G E T _ P L A T F O R M } b i n d i n g s $ { G E O D E _ C O D E G E N _ P A T H }
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
C O M M E N T " R u n C o d e g e n "
2022-10-13 07:00:41 -04:00
B Y P R O D U C T S $ { G E O D E _ C O D E G E N _ P A T H } / G e o d e / G e n e r a t e d S o u r c e . c p p
2022-07-30 12:24:03 -04:00
)
add_dependencies ( ${ PROJECT_NAME } CodegenRun )
add_dependencies ( CodegenRun Codegen )
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 ( )
2022-10-13 07:00:41 -04:00
target_sources ( ${ PROJECT_NAME } INTERFACE ${ GEODE_CODEGEN_PATH } /Geode/GeneratedSource.cpp )
2022-07-30 12:24:03 -04:00
target_include_directories ( ${ PROJECT_NAME } INTERFACE
2022-10-13 07:00:41 -04:00
$ { G E O D E _ C O D E G E N _ P A T H }
2022-07-30 12:24:03 -04:00
$ { G E O D E _ L O A D E R _ P A T H } / i n c l u d e
$ { G E O D E _ L O A D E R _ P A T H } / i n c l u d e / G e o d e / c o c o s /
$ { G E O D E _ L O A D E R _ P A T H } / i n c l u d e / G e o d e / c o c o s / c o c o s 2 d x
$ { G E O D E _ L O A D E R _ P A T H } / i n c l u d e / G e o d e / c o c o s / c o c o s 2 d x / i n c l u d e
$ { G E O D E _ L O A D E R _ P A T H } / i n c l u d e / G e o d e / c o c o s / c o c o s 2 d x / s u p p o r t / z i p _ s u p p o r t
$ { G E O D E _ L O A D E R _ P A T H } / i n c l u d e / G e o d e / c o c o s / c o c o s 2 d x / k a z m a t h / i n c l u d e
$ { G E O D E _ L O A D E R _ P A T H } / i n c l u d e / G e o d e / c o c o s / e x t e n s i o n s
$ { G E O D E _ L O A D E R _ P A T H } / i n c l u d e / G e o d e / f m o d
)
target_link_directories ( ${ PROJECT_NAME } INTERFACE ${ CMAKE_CURRENT_SOURCE_DIR } /loader/include/link )
add_subdirectory ( filesystem )
add_subdirectory ( fmt )
target_link_libraries ( ${ PROJECT_NAME } INTERFACE filesystem fmt )
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-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}" )
target_precompile_headers ( ${ PROJECT_NAME } INTERFACE "${GEODE_LOADER_PATH}/include/Geode/Geode.hpp" )
else ( )
message ( FATAL_ERROR "No valid loader binary to link to! Install a pre-built binary for version ${PROJECT_VERSION} with Geode CLI or build it from source." )
endif ( )