


set(Enclave_uh Enclave_u.h Enclave_u.c)

add_custom_command(OUTPUT ${Enclave_uh} PRE_BUILD
    COMMAND rm -f Enclave_u.*  && ${SGX_EDGER8R} --untrusted ${EDL_FILES_PATH}/Enclave.edl --search-path ${EDL_FILES_PATH} --search-path ${SGX_SDK}/include 
    COMMENT "make ucode again"
)

# # add_executable(UDFTest UDFTest.cpp )
# # target_link_libraries(UDFTest ${Udf_Lib} -Wl,--as-needed ${OPENSSL_LIBRARIES} ) 

#add_executable(EnclaveTest EnclaveTest.cpp ${Enclave_uh})
#target_link_libraries(EnclaveTest   -Wl,--as-needed ${Udf_Lib} -lsgx_uswitchless  ${jsoncpp_LIBRARY})

# 添加 PostgreSQL 库路径和头文件路径
set(PG_LIB_PATH "/usr/local/postgresql/lib")
set(PG_INCLUDE_PATH "/usr/local/postgresql/include")

link_directories(${PG_LIB_PATH})
include_directories(${PG_INCLUDE_PATH})

# 添加PostgreSQL后端库路径
set(PG_BACKEND_PATH "/new_enc/postgresql-14.2/src/backend")
link_directories(${PG_BACKEND_PATH})

add_executable(EnclaveTest EnclaveTest.cpp ${Enclave_uh})
target_link_libraries(EnclaveTest
    -Wl,--as-needed 
    ${Udf_Lib}
    -lsgx_uswitchless
    ${jsoncpp_LIBRARY}
    -L${SGX_LIBRARY_PATH}
    -Wl,--whole-archive -lsgx_uprotected_fs -Wl,--no-whole-archive
    -lsgx_urts_sim
    sgx_uae_service_sim
    ${SYM_Lib}
    ${HE_Lib}
    ${ORE_Lib}
    gmp
    log4cpp
    ssl
    crypto
    pthread
    # PostgreSQL相关库
    -L${PG_LIB_PATH}
)
target_link_libraries(EnclaveTest
    /new_enc/postgresql-14.2/src/port/libpgport.a
    /new_enc/postgresql-14.2/src/common/libpgcommon.a
)

# 添加编译选项，避免符号冲突
add_definitions(
    -DFRONTEND
    -DUSE_ASSERT_CHECKING
)
