cmake_minimum_required(VERSION 3.24)
project(PKCS11KeyWrapping C)
set(CMAKE_C_STANDARD 99)

include_directories("/usr/include/openssl")
include_directories("include")

add_library(PKCS11KeyWrappingLibrary SHARED openvpn_pkcs11_key_wrapping.c pkcs11_handler.c shared.c)
add_executable(PKCS11KeyWrappingExec pkcs11_handler.c shared.c)

set_property(TARGET PKCS11KeyWrappingLibrary PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET PKCS11KeyWrappingLibrary PROPERTY COMPILE_WARNING_AS_ERROR ON)

include(CheckCCompilerFlag)
check_c_compiler_flag(-Wwrite-strings HAVE_STRING_WARN)

if (HAVE_STRING_WARN)
    target_compile_options(PKCS11KeyWrappingLibrary PRIVATE -Wno-write-strings)
    target_compile_options(PKCS11KeyWrappingExec PRIVATE -Wno-write-strings)
endif(HAVE_STRING_WARN)

target_link_libraries(PKCS11KeyWrappingLibrary ssl crypto)
target_link_libraries(PKCS11KeyWrappingExec ssl crypto)