cmake_minimum_required(VERSION 3.24)
project(pingpang)

# 标准 C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 引用 godot-cpp（CMake 方式）
set(GODOT_CPP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/godot-cpp")
add_subdirectory("${GODOT_CPP_PATH}")

# 扩展库本体
add_library(pingpang SHARED
    src/register_types.cpp
    src/register_types.h
    src/pingpong_ball.cpp
    src/pingpong_ball.h
    src/pingpong_paddle.cpp
    src/pingpong_paddle.h
    src/pingpong_game.cpp
    src/pingpong_game.h
)

target_include_directories(pingpang PRIVATE src)

# 链接 godot-cpp
target_link_libraries(pingpang PRIVATE godot-cpp)

# 输出到 main/bin/ 目录（Godot 项目从这里加载 GDExtension）
set_target_properties(pingpang PROPERTIES
    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/main/bin"
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/main/bin"
    ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/main/bin"
    PREFIX ""
)

# VS 多配置生成器会输出到子目录，这里复制到 main/bin/ 根目录
add_custom_command(TARGET pingpang POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
        "$<TARGET_FILE:pingpang>"
        "${CMAKE_CURRENT_SOURCE_DIR}/main/bin/$<TARGET_FILE_NAME:pingpang>"
    COMMENT "复制 pingpang.dll 到 main/bin/ 根目录"
)
