CCF/cmake/ccf_app.cmake

128 строки
3.5 KiB
CMake
Исходник Обычный вид История

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the Apache 2.0 License.
set(ALLOWED_TARGETS "snp;virtual")
if(NOT DEFINED COMPILE_TARGET)
set(COMPILE_TARGET
"snp"
CACHE STRING
"Target compilation platforms, Choose from: ${ALLOWED_TARGETS}"
)
endif()
if(NOT COMPILE_TARGET IN_LIST ALLOWED_TARGETS)
2020-01-28 21:09:42 +03:00
message(
FATAL_ERROR
"${REQUESTED_TARGET} is not a valid target. Choose from: ${ALLOWED_TARGETS}"
2020-01-28 21:09:42 +03:00
)
endif()
message(STATUS "Compile target platform: ${COMPILE_TARGET}")
list(APPEND COMPILE_LIBCXX -stdlib=libc++)
2023-04-19 17:42:34 +03:00
list(APPEND LINK_LIBCXX -lc++ -lc++abi -stdlib=libc++)
# Enclave library wrapper
function(add_ccf_app name)
2020-01-28 21:09:42 +03:00
cmake_parse_arguments(
PARSE_ARGV
1
PARSED_ARGS
""
""
"SRCS;INCLUDE_DIRS;SYSTEM_INCLUDE_DIRS;LINK_LIBS_ENCLAVE;LINK_LIBS_VIRTUAL;LINK_LIBS_SNP;DEPS;INSTALL_LIBS"
)
add_custom_target(${name} ALL)
if(COMPILE_TARGET STREQUAL "snp")
# Build an SNP enclave, loaded as a shared library
set(snp_name ${name}.snp)
add_library(${snp_name} SHARED ${PARSED_ARGS_SRCS})
target_compile_definitions(${snp_name} PUBLIC PLATFORM_SNP)
target_include_directories(${snp_name} PRIVATE ${PARSED_ARGS_INCLUDE_DIRS})
target_include_directories(
${snp_name} SYSTEM PRIVATE ${PARSED_ARGS_SYSTEM_INCLUDE_DIRS}
)
add_warning_checks(${snp_name})
target_link_libraries(
${snp_name} PRIVATE ${PARSED_ARGS_LINK_LIBS_SNP} ccf.snp
)
if(NOT (SAN OR TSAN))
target_link_options(${snp_name} PRIVATE LINKER:--no-undefined)
endif()
target_link_options(
${snp_name} PRIVATE
LINKER:--undefined=enclave_create_node,--undefined=enclave_run
)
set_property(TARGET ${snp_name} PROPERTY POSITION_INDEPENDENT_CODE ON)
add_san(${snp_name})
add_dependencies(${name} ${snp_name})
if(PARSED_ARGS_DEPS)
add_dependencies(${snp_name} ${PARSED_ARGS_DEPS})
endif()
if(${PARSED_ARGS_INSTALL_LIBS})
install(TARGETS ${snp_name} DESTINATION lib)
endif()
elseif(COMPILE_TARGET STREQUAL "virtual")
# Build a virtual enclave, loaded as a shared library
set(virt_name ${name}.virtual)
add_library(${virt_name} SHARED ${PARSED_ARGS_SRCS})
target_compile_definitions(${virt_name} PUBLIC PLATFORM_VIRTUAL)
target_include_directories(${virt_name} PRIVATE ${PARSED_ARGS_INCLUDE_DIRS})
2020-01-28 21:09:42 +03:00
target_include_directories(
${virt_name} SYSTEM PRIVATE ${PARSED_ARGS_SYSTEM_INCLUDE_DIRS}
)
add_warning_checks(${virt_name})
2020-01-28 21:09:42 +03:00
target_link_libraries(
${virt_name} PRIVATE ${PARSED_ARGS_LINK_LIBS_VIRTUAL} ccf.virtual
)
if(NOT (SAN OR TSAN))
target_link_options(${virt_name} PRIVATE LINKER:--no-undefined)
endif()
target_link_options(
${virt_name} PRIVATE
LINKER:--undefined=enclave_create_node,--undefined=enclave_run
)
set_property(TARGET ${virt_name} PROPERTY POSITION_INDEPENDENT_CODE ON)
add_san(${virt_name})
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()
endif()
2020-01-28 21:09:42 +03:00
endfunction()
function(add_host_library name)
cmake_parse_arguments(PARSE_ARGV 1 PARSED_ARGS "" "" "")
set(files ${PARSED_ARGS_UNPARSED_ARGUMENTS})
add_library(${name} ${files})
target_compile_options(${name} PUBLIC ${COMPILE_LIBCXX})
target_link_libraries(${name} PUBLIC ${LINK_LIBCXX} -lgcc)
set_property(TARGET ${name} PROPERTY POSITION_INDEPENDENT_CODE ON)
endfunction()