cmake_minimum_required(VERSION 3.20)
cmake_policy(SET CMP0091 NEW)
project(DefJamSetup LANGUAGES CXX RC)
if(NOT WIN32)
    message(FATAL_ERROR "Windows setup first; macOS/Linux installers are to-dos")
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
# The shield icon and the file properties, with the version of the source this setup carries.
include(../cmake/windows_resource.cmake)
file(STRINGS ../CMakeLists.txt version_line REGEX "^project[(]defjam_recomp VERSION [0-9.]+")
string(REGEX REPLACE ".*VERSION ([0-9.]+).*" "\\1" DEFJAM_VERSION "${version_line}")
defjam_windows_resource(LAUNCHER_RC NAME DefJamLauncher VERSION ${DEFJAM_VERSION}
                        DESCRIPTION "Def Jam: Fight for NY - Recompiled launcher")
defjam_windows_resource(SETUP_RC NAME DefJamSetup VERSION ${DEFJAM_VERSION}
                        DESCRIPTION "Def Jam: Fight for NY - Recompiled setup")
add_executable(DefJamLauncher WIN32 main.cpp app.manifest "${LAUNCHER_RC}")
target_compile_definitions(DefJamLauncher PRIVATE DEFJAM_LAUNCHER_ONLY UNICODE _UNICODE NOMINMAX)
target_link_libraries(DefJamLauncher PRIVATE comctl32 shell32 ole32 uuid bcrypt)
target_compile_options(DefJamLauncher PRIVATE /utf-8)
set(SETUP_PAYLOAD "" CACHE FILEPATH "Verified payload ZIP to embed in the setup executable")
if(SETUP_PAYLOAD)
    file(TO_CMAKE_PATH "${SETUP_PAYLOAD}" PAYLOAD_PATH)
    file(SHA256 "${SETUP_PAYLOAD}" PAYLOAD_SHA256)
    configure_file(payload.rc.in payload.rc @ONLY)
    add_executable(DefJamSetup WIN32 main.cpp app.manifest "${SETUP_RC}" "${CMAKE_CURRENT_BINARY_DIR}/payload.rc")
    target_compile_definitions(DefJamSetup PRIVATE UNICODE _UNICODE NOMINMAX PAYLOAD_SHA256=L"${PAYLOAD_SHA256}")
    target_link_libraries(DefJamSetup PRIVATE comctl32 shell32 ole32 uuid bcrypt)
    target_compile_options(DefJamSetup PRIVATE /utf-8)
endif()
