cmake_minimum_required(VERSION 3.20)
project(AnyPS5IcuHost LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}/bin>")
add_compile_definitions(U_STATIC_IMPLEMENTATION)
function(icu_sources result directory)
    file(STRINGS ${ICU_SOURCE_DIR}/${directory}/sources.txt names)
    list(TRANSFORM names PREPEND ${ICU_SOURCE_DIR}/${directory}/)
    set(${result} ${names} PARENT_SCOPE)
endfunction()
icu_sources(common common)
add_library(host_common STATIC ${common} ${ICU_SOURCE_DIR}/stubdata/stubdata.cpp)
target_compile_definitions(host_common PRIVATE U_COMMON_IMPLEMENTATION)
target_include_directories(host_common PUBLIC ${ICU_SOURCE_DIR}/common)
find_package(Threads REQUIRED)
target_link_libraries(host_common PUBLIC Threads::Threads ${CMAKE_DL_LIBS})
icu_sources(i18n i18n)
add_library(host_i18n STATIC ${i18n})
target_compile_definitions(host_i18n PRIVATE U_I18N_IMPLEMENTATION)
target_include_directories(host_i18n PUBLIC ${ICU_SOURCE_DIR}/i18n)
target_link_libraries(host_i18n PUBLIC host_common)
icu_sources(toolutil tools/toolutil)
add_library(host_toolutil STATIC ${toolutil})
target_compile_definitions(host_toolutil PRIVATE U_TOOLUTIL_IMPLEMENTATION)
target_include_directories(host_toolutil PUBLIC ${ICU_SOURCE_DIR}/tools/toolutil)
target_link_libraries(host_toolutil PUBLIC host_i18n)
foreach(tool genbrk gendict genrb gencnval icupkg genccode)
    icu_sources(sources tools/${tool})
    add_executable(${tool} ${sources})
    target_link_libraries(${tool} PRIVATE host_toolutil)
    set_target_properties(${tool} PROPERTIES LINKER_LANGUAGE CXX)
    if(WIN32)
        target_link_libraries(${tool} PRIVATE advapi32)
        set_target_properties(${tool} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/${tool}/host)
        foreach(config DEBUG RELEASE RELWITHDEBINFO MINSIZEREL)
            set_target_properties(${tool} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${config} ${CMAKE_BINARY_DIR}/bin/${tool}/host)
        endforeach()
        if(MINGW)
            target_link_options(${tool} PRIVATE -static -static-libgcc -static-libstdc++)
        endif()
    endif()
endforeach()
