cmake_minimum_required(VERSION 3.16)

project(transm LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(MSVC)
add_compile_options(/source-charset:utf-8)
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_SYSTEM_NAME MATCHES "Windows")
message(status "add mingw param.")
add_compile_options(-finput-charset=utf-8)
add_compile_options(-fexec-charset=gbk)
add_compile_options(-Wa,-mbig-obj)
endif()

if(DEFINED IOS_ISH)
message(STATUS "INPUT IOS_ISH ${IOS_ISH}")
endif()

set(CMAKE_DEBUG_POSTFIX "d")
message(STATUS "System: ${CMAKE_SYSTEM_NAME}")
message(STATUS "Compiler CXX ID: ${CMAKE_CXX_COMPILER_ID}")

set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
    ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}/
)

add_definitions(-DFMT_HEADER_ONLY)
add_definitions(-D_WIN32_WINNT=0x0601)
include_directories(3rd)
include_directories(.)
include_directories(${PROJECT_BINARY_DIR})
add_subdirectory(ofen)
add_subdirectory(net)
add_subdirectory(util)
add_subdirectory(server)
add_subdirectory(client)
add_subdirectory(filecomplete)

string(TIMESTAMP VERSION_BUILD_DATE "%Y-%m-%d %H:%M")
execute_process(
    COMMAND git rev-parse --short HEAD
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    OUTPUT_VARIABLE VERSION_GIT_HASH
    OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
    COMMAND git rev-parse --abbrev-ref HEAD
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    OUTPUT_VARIABLE VERSION_GIT_BRANCH
    OUTPUT_STRIP_TRAILING_WHITESPACE
)
configure_file(version.h.in version.h)
message(STATUS "build dir:${PROJECT_BINARY_DIR}")

# add_executable(transm_test1 test1.cpp)
# target_link_libraries(transm_test1 PRIVATE trans_net trans_util)
# add_executable(transm_test2 test2.cpp)
# target_link_libraries(transm_test2 PRIVATE trans_net trans_util)
