cmake_minimum_required(VERSION 3.20)
project(xenogears_native_hook_example C)
set(PSX_NATIVE_SDK_INCLUDE "${CMAKE_CURRENT_LIST_DIR}/../../psxrecomp/runtime/include"
    CACHE PATH "Directory containing the standalone mod_native_api.h SDK")
add_library(native_hook_example SHARED native_hook.c)
include(CheckLanguage)
check_language(CXX)
set(_examples native_hook_example)
if(CMAKE_CXX_COMPILER)
    enable_language(CXX)
    add_library(native_hook_cpp_example SHARED native_hook_cpp.cpp)
    set_target_properties(native_hook_cpp_example PROPERTIES PREFIX "" CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
    add_library(native_hook_named_example SHARED native_hook_named.cpp)
    set_target_properties(native_hook_named_example PROPERTIES PREFIX "" CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
    list(APPEND _examples native_hook_cpp_example native_hook_named_example)
endif()
set_target_properties(native_hook_example PROPERTIES PREFIX "" C_STANDARD 99)
foreach(_example IN LISTS _examples)
    target_include_directories(${_example} PRIVATE "${PSX_NATIVE_SDK_INCLUDE}")
    if(MSVC)
        set_target_properties(${_example} PROPERTIES
            MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
    elseif(MINGW)
        target_link_options(${_example} PRIVATE -static-libgcc)
    endif()
endforeach()
if(MINGW AND TARGET native_hook_cpp_example)
    target_link_options(native_hook_cpp_example PRIVATE -static-libstdc++)
    target_link_options(native_hook_named_example PRIVATE -static-libstdc++)
endif()
