# ncaafootball14 - ReXGlue Recompiled Project
# SDK boilerplate lives in generated/rexglue.cmake.

cmake_minimum_required(VERSION 3.25)
project(ncaafootball14 VERSION 0.1.1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(generated/rexglue.cmake)

# libarchive reads the .rar College Football Revamped ships its packages in.
# Only the RAR readers are wanted, so every optional library is off.
include(FetchContent)
foreach(opt ENABLE_TEST ENABLE_TAR ENABLE_CPIO ENABLE_CAT ENABLE_UNZIP ENABLE_INSTALL ENABLE_WERROR
            ENABLE_OPENSSL ENABLE_MBEDTLS ENABLE_NETTLE ENABLE_LIBB2 ENABLE_LZ4 ENABLE_LZO ENABLE_LZMA
            ENABLE_ZSTD ENABLE_ZLIB ENABLE_BZip2 ENABLE_LIBXML2 ENABLE_EXPAT ENABLE_PCREPOSIX
            ENABLE_PCRE2POSIX ENABLE_ICONV ENABLE_ACL ENABLE_XATTR)
    set(${opt} OFF CACHE BOOL "" FORCE)
endforeach()
# libarchive's random source on Windows calls BCrypt whether or not CNG is
# enabled, and only ENABLE_CNG links bcrypt.
set(ENABLE_CNG ON CACHE BOOL "" FORCE)
set(BUILD_SHARED_LIBS OFF)
FetchContent_Declare(libarchive
    GIT_REPOSITORY https://github.com/libarchive/libarchive.git
    GIT_TAG v3.8.9
    GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(libarchive)
add_library(ncaa14_unpack INTERFACE)
target_link_libraries(ncaa14_unpack INTERFACE archive_static)
target_include_directories(ncaa14_unpack INTERFACE "${libarchive_SOURCE_DIR}/libarchive")
target_compile_definitions(ncaa14_unpack INTERFACE LIBARCHIVE_STATIC)

# Sources
set(NCAAFOOTBALL14_SOURCES
    src/main.cpp
)

if(WIN32)
    # Clang's MSVC-style driver does not put rc.exe on the path and CMake only
    # looks for rc there, so llvm-rc stands in when that is what exists.
    if(NOT CMAKE_RC_COMPILER)
        find_program(_rc_compiler NAMES rc llvm-rc)
        if(_rc_compiler)
            set(CMAKE_RC_COMPILER "${_rc_compiler}")
        endif()
    endif()
    enable_language(RC)
    set(PACKAGING_WINDOWS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/packaging/windows")
    configure_file(packaging/windows/ncaafootball14.manifest
                   ncaafootball14.manifest @ONLY)
    configure_file(packaging/windows/ncaafootball14.rc.in
                   ncaafootball14.rc @ONLY)
    # A .manifest source is merged into the manifest the linker embeds; one
    # placed in the resource script would collide with it.
    add_executable(ncaafootball14 WIN32 ${NCAAFOOTBALL14_SOURCES}
                   "${CMAKE_CURRENT_BINARY_DIR}/ncaafootball14.rc"
                   "${CMAKE_CURRENT_BINARY_DIR}/ncaafootball14.manifest")
else()
    add_executable(ncaafootball14 ${NCAAFOOTBALL14_SOURCES})
endif()

# Stages librexgpu-xenos.so next to the executable: the plugin is loaded from
# the executable's directory, not through LD_LIBRARY_PATH.
rexglue_setup_target(ncaafootball14 GPU_PLUGINS xenos)
target_link_libraries(ncaafootball14 PRIVATE ncaa14_unpack)

# Standalone check of the launcher's mod installer; runs without a window, so
# it can be exercised on any build machine.
add_executable(ncaa14_mod_install_test tools/mod_install_test.cpp)
target_include_directories(ncaa14_mod_install_test PRIVATE src)
target_link_libraries(ncaa14_mod_install_test PRIVATE rex::runtime ncaa14_unpack)
