cmake_minimum_required(VERSION 3.25)
project(spaceshooter)

set(STDCPP_LIB stdc++ -static)

set(PATH_ALLEGRO_STATIC "" CACHE PATH "Path to allegro static libs")
set(PATH_DEPS_STATIC "" CACHE PATH "Path to dependencies static libs")

include_directories("lib/" "network/" "objects/")

# STATIC LIBRARY ALLEGRO 5
# https://github.com/liballeg/allegro5/releases

add_library(allegro STATIC IMPORTED)
set_property(TARGET allegro PROPERTY IMPORTED_LOCATION "${PATH_ALLEGRO_STATIC}/liballegro-static.a")
add_library(allegro_primitives STATIC IMPORTED)
set_property(TARGET allegro_primitives PROPERTY IMPORTED_LOCATION "${PATH_ALLEGRO_STATIC}/liballegro_primitives-static.a")
add_library(allegro_dialog STATIC IMPORTED)
set_property(TARGET allegro_dialog PROPERTY IMPORTED_LOCATION "${PATH_ALLEGRO_STATIC}/liballegro_dialog-static.a")
add_library(allegro_image STATIC IMPORTED)
set_property(TARGET allegro_image PROPERTY IMPORTED_LOCATION "${PATH_ALLEGRO_STATIC}/liballegro_image-static.a")
add_library(allegro_font STATIC IMPORTED)
set_property(TARGET allegro_font PROPERTY IMPORTED_LOCATION "${PATH_ALLEGRO_STATIC}/liballegro_font-static.a")
add_library(allegro_ttf STATIC IMPORTED)
set_property(TARGET allegro_ttf PROPERTY IMPORTED_LOCATION "${PATH_ALLEGRO_STATIC}/liballegro_ttf-static.a")
add_library(allegro_audio STATIC IMPORTED)
set_property(TARGET allegro_audio PROPERTY IMPORTED_LOCATION "${PATH_ALLEGRO_STATIC}/liballegro_audio-static.a")
add_library(allegro_acodec STATIC IMPORTED)
set_property(TARGET allegro_acodec PROPERTY IMPORTED_LOCATION "${PATH_ALLEGRO_STATIC}/liballegro_acodec-static.a")

# DEPENDENCIES
# https://github.com/liballeg/allegro_winpkg/releases

add_library(dumb STATIC IMPORTED)
set_property(TARGET dumb PROPERTY IMPORTED_LOCATION "${PATH_DEPS_STATIC}/libdumb.a")
add_library(FLAC STATIC IMPORTED)
set_property(TARGET FLAC PROPERTY IMPORTED_LOCATION "${PATH_DEPS_STATIC}/libFLAC.a")
add_library(freetype STATIC IMPORTED)
set_property(TARGET freetype PROPERTY IMPORTED_LOCATION "${PATH_DEPS_STATIC}/libfreetype.a")
add_library(jpeg STATIC IMPORTED)
set_property(TARGET jpeg PROPERTY IMPORTED_LOCATION "${PATH_DEPS_STATIC}/libjpeg.a")
add_library(ogg STATIC IMPORTED)
set_property(TARGET ogg PROPERTY IMPORTED_LOCATION "${PATH_DEPS_STATIC}/libogg.a")
add_library(opus STATIC IMPORTED)
set_property(TARGET opus PROPERTY IMPORTED_LOCATION "${PATH_DEPS_STATIC}/libopus.a")
add_library(opusfile STATIC IMPORTED)
set_property(TARGET opusfile PROPERTY IMPORTED_LOCATION "${PATH_DEPS_STATIC}/libopusfile.a")
add_library(physfs STATIC IMPORTED)
set_property(TARGET physfs PROPERTY IMPORTED_LOCATION "${PATH_DEPS_STATIC}/libphysfs.a")
add_library(png16 STATIC IMPORTED)
set_property(TARGET png16 PROPERTY IMPORTED_LOCATION "${PATH_DEPS_STATIC}/libpng16.a")
add_library(theoradec STATIC IMPORTED)
set_property(TARGET theoradec PROPERTY IMPORTED_LOCATION "${PATH_DEPS_STATIC}/libtheoradec.a")
add_library(vorbis STATIC IMPORTED)
set_property(TARGET vorbis PROPERTY IMPORTED_LOCATION "${PATH_DEPS_STATIC}/libvorbis.a")
add_library(vorbisfile STATIC IMPORTED)
set_property(TARGET vorbisfile PROPERTY IMPORTED_LOCATION "${PATH_DEPS_STATIC}/libvorbisfile.a")
add_library(webp STATIC IMPORTED)
set_property(TARGET webp PROPERTY IMPORTED_LOCATION "${PATH_DEPS_STATIC}/libwebp.a")
add_library(webpdecoder STATIC IMPORTED)
set_property(TARGET webpdecoder PROPERTY IMPORTED_LOCATION "${PATH_DEPS_STATIC}/libwebpdecoder.a")
add_library(webpdemux STATIC IMPORTED)
set_property(TARGET webpdemux PROPERTY IMPORTED_LOCATION "${PATH_DEPS_STATIC}/libwebpdemux.a")
add_library(zlib STATIC IMPORTED)
set_property(TARGET zlib PROPERTY IMPORTED_LOCATION "${PATH_DEPS_STATIC}/libzlib.a")

# add_library(enet STATIC IMPORTED)
# set_property(TARGET enet PROPERTY IMPORTED_LOCATION "C:/msys64/mingw64/lib/libenet.a")

set(SRC_GAME
    autors.c
    common.c
    data.c
    gameover.c
    main.c
    menu.c
    networkcreate.c
    networkgame.c
    networkjoin.c
    networklist.c
    networkmode.c
    networkout.c
    networkparty.c
    pause.c
    single.c)

set(SRC_LIB
    lib/common.c
    lib/event.c
    lib/instance.c
    lib/interface.c
    lib/media.c
    lib/message.c
    lib/screen.c
    lib/timer.c)

set(SRC_NETWORK network/network.c)

set(SRC_OBJECTS objects/objects.c)

set(ALLEGRO_LIB allegro)
set(ALLEGRO_PRIMITIVES_LIB allegro_primitives)
set(ALLEGRO_DIALOG_LIB allegro_dialog)
set(ALLEGRO_IMAGE_LIB allegro_image)
set(ALLEGRO_FONT_LIB allegro_font)
set(ALLEGRO_TTF_LIB allegro_ttf)
set(ALLEGRO_AUDIO_LIB allegro_audio)
set(ALLEGRO_ACODEC_LIB allegro_acodec)

# https://packages.msys2.org/package/mingw-w64-x86_64-enet?repo=mingw64
set(ENET_LIB enet)

find_library(WINMM_LIB winmm)
find_library(OPENGL32_LIB opengl32)
find_library(GDI32_LIB gdi32)
find_library(OLE32_LIB ole32)
find_library(SHLWAPI_LIB shlwapi)
find_library(DSOUND_LIB dsound)
find_library(WS2_32_LIB ws2_32)

set(FLAC_LIB FLAC)
set(OGG_LIB ogg)
set(VORBIS_LIB vorbis)
set(OPUS_LIB opus)
set(PNG16_LIB png16)
set(FREETYPE_LIB freetype)
set(JPEG_LIB jpeg)
set(WEBP_LIB webp)
set(DUMB_LIB dumb)
set(VORBISFILE_LIB vorbisfile)
set(OPUSFILE_LIB opusfile)
set(Z_LIB zlib)

set(PHYSFS_LIB physfs)

find_library(GDIPLUS_32_LIB gdiplus)
find_library(UUID_LIB uuid)
find_library(KERNEL32_LIB kernel32)
find_library(PSAPI_32_LIB psapi)
find_library(GLU32_32_LIB glu32)
find_library(USER32_LIB user32)
find_library(COMDLG32_LIB Comdlg32)
find_library(SHELL32_LIB shell32)
find_library(ADVAPI32_LIB advapi32)

add_executable(${PROJECT_NAME} WIN32 ${SRC_OBJECTS} ${SRC_LIB} ${SRC_NETWORK} ${SRC_GAME})

target_link_libraries(${PROJECT_NAME}
    ${ALLEGRO_PRIMITIVES_LIB}
    ${ALLEGRO_DIALOG_LIB}
    ${ALLEGRO_IMAGE_LIB}
    ${ALLEGRO_FONT_LIB}
    ${ALLEGRO_TTF_LIB}
    ${ALLEGRO_AUDIO_LIB}
    ${ALLEGRO_ACODEC_LIB}
    ${ALLEGRO_LIB}

    ${ENET_LIB}

    ${JPEG_LIB}
    ${DUMB_LIB}
    ${WEBP_LIB}
    ${FLAC_LIB}
    ${VORBISFILE_LIB}
    ${VORBIS_LIB}
    ${OGG_LIB}
    ${FREETYPE_LIB}
    ${PNG16_LIB}
    ${DSOUND_LIB}
    ${WINMM_LIB}
    ${OPENGL32_LIB}
    ${GDI32_LIB}
    ${OLE32_LIB}
    ${SHLWAPI_LIB}
    ${STDCPP_LIB}
    ${Z_LIB}
    ${OPUSFILE_LIB}
    ${OPUS_LIB}
    ${WS2_32_LIB}

#     ${PHYSFS_LIB}
#     ${GDIPLUS_32_LIB}
#     ${UUID_LIB}
#     ${KERNEL32_LIB}
#     ${PSAPI_32_LIB}
#     ${GLU32_32_LIB}
#     ${USER32_LIB}
#     ${COMDLG32_LIB}
#     ${SHELL32_LIB}
#     ${ADVAPI32_LIB}
    )
