# SPDX-License-Identifier: GPL-3.0-or-later OR BSD-2-Clause
option(UC2_BUILD_WCX "Build the Total Commander read-only plugin" OFF)
set(UC2_WCX_SDK_DIR "" CACHE PATH "Directory containing official wcxhead.h")
if(NOT UC2_BUILD_WCX)
    return()
endif()
if(NOT WIN32 OR NOT EXISTS "${UC2_WCX_SDK_DIR}/wcxhead.h")
    message(FATAL_ERROR "WCX requires Windows/MinGW and UC2_WCX_SDK_DIR with wcxhead.h")
endif()
add_library(uc2_wcx MODULE uc2_wcx.c)
target_include_directories(uc2_wcx PRIVATE "${UC2_WCX_SDK_DIR}")
target_link_libraries(uc2_wcx PRIVATE uc2)
target_compile_features(uc2_wcx PRIVATE c_std_99)
set_target_properties(uc2_wcx PROPERTIES PREFIX "" OUTPUT_NAME "uc2")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
    set_target_properties(uc2_wcx PROPERTIES SUFFIX ".wcx64")
else()
    set_target_properties(uc2_wcx PROPERTIES SUFFIX ".wcx")
endif()
if(MINGW)
    target_link_options(uc2_wcx PRIVATE -Wl,--kill-at -static-libgcc)
endif()
add_executable(test_wcx ${PROJECT_SOURCE_DIR}/tests/wcx/test_wcx.c)
target_include_directories(test_wcx PRIVATE "${UC2_WCX_SDK_DIR}")
if(MINGW)
    target_link_options(test_wcx PRIVATE -municode -static-libgcc)
endif()
install(TARGETS uc2_wcx LIBRARY DESTINATION share/uc2/totalcommander
                       RUNTIME DESTINATION share/uc2/totalcommander)
install(FILES pluginst.inf DESTINATION share/uc2/totalcommander)
