2020-01-21 18:14:27 +03:00
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
# Licensed under the Apache 2.0 License.
|
|
|
|
|
2024-08-16 13:43:28 +03:00
|
|
|
set(ALLOWED_TARGETS "snp;virtual")
|
2020-03-25 17:50:30 +03:00
|
|
|
|
2022-11-03 14:25:53 +03:00
|
|
|
if(NOT DEFINED COMPILE_TARGET)
|
|
|
|
set(COMPILE_TARGET
|
2024-08-16 13:43:28 +03:00
|
|
|
"snp"
|
2022-11-03 14:25:53 +03:00
|
|
|
CACHE STRING
|
|
|
|
"Target compilation platforms, Choose from: ${ALLOWED_TARGETS}"
|
|
|
|
)
|
|
|
|
endif()
|
2020-03-25 17:50:30 +03:00
|
|
|
|
2022-10-26 12:08:24 +03:00
|
|
|
if(NOT COMPILE_TARGET IN_LIST ALLOWED_TARGETS)
|
2020-01-28 21:09:42 +03:00
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
2022-10-26 12:08:24 +03:00
|
|
|
"${REQUESTED_TARGET} is not a valid target. Choose from: ${ALLOWED_TARGETS}"
|
2020-01-28 21:09:42 +03:00
|
|
|
)
|
2020-01-21 18:14:27 +03:00
|
|
|
endif()
|
2022-11-01 20:56:09 +03:00
|
|
|
message(STATUS "Compile target platform: ${COMPILE_TARGET}")
|
2020-01-21 18:14:27 +03:00
|
|
|
|
2022-07-14 13:54:53 +03:00
|
|
|
list(APPEND COMPILE_LIBCXX -stdlib=libc++)
|
2023-04-19 17:42:34 +03:00
|
|
|
list(APPEND LINK_LIBCXX -lc++ -lc++abi -stdlib=libc++)
|
2022-07-14 13:54:53 +03:00
|
|
|
|
2020-01-21 18:14:27 +03:00
|
|
|
# Enclave library wrapper
|
2020-01-28 17:06:12 +03:00
|
|
|
function(add_ccf_app name)
|
2020-01-21 18:14:27 +03:00
|
|
|
|
2020-01-28 21:09:42 +03:00
|
|
|
cmake_parse_arguments(
|
2022-11-18 16:21:14 +03:00
|
|
|
PARSE_ARGV
|
|
|
|
1
|
|
|
|
PARSED_ARGS
|
|
|
|
""
|
|
|
|
""
|
2023-02-04 10:28:08 +03:00
|
|
|
"SRCS;INCLUDE_DIRS;SYSTEM_INCLUDE_DIRS;LINK_LIBS_ENCLAVE;LINK_LIBS_VIRTUAL;LINK_LIBS_SNP;DEPS;INSTALL_LIBS"
|
2020-01-21 18:14:27 +03:00
|
|
|
)
|
2020-01-28 17:06:12 +03:00
|
|
|
add_custom_target(${name} ALL)
|
|
|
|
|
2024-08-16 13:43:28 +03:00
|
|
|
if(COMPILE_TARGET STREQUAL "snp")
|
|
|
|
# Build an SNP enclave, loaded as a shared library
|
2022-11-18 16:21:14 +03:00
|
|
|
set(snp_name ${name}.snp)
|
2020-01-28 17:06:12 +03:00
|
|
|
|
2022-11-18 16:21:14 +03:00
|
|
|
add_library(${snp_name} SHARED ${PARSED_ARGS_SRCS})
|
2020-01-28 17:06:12 +03:00
|
|
|
|
2022-11-18 16:21:14 +03:00
|
|
|
target_compile_definitions(${snp_name} PUBLIC PLATFORM_SNP)
|
2022-10-26 12:08:24 +03:00
|
|
|
|
2023-02-04 10:28:08 +03:00
|
|
|
target_include_directories(${snp_name} PRIVATE ${PARSED_ARGS_INCLUDE_DIRS})
|
2022-10-26 12:08:24 +03:00
|
|
|
target_include_directories(
|
2023-02-04 10:28:08 +03:00
|
|
|
${snp_name} SYSTEM PRIVATE ${PARSED_ARGS_SYSTEM_INCLUDE_DIRS}
|
2022-10-26 12:08:24 +03:00
|
|
|
)
|
2022-11-18 16:21:14 +03:00
|
|
|
add_warning_checks(${snp_name})
|
2022-10-26 12:08:24 +03:00
|
|
|
|
|
|
|
target_link_libraries(
|
2022-11-18 16:21:14 +03:00
|
|
|
${snp_name} PRIVATE ${PARSED_ARGS_LINK_LIBS_SNP} ccf.snp
|
2022-10-26 12:08:24 +03:00
|
|
|
)
|
|
|
|
|
2023-03-08 16:26:59 +03:00
|
|
|
if(NOT (SAN OR TSAN))
|
2022-11-18 16:21:14 +03:00
|
|
|
target_link_options(${snp_name} PRIVATE LINKER:--no-undefined)
|
2022-10-26 12:08:24 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
target_link_options(
|
2022-11-18 16:21:14 +03:00
|
|
|
${snp_name} PRIVATE
|
2022-10-26 12:08:24 +03:00
|
|
|
LINKER:--undefined=enclave_create_node,--undefined=enclave_run
|
|
|
|
)
|
|
|
|
|
2022-11-18 16:21:14 +03:00
|
|
|
set_property(TARGET ${snp_name} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
2022-10-26 12:08:24 +03:00
|
|
|
|
2022-11-18 16:21:14 +03:00
|
|
|
add_san(${snp_name})
|
2022-10-26 12:08:24 +03:00
|
|
|
|
2022-11-18 16:21:14 +03:00
|
|
|
add_dependencies(${name} ${snp_name})
|
2022-10-26 12:08:24 +03:00
|
|
|
if(PARSED_ARGS_DEPS)
|
2022-11-18 16:21:14 +03:00
|
|
|
add_dependencies(${snp_name} ${PARSED_ARGS_DEPS})
|
2022-10-26 12:08:24 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(${PARSED_ARGS_INSTALL_LIBS})
|
2022-11-18 16:21:14 +03:00
|
|
|
install(TARGETS ${snp_name} DESTINATION lib)
|
2022-10-26 12:08:24 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
elseif(COMPILE_TARGET STREQUAL "virtual")
|
2024-08-16 13:43:28 +03:00
|
|
|
# Build a virtual enclave, loaded as a shared library
|
2022-10-26 12:08:24 +03:00
|
|
|
set(virt_name ${name}.virtual)
|
|
|
|
|
|
|
|
add_library(${virt_name} SHARED ${PARSED_ARGS_SRCS})
|
|
|
|
|
|
|
|
target_compile_definitions(${virt_name} PUBLIC PLATFORM_VIRTUAL)
|
|
|
|
|
2023-02-04 10:28:08 +03:00
|
|
|
target_include_directories(${virt_name} PRIVATE ${PARSED_ARGS_INCLUDE_DIRS})
|
2020-01-28 21:09:42 +03:00
|
|
|
target_include_directories(
|
2023-02-04 10:28:08 +03:00
|
|
|
${virt_name} SYSTEM PRIVATE ${PARSED_ARGS_SYSTEM_INCLUDE_DIRS}
|
2020-01-21 18:14:27 +03:00
|
|
|
)
|
2020-07-21 18:08:25 +03:00
|
|
|
add_warning_checks(${virt_name})
|
2020-01-21 18:14:27 +03:00
|
|
|
|
2020-01-28 21:09:42 +03:00
|
|
|
target_link_libraries(
|
|
|
|
${virt_name} PRIVATE ${PARSED_ARGS_LINK_LIBS_VIRTUAL} ccf.virtual
|
2020-01-21 18:14:27 +03:00
|
|
|
)
|
2020-01-28 17:06:12 +03:00
|
|
|
|
2023-03-08 16:26:59 +03:00
|
|
|
if(NOT (SAN OR TSAN))
|
2022-01-26 20:50:44 +03:00
|
|
|
target_link_options(${virt_name} PRIVATE LINKER:--no-undefined)
|
2020-09-03 18:28:34 +03:00
|
|
|
endif()
|
2020-09-02 12:46:17 +03:00
|
|
|
|
2022-01-26 20:50:44 +03:00
|
|
|
target_link_options(
|
|
|
|
${virt_name} PRIVATE
|
|
|
|
LINKER:--undefined=enclave_create_node,--undefined=enclave_run
|
|
|
|
)
|
|
|
|
|
2020-01-21 18:14:27 +03:00
|
|
|
set_property(TARGET ${virt_name} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
|
|
|
|
|
|
|
add_san(${virt_name})
|
2020-01-28 17:06:12 +03:00
|
|
|
|
|
|
|
add_dependencies(${name} ${virt_name})
|
2020-04-14 17:00:47 +03:00
|
|
|
if(PARSED_ARGS_DEPS)
|
|
|
|
add_dependencies(${virt_name} ${PARSED_ARGS_DEPS})
|
|
|
|
endif()
|
2020-06-23 12:10:22 +03:00
|
|
|
|
|
|
|
if(${PARSED_ARGS_INSTALL_LIBS})
|
|
|
|
install(TARGETS ${virt_name} DESTINATION lib)
|
|
|
|
endif()
|
2020-01-21 18:14:27 +03:00
|
|
|
endif()
|
2020-01-28 21:09:42 +03:00
|
|
|
endfunction()
|
2020-04-16 13:31:04 +03:00
|
|
|
|
2021-09-07 22:36:36 +03:00
|
|
|
function(add_host_library name)
|
|
|
|
cmake_parse_arguments(PARSE_ARGV 1 PARSED_ARGS "" "" "")
|
|
|
|
set(files ${PARSED_ARGS_UNPARSED_ARGUMENTS})
|
2021-03-25 17:19:15 +03:00
|
|
|
add_library(${name} ${files})
|
|
|
|
target_compile_options(${name} PUBLIC ${COMPILE_LIBCXX})
|
2023-05-30 13:50:18 +03:00
|
|
|
target_link_libraries(${name} PUBLIC ${LINK_LIBCXX} -lgcc)
|
2021-03-25 17:19:15 +03:00
|
|
|
set_property(TARGET ${name} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
|
|
|
endfunction()
|