cmake_minimum_required(VERSION 3.20)
project(mpemtrans VERSION 0.1.0 LANGUAGES C)
set(CMAKE_C_STANDARD 11)
# Windows archives contain one executable, with OpenSSL and the C runtime
# linked statically. Linux uses the distribution-maintained shared libcrypto.
if(WIN32)
  set(OPENSSL_USE_STATIC_LIBS TRUE)
  set(OPENSSL_MSVC_STATIC_RT TRUE)
  set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
else()
  set(OPENSSL_USE_STATIC_LIBS FALSE)
endif()
find_package(OpenSSL 3.0 REQUIRED COMPONENTS Crypto)
find_package(Threads REQUIRED)
find_path(CRYPTLIB_INCLUDE_DIR cryptlib.h REQUIRED)
add_executable(mpemtrans pemtrans.c)
target_include_directories(mpemtrans PRIVATE ${CRYPTLIB_INCLUDE_DIR})
target_link_libraries(mpemtrans PRIVATE OpenSSL::Crypto Threads::Threads ${CMAKE_DL_LIBS})
if(WIN32)
  target_link_libraries(mpemtrans PRIVATE advapi32)
  target_compile_definitions(mpemtrans PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
