cmake_minimum_required(VERSION 3.16)
project(DNF C CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/DNF)

set(CMAKE_CXX_STANDARD 17)

# 添加子目录，引用squirrel项目
add_subdirectory(Library/squirrel)
# 添加zlib子项目
set(ZLIB_BUILD_SHARED OFF CACHE BOOL "Disable zlib shared library" FORCE)
set(ZLIB_BUILD_STATIC ON CACHE BOOL "Enable zlib static library" FORCE)
add_subdirectory(Library/zlib-1.3.1)

# 添加SDL2子项目
set(SDL2_DISABLE_INSTALL ON CACHE BOOL "Disable SDL2 installation" FORCE)
set(SDL_STATIC ON CACHE BOOL "Build SDL2 as static library" FORCE)
set(SDL_SHARED OFF CACHE BOOL "Disable SDL2 shared library" FORCE)
set(SDL_BUILD_EXAMPLES OFF CACHE BOOL "Disable SDL2 examples" FORCE)
add_subdirectory(Library/SDL2-2.28.5)

set(SDL2IMAGE_INSTALL OFF CACHE BOOL "Disable SDL2_image installation" FORCE)
set(SDL2IMAGE_BUILD_SHARED OFF CACHE BOOL "Disable SDL2_image shared library" FORCE)
set(SDL2IMAGE_BUILD_STATIC ON CACHE BOOL "Enable SDL2_image static library" FORCE)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Force SDL2_image to build as static library" FORCE)
set(SDL2IMAGE_SAMPLES OFF CACHE BOOL "Disable SDL2_image samples (showanim/showimage)" FORCE)
set(SDL2IMAGE_SAMPLES_INSTALL OFF CACHE BOOL "Disable SDL2_image samples installation" FORCE)
add_subdirectory(Library/SDL2_image-2.5.2)

set(SDL2MIXER_INSTALL OFF CACHE BOOL "Disable SDL2_mixer installation" FORCE)
set(SDL2MIXER_VENDORED ON CACHE BOOL "Use vendored libraries (ogg/opus/flac etc.)" FORCE)
set(SDL2MIXER_DEPS_SHARED OFF CACHE BOOL "Compile vendored deps as static libs" FORCE)
set(SDL2MIXER_BUILD_SHARED OFF CACHE BOOL "Disable SDL2_mixer shared library" FORCE)
set(SDL2MIXER_BUILD_STATIC ON CACHE BOOL "Enable SDL2_mixer static library" FORCE)
set(SDL2MIXER_SAMPLES OFF CACHE BOOL "Disable SDL2_mixer examples (playmus/playwave)" FORCE)
add_subdirectory(Library/SDL_mixer)

set(SDL2NET_INSTALL OFF CACHE BOOL "Disable SDL2_net installation" FORCE)
set(SDL2NET_BUILD_SHARED OFF CACHE BOOL "Disable SDL2_net shared library" FORCE)
set(SDL2NET_BUILD_STATIC ON CACHE BOOL "Enable SDL2_net static library" FORCE)
set(SDL2NET_BUILD_EXAMPLES OFF CACHE BOOL "Disable SDL2_net examples" FORCE)
add_subdirectory(Library/SDL2_net-2.1.1)

set(SDL2TTF_INSTALL OFF CACHE BOOL "Disable SDL2_ttf installation" FORCE)
set(SDL2TTF_VENDORED ON CACHE BOOL "Use vendored freetype/harfbuzz libraries" FORCE)
set(SDL2TTF_HARFBUZZ ON CACHE BOOL "Enable harfbuzz support" FORCE)
set(SDL2TTF_BUILD_SHARED OFF CACHE BOOL "Disable SDL2_ttf shared library" FORCE)
set(SDL2TTF_BUILD_STATIC ON CACHE BOOL "Enable SDL2_ttf static library" FORCE)
set(SDL2TTF_BUILD_EXAMPLES OFF CACHE BOOL "Disable SDL2_ttf examples" FORCE)
add_subdirectory(Library/SDL_ttf)



# 收集源文件
file(GLOB_RECURSE SOURCES 
    "Library/src/*.c"
    "source/*.cpp"
    "source_game/*.cpp"
)
add_executable(${PROJECT_NAME} ${SOURCES})

set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O1 -g" CACHE STRING "" FORCE)

# 设置头文件目录（包含所有库的头文件路径）
target_include_directories(${PROJECT_NAME} PRIVATE
    Library/zlib-1.3.1    
    Library/SDL2-2.28.5
    Library/SDL2-2.28.5/SDL2
    Library/include
    Library/include/SDL2
    Library/squirrel/include
    Library/squirrel/squirrel
    Library/squirrel/sqstdlib
    source
    source_game
)

# 指定库文件所在的目录（.lib文件的位置）
link_directories(${PROJECT_SOURCE_DIR}/Library/lib)
message("Link directories: ${PROJECT_SOURCE_DIR}/Library/lib")

# 链接预编译库（确保这里的库文件名与Library/lib中的实际文件名完全一致）
target_link_libraries(${PROJECT_NAME} PRIVATE
    SDL2main
    SDL2-static
    SDL2_image
    SDL2_mixer
    SDL2_ttf
    SDL2_net

    zlibstatic      # zlib库
    squirrel_static  # squirrel库（根据实际目标名调整）
    sqstdlib_static
    iconv  

    mingwex  
    winmm             
    imm32             
    setupapi                
    version           
    ole32    
    uuid                
)
