2024-01-13 12:21:13 +00:00
|
|
|
# Configuration can be used as a template for custom project, read comments
|
2024-01-09 21:35:20 +00:00
|
|
|
cmake_minimum_required(VERSION 3.6)
|
2024-01-13 12:21:13 +00:00
|
|
|
project(gdexample LANGUAGES CXX)
|
|
|
|
|
|
|
|
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo;MinSizeRel")
|
|
|
|
set(GODOT_CPP_PATH ../) # path to godot-cpp repository
|
2021-12-24 00:29:21 +00:00
|
|
|
|
2023-12-31 17:17:35 +00:00
|
|
|
add_subdirectory(
|
2024-01-13 12:21:13 +00:00
|
|
|
${GODOT_CPP_PATH}
|
2023-12-31 17:17:35 +00:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/godot-cpp # needed because godot-cpp is top directory
|
|
|
|
)
|
2023-08-16 09:47:19 +00:00
|
|
|
|
2021-12-24 00:29:21 +00:00
|
|
|
# Get Sources
|
|
|
|
file(GLOB_RECURSE SOURCES src/*.c**)
|
2024-01-13 12:21:13 +00:00
|
|
|
file(GLOB_RECURSE HEADERS src/*.h**)
|
2021-12-24 00:29:21 +00:00
|
|
|
|
|
|
|
# Define our godot-cpp library
|
2023-12-31 17:17:35 +00:00
|
|
|
if(${PLATFORM} STREQUAL "WEB")
|
|
|
|
# wasm libraries loaded with dlopen() are created like this in cmake
|
|
|
|
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
|
|
|
|
set_target_properties(${PROJECT_NAME}
|
|
|
|
PROPERTIES
|
|
|
|
PREFIX "lib"
|
|
|
|
SUFFIX ".wasm"
|
2024-01-13 12:21:13 +00:00
|
|
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin"
|
2024-01-09 21:35:20 +00:00
|
|
|
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/project/bin"
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/project/bin"
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/project/bin"
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_CURRENT_SOURCE_DIR}/project/bin"
|
|
|
|
|
2023-12-31 17:17:35 +00:00
|
|
|
)
|
|
|
|
elseif(${PLATFORM} STREQUAL "MACOS")
|
|
|
|
# TODO: create framework with cmake FRAMEWORK property
|
|
|
|
# or with template file
|
|
|
|
message(WARNING "Mac/IOS framework configuration is not tested and may not work.")
|
|
|
|
|
|
|
|
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS})
|
|
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
|
|
|
FRAMEWORK TRUE
|
|
|
|
MACOSX_FRAMEWORK_IDENTIFIER com.godotengine.${PROJECT_NAME}
|
|
|
|
MACOSX_FRAMEWORK_INFO_PLIST Info.plist
|
|
|
|
)
|
2021-12-24 00:29:21 +00:00
|
|
|
else()
|
2023-12-31 17:17:35 +00:00
|
|
|
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS})
|
2021-12-24 00:29:21 +00:00
|
|
|
endif()
|
|
|
|
|
2023-12-31 17:17:35 +00:00
|
|
|
target_link_libraries(${PROJECT_NAME} PUBLIC godot-cpp)
|
2021-12-24 00:29:21 +00:00
|
|
|
|
2024-01-13 12:21:13 +00:00
|
|
|
get_directory_property(GODOT_CC_FLAGS DIRECTORY ${GODOT_CPP_PATH} DEFINITION GODOT_CC_FLAGS)
|
|
|
|
get_directory_property(GODOT_CXX_FLAGS DIRECTORY ${GODOT_CPP_PATH} DEFINITION GODOT_CXX_FLAGS)
|
2023-12-31 17:17:35 +00:00
|
|
|
target_compile_options(${PROJECT_NAME} PRIVATE
|
|
|
|
${GODOT_CC_FLAGS}
|
|
|
|
${GODOT_CXX_FLAGS}
|
|
|
|
)
|
2021-12-24 00:29:21 +00:00
|
|
|
|
2024-01-13 12:21:13 +00:00
|
|
|
get_directory_property(GODOT_LINK_FLAGS DIRECTORY ${GODOT_CPP_PATH} DEFINITION GODOT_LINK_FLAGS)
|
2023-12-31 17:17:35 +00:00
|
|
|
target_link_options(${PROJECT_NAME} PRIVATE ${GODOT_LINK_FLAGS})
|
2022-01-23 18:54:51 +00:00
|
|
|
|
2021-12-24 00:29:21 +00:00
|
|
|
|
2024-01-13 12:21:13 +00:00
|
|
|
get_directory_property(LIBRARY_SUFFIX DIRECTORY ${GODOT_CPP_PATH} DEFINITION LIBRARY_SUFFIX)
|
2023-12-31 17:17:35 +00:00
|
|
|
set_target_properties(${PROJECT_NAME}
|
|
|
|
PROPERTIES
|
2024-01-13 12:21:13 +00:00
|
|
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin"
|
2024-01-09 21:35:20 +00:00
|
|
|
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/project/bin"
|
|
|
|
LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/project/bin"
|
|
|
|
LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/project/bin"
|
|
|
|
LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_CURRENT_SOURCE_DIR}/project/bin"
|
|
|
|
|
2023-12-31 17:17:35 +00:00
|
|
|
OUTPUT_NAME "${PROJECT_NAME}${LIBRARY_SUFFIX}"
|
|
|
|
)
|
2024-01-09 21:35:20 +00:00
|
|
|
if(${GODOT_CPP_WARNING_AS_ERROR})
|
|
|
|
set_warning_as_error(${PROJECT_NAME})
|
|
|
|
endif()
|
2021-12-24 00:29:21 +00:00
|
|
|
|