find_package(OpenEnclave CONFIG REQUIRED)

set(EDL ${CMAKE_CURRENT_SOURCE_DIR}/../tls_server.edl)

add_custom_command(
  OUTPUT tls_server_u.h tls_server_u.c tls_server_args.h
  DEPENDS ${EDL}
  COMMAND openenclave::oeedger8r --untrusted ${EDL}
          --search-path ${OE_INCLUDEDIR}
          --search-path ${OE_INCLUDEDIR}/openenclave/edl
          --search-path ${OE_INCLUDEDIR}/openenclave/edl/sgx)

add_library(
  tls_server_host STATIC
  host.cpp
  receiver.cpp
  server_init_config.hpp
  ${CMAKE_CURRENT_BINARY_DIR}/tls_server_u.c)

target_include_directories(
  tls_server_host
  PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_BINARY_DIR}
    ${PROJECT_SOURCE_DIR}/src/interfaces/libpq/encryptsql/src/KeyDistribution/common
    ${PROJECT_SOURCE_DIR}/include
    ${PROJECT_SOURCE_DIR}/pg_include
    ${PROJECT_SOURCE_DIR}/db_include)

target_compile_options(tls_server_host PRIVATE -fPIC)

target_compile_features(tls_server_host PRIVATE cxx_std_17)

target_link_libraries(
  tls_server_host
  keydistribution_common
  openenclave::oehost
  OpenSSL::SSL
  OpenSSL::Crypto
  pthread)
