From 9bf881bde20a06eae72c6a681f943a8766557c70 Mon Sep 17 00:00:00 2001 From: Jork Loeser Date: Sat, 18 Nov 2017 13:43:59 -0800 Subject: [PATCH] CMake conversion of OE, step 2 The fudamentals are in place: - build & install of 3rd-party projects - build & install of libs & tools - build & execute tests + manual HW/sim distinction - std build configs (none, debug/release/relwithdebug) Not yet: - config-script (thereby sample intregration) + review prereqs + cmake packaging... - docs/ are POD makefile for Linux only - review scripts - enable & doc valgrind usage - polishing + libunwind: pass build config through configure/automake + misc bits here and there --- 3rdparty/CMakeLists.txt | 7 ++ 3rdparty/libcxx/CMakeLists.txt | 85 +++++++++++++++++++ 3rdparty/libcxxrt/CMakeLists.txt | 12 +++ 3rdparty/libunwind/CMakeLists.txt | 25 ++++++ 3rdparty/mbedtls/CMakeLists.txt | 40 +++++++++ 3rdparty/musl/CMakeLists.txt | 49 +++++++++++ CMakeLists.txt | 21 +++-- cmake/add_enclave_executable.cmake | 52 ++++++++++++ cmake/oeidl_file.cmake | 54 ++++++++++++ cmake/wrap.cmake | 21 +++++ common/README.md | 2 + doc/README.cmake.txt | 39 +++++++++ enclave/CMakeLists.txt | 4 +- host/CMakeLists.txt | 15 ++-- host/aesm.c | 30 +++---- idl/CMakeLists.txt | 33 +++++++ libc/CMakeLists.txt | 29 ++++--- libcxx/CMakeLists.txt | 44 ++++++++++ tests/CMakeLists.txt | 42 +++++++++ tests/SampleApp/CMakeLists.txt | 4 + tests/SampleApp/SampleApp/CMakeLists.txt | 7 ++ tests/SampleApp/SampleAppHost/CMakeLists.txt | 6 ++ tests/SampleAppAttestation/CMakeLists.txt | 4 + .../SampleAppAttestation/CMakeLists.txt | 7 ++ .../SampleAppAttestationHost/CMakeLists.txt | 7 ++ tests/SampleAppCRT/CMakeLists.txt | 4 + .../SampleAppCRT/SampleAppCRT/CMakeLists.txt | 8 ++ .../SampleAppCRTHost/CMakeLists.txt | 6 ++ tests/aesm/CMakeLists.txt | 7 ++ tests/attic/dead.txt | 1 + tests/ecall/CMakeLists.txt | 4 + tests/ecall/enc/CMakeLists.txt | 6 ++ tests/ecall/host/CMakeLists.txt | 9 ++ tests/echo/CMakeLists.txt | 4 + tests/echo/enc/CMakeLists.txt | 6 ++ tests/echo/host/CMakeLists.txt | 6 ++ tests/eenter/dead.txt | 1 + tests/file/CMakeLists.txt | 4 + tests/file/enc/CMakeLists.txt | 12 +++ tests/file/host/CMakeLists.txt | 9 ++ tests/hashstr/dead.txt | 1 + tests/libc/CMakeLists.txt | 12 +++ tests/libc/enc/CMakeLists.txt | 43 ++++++++++ tests/libc/get_testcase_name.cmake | 18 ++++ tests/libc/host/CMakeLists.txt | 6 ++ tests/libc/host/host.cpp | 1 + tests/libcxx/CMakeLists.txt | 12 +++ tests/libcxx/enc/CMakeLists.txt | 45 ++++++++++ tests/libcxx/host/CMakeLists.txt | 5 ++ tests/libcxx/host/host.cpp | 1 + tests/load/CMakeLists.txt | 7 ++ tests/load/dead.txt | 1 + tests/mbed/CMakeLists.txt | 4 + tests/mbed/enc/CMakeLists.txt | 7 ++ tests/mbed/host/CMakeLists.txt | 9 ++ tests/measure/dead.txt | 1 + tests/mem/CMakeLists.txt | 8 ++ tests/ocall/CMakeLists.txt | 4 + tests/ocall/enc/CMakeLists.txt | 6 ++ tests/ocall/host/CMakeLists.txt | 9 ++ tests/pingpong/CMakeLists.txt | 4 + tests/pingpong/enc/CMakeLists.txt | 12 +++ tests/pingpong/host/CMakeLists.txt | 9 ++ tests/print/CMakeLists.txt | 10 +++ tests/print/enc/CMakeLists.txt | 15 ++++ tests/print/host/CMakeLists.txt | 9 ++ tests/report/CMakeLists.txt | 4 + tests/report/enc/CMakeLists.txt | 6 ++ tests/report/host/CMakeLists.txt | 6 ++ tests/ricochet/CMakeLists.txt | 4 + tests/ricochet/enc/CMakeLists.txt | 6 ++ tests/ricochet/host/CMakeLists.txt | 9 ++ tests/stdc/CMakeLists.txt | 4 + tests/stdc/enc/CMakeLists.txt | 15 ++++ tests/stdc/host/CMakeLists.txt | 9 ++ tests/stdcxx/CMakeLists.txt | 4 + tests/stdcxx/enc/CMakeLists.txt | 16 ++++ tests/stdcxx/host/CMakeLists.txt | 9 ++ tests/str/CMakeLists.txt | 11 +++ tests/tester/CMakeLists.txt | 4 + tests/tester/enc/CMakeLists.txt | 12 +++ tests/tester/host/CMakeLists.txt | 9 ++ tests/thread/CMakeLists.txt | 4 + tests/thread/enc/CMakeLists.txt | 14 +++ tests/thread/host/CMakeLists.txt | 9 ++ tests/typeinfo/CMakeLists.txt | 13 +++ tools/CMakeLists.txt | 6 ++ tools/dox2md/CMakeLists.txt | 13 +++ tools/oedump/CMakeLists.txt | 13 +++ tools/oeelf/CMakeLists.txt | 12 +++ tools/oeelf/README.md | 3 + tools/oegen/CMakeLists.txt | 19 +++++ tools/oesgx/CMakeLists.txt | 10 +++ tools/oesign/CMakeLists.txt | 10 +++ 94 files changed, 1202 insertions(+), 37 deletions(-) create mode 100644 3rdparty/CMakeLists.txt create mode 100644 3rdparty/libcxx/CMakeLists.txt create mode 100644 3rdparty/libcxxrt/CMakeLists.txt create mode 100644 3rdparty/libunwind/CMakeLists.txt create mode 100644 3rdparty/mbedtls/CMakeLists.txt create mode 100644 3rdparty/musl/CMakeLists.txt create mode 100644 cmake/add_enclave_executable.cmake create mode 100644 cmake/oeidl_file.cmake create mode 100644 cmake/wrap.cmake create mode 100644 common/README.md create mode 100644 doc/README.cmake.txt create mode 100644 idl/CMakeLists.txt create mode 100644 libcxx/CMakeLists.txt create mode 100644 tests/CMakeLists.txt create mode 100644 tests/SampleApp/CMakeLists.txt create mode 100644 tests/SampleApp/SampleApp/CMakeLists.txt create mode 100644 tests/SampleApp/SampleAppHost/CMakeLists.txt create mode 100644 tests/SampleAppAttestation/CMakeLists.txt create mode 100644 tests/SampleAppAttestation/SampleAppAttestation/CMakeLists.txt create mode 100644 tests/SampleAppAttestation/SampleAppAttestationHost/CMakeLists.txt create mode 100644 tests/SampleAppCRT/CMakeLists.txt create mode 100644 tests/SampleAppCRT/SampleAppCRT/CMakeLists.txt create mode 100644 tests/SampleAppCRT/SampleAppCRTHost/CMakeLists.txt create mode 100644 tests/aesm/CMakeLists.txt create mode 100644 tests/attic/dead.txt create mode 100644 tests/ecall/CMakeLists.txt create mode 100644 tests/ecall/enc/CMakeLists.txt create mode 100644 tests/ecall/host/CMakeLists.txt create mode 100644 tests/echo/CMakeLists.txt create mode 100644 tests/echo/enc/CMakeLists.txt create mode 100644 tests/echo/host/CMakeLists.txt create mode 100644 tests/eenter/dead.txt create mode 100644 tests/file/CMakeLists.txt create mode 100644 tests/file/enc/CMakeLists.txt create mode 100644 tests/file/host/CMakeLists.txt create mode 100644 tests/hashstr/dead.txt create mode 100644 tests/libc/CMakeLists.txt create mode 100644 tests/libc/enc/CMakeLists.txt create mode 100644 tests/libc/get_testcase_name.cmake create mode 100644 tests/libc/host/CMakeLists.txt create mode 100644 tests/libcxx/CMakeLists.txt create mode 100644 tests/libcxx/enc/CMakeLists.txt create mode 100644 tests/libcxx/host/CMakeLists.txt create mode 100644 tests/load/CMakeLists.txt create mode 100644 tests/load/dead.txt create mode 100644 tests/mbed/CMakeLists.txt create mode 100644 tests/mbed/enc/CMakeLists.txt create mode 100644 tests/mbed/host/CMakeLists.txt create mode 100644 tests/measure/dead.txt create mode 100644 tests/mem/CMakeLists.txt create mode 100644 tests/ocall/CMakeLists.txt create mode 100644 tests/ocall/enc/CMakeLists.txt create mode 100644 tests/ocall/host/CMakeLists.txt create mode 100644 tests/pingpong/CMakeLists.txt create mode 100644 tests/pingpong/enc/CMakeLists.txt create mode 100644 tests/pingpong/host/CMakeLists.txt create mode 100644 tests/print/CMakeLists.txt create mode 100644 tests/print/enc/CMakeLists.txt create mode 100644 tests/print/host/CMakeLists.txt create mode 100644 tests/report/CMakeLists.txt create mode 100644 tests/report/enc/CMakeLists.txt create mode 100644 tests/report/host/CMakeLists.txt create mode 100644 tests/ricochet/CMakeLists.txt create mode 100644 tests/ricochet/enc/CMakeLists.txt create mode 100644 tests/ricochet/host/CMakeLists.txt create mode 100644 tests/stdc/CMakeLists.txt create mode 100644 tests/stdc/enc/CMakeLists.txt create mode 100644 tests/stdc/host/CMakeLists.txt create mode 100644 tests/stdcxx/CMakeLists.txt create mode 100644 tests/stdcxx/enc/CMakeLists.txt create mode 100644 tests/stdcxx/host/CMakeLists.txt create mode 100644 tests/str/CMakeLists.txt create mode 100644 tests/tester/CMakeLists.txt create mode 100644 tests/tester/enc/CMakeLists.txt create mode 100644 tests/tester/host/CMakeLists.txt create mode 100644 tests/thread/CMakeLists.txt create mode 100644 tests/thread/enc/CMakeLists.txt create mode 100644 tests/thread/host/CMakeLists.txt create mode 100644 tests/typeinfo/CMakeLists.txt create mode 100644 tools/CMakeLists.txt create mode 100644 tools/dox2md/CMakeLists.txt create mode 100644 tools/oedump/CMakeLists.txt create mode 100644 tools/oeelf/CMakeLists.txt create mode 100644 tools/oeelf/README.md create mode 100644 tools/oegen/CMakeLists.txt create mode 100644 tools/oesgx/CMakeLists.txt create mode 100644 tools/oesign/CMakeLists.txt diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt new file mode 100644 index 0000000000..be1961d07b --- /dev/null +++ b/3rdparty/CMakeLists.txt @@ -0,0 +1,7 @@ +# Note: order does matter + +add_subdirectory(libcxx) +add_subdirectory(libcxxrt) +add_subdirectory(libunwind) +add_subdirectory(musl) +add_subdirectory(mbedtls) # after musl diff --git a/3rdparty/libcxx/CMakeLists.txt b/3rdparty/libcxx/CMakeLists.txt new file mode 100644 index 0000000000..8b141a8816 --- /dev/null +++ b/3rdparty/libcxx/CMakeLists.txt @@ -0,0 +1,85 @@ +# Copy headers to collector-dir, patch, compile libcxx into intermittent library +# place install rule + +# Use an external project to place the headers in the collector-dir +include (ExternalProject) +ExternalProject_Add(oelibcxx_cxx_includes + DOWNLOAD_COMMAND "" + CONFIGURE_COMMAND "" + BUILD_COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_CURRENT_LIST_DIR}/libcxx/include ${OE_INCDIR}/openenclave/libcxx + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/libcxx/include/__config ${OE_INCDIR}/openenclave/libcxx/__config_original + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/__config ${OE_INCDIR}/openenclave/libcxx/__config + INSTALL_COMMAND "" + ) +install (DIRECTORY ${OE_INCDIR}/openenclave/libcxx DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openenclave) + +# build sources + +add_library(oelibcxx_cxx STATIC + __dso_handle.cpp + + libcxx/src/algorithm.cpp + libcxx/src/any.cpp + libcxx/src/bind.cpp + libcxx/src/chrono.cpp + libcxx/src/condition_variable.cpp + libcxx/src/debug.cpp + libcxx/src/exception.cpp + libcxx/src/functional.cpp + libcxx/src/future.cpp + libcxx/src/hash.cpp + libcxx/src/ios.cpp + libcxx/src/iostream.cpp + libcxx/src/locale.cpp + libcxx/src/memory.cpp + libcxx/src/mutex.cpp + libcxx/src/new.cpp + libcxx/src/optional.cpp + libcxx/src/random.cpp + libcxx/src/regex.cpp + libcxx/src/shared_mutex.cpp + libcxx/src/stdexcept.cpp + libcxx/src/string.cpp + libcxx/src/strstream.cpp + libcxx/src/system_error.cpp + libcxx/src/thread.cpp + libcxx/src/typeinfo.cpp + libcxx/src/utility.cpp + libcxx/src/valarray.cpp + libcxx/src/variant.cpp + libcxx/src/vector.cpp + ) + +target_compile_options(oelibcxx_cxx PRIVATE + -nostdinc + -nostdinc++ + + -w + + -std=c++14 + -fPIC + ) + +target_compile_definitions(oelibcxx_cxx PRIVATE + -DLIBCXXRT + -D_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE + -D_LIBCPP_BUILDING_LIBRARY + ) + +# need the LIBCXX_CXX headers placed +add_dependencies(oelibcxx_cxx oelibcxx_cxx_includes) +# this project and its dependents require include/libcxx in the include path +target_include_directories(oelibcxx_cxx PUBLIC ${OE_INCDIR}/openenclave/libcxx) + +# this project (and is dependents) require the LIBC includes +target_link_libraries(oelibcxx_cxx PUBLIC oelibc) +# If we built an OBJECT library, we would want to do the following, though CMake does not allow +# using target_link_libraries on an OBJECT lib (yet?): +#add_dependencies(oelibcxx_cxx oelibc) +#target_include_directories(oelibcxx_cxx PUBLIC ${OE_INCDIR}/libc) + +# when building this project, we also need a number of internal includes +target_include_directories(oelibcxx_cxx PRIVATE libcxx/src) +target_include_directories(oelibcxx_cxx PRIVATE ${CMAKE_SOURCE_DIR}/3rdparty/libcxxrt/libcxxrt/src) + diff --git a/3rdparty/libcxxrt/CMakeLists.txt b/3rdparty/libcxxrt/CMakeLists.txt new file mode 100644 index 0000000000..66546c3323 --- /dev/null +++ b/3rdparty/libcxxrt/CMakeLists.txt @@ -0,0 +1,12 @@ +# Compile CXXRT + +# build cxxrt sources passing additional options +add_subdirectory(libcxxrt/src) +target_compile_options(cxxrt-static PRIVATE + -include ${CMAKE_CURRENT_SOURCE_DIR}/stubs.h + -fPIC + # cannot use add_link_libraries on out-of-dir target + -nostdinc + -I${OE_INCDIR}/openenclave/libc + ) +add_dependencies(cxxrt-static oelibc_includes) diff --git a/3rdparty/libunwind/CMakeLists.txt b/3rdparty/libunwind/CMakeLists.txt new file mode 100644 index 0000000000..97503f4224 --- /dev/null +++ b/3rdparty/libunwind/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copy libunwind sources and build out-of-tree + +set (OELIBCXX_UNWIND_OPTS + --enable-shared=no + --disable-block-signals + --enable-debug=no + --enable-debug-frame==no + --enable-cxx-exceptions + ) + +set (OELIBCXX_UNWIND_CFLAGS + "-DUNW_LOCAL_ONLY -DWSIZE=8 -fno-builtin -fPIC -DOPEN_ENCLAVE -include ${CMAKE_CURRENT_SOURCE_DIR}/stubs.h" + ) + +include (ExternalProject) +ExternalProject_Add(oelibcxx_unwind + DOWNLOAD_COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_CURRENT_LIST_DIR}/libunwind ${CMAKE_CURRENT_BINARY_DIR}/libunwind + CONFIGURE_COMMAND cd ${CMAKE_CURRENT_BINARY_DIR}/libunwind && + ./autogen.sh + COMMAND cd ${CMAKE_CURRENT_BINARY_DIR}/libunwind && + ./configure "${OELIBCXX_UNWIND_OPTS}" "CFLAGS=${OELIBCXX_UNWIND_CFLAGS}" + BUILD_COMMAND $(MAKE) -C ${CMAKE_CURRENT_BINARY_DIR}/libunwind/src + INSTALL_COMMAND "" + ) diff --git a/3rdparty/mbedtls/CMakeLists.txt b/3rdparty/mbedtls/CMakeLists.txt new file mode 100644 index 0000000000..3b3311f5ce --- /dev/null +++ b/3rdparty/mbedtls/CMakeLists.txt @@ -0,0 +1,40 @@ +# Copy mbedtls sources to replace config.h and build w/ own flags + +set(MBEDTLS_WRAP_CFLAGS "-nostdinc -I${OE_INCDIR}/openenclave/libc -fPIC -fno-builtin-udivti3") + +include (ExternalProject) +ExternalProject_Add(mbedtls-wrap + DEPENDS oelibc_includes + + DOWNLOAD_COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_CURRENT_LIST_DIR}/mbedtls + PATCH_COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_CURRENT_SOURCE_DIR}/config.h /include/mbedtls/config.h + + # Addl args for compiler + CMAKE_ARGS + -DCMAKE_C_FLAGS=${MBEDTLS_WRAP_CFLAGS} + -DENABLE_PROGRAMS=OFF + -DENABLE_TESTING=OFF + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + + # copy headers/libs + INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory + /include/mbedtls ${OE_INCDIR}/openenclave/oe-mbedtls/mbedtls + COMMAND ${CMAKE_COMMAND} -E copy + /library/libmbedcrypto.a ${OE_LIBDIR}/openenclave/enclave/ + ) +install (DIRECTORY ${OE_INCDIR}/openenclave/oe-mbedtls DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openenclave) +install (FILES ${OE_LIBDIR}/openenclave/enclave/libmbedcrypto.a DESTINATION ${CMAKE_INSTALL_LIBDIR}/openenclave/enclave) + +# Convenience lib for use in target_link_libraries +add_library(mbedcrypto INTERFACE) +add_dependencies(mbedcrypto mbedtls-wrap) +target_include_directories(mbedcrypto INTERFACE ${OE_INCDIR}/openenclave/oe-mbedtls) +target_link_libraries(mbedcrypto INTERFACE ${OE_LIBDIR}/openenclave/enclave/libmbedcrypto.a) +# For the libc dependency, We would just want to use "oelibc". However, we need +# an actual lib-dependency between crypto an libc, which is not expressable +# with CMake. If using the target "oelibc", CMake reorders the libs, resulting +# in undefined LIBC symbols from crypto. Using the explicit lib-name preserves +# order. +target_link_libraries(mbedcrypto INTERFACE ${OE_LIBDIR}/openenclave/enclave/liboelibc.a) diff --git a/3rdparty/musl/CMakeLists.txt b/3rdparty/musl/CMakeLists.txt new file mode 100644 index 0000000000..4dbb0738ad --- /dev/null +++ b/3rdparty/musl/CMakeLists.txt @@ -0,0 +1,49 @@ +# Copy MUSL headers to collector dir and wrap +# actual compilation and lib-generation happens in /libc/ + +include (ExternalProject) +ExternalProject_Add(oelibc_includes + DOWNLOAD_COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_CURRENT_LIST_DIR}/musl ${CMAKE_CURRENT_BINARY_DIR}/musl + CONFIGURE_COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR}/musl + ./configure --includedir=${OE_INCDIR}/openenclave/libc CFLAGS=-fPIC + BUILD_COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR}/musl + make install-headers + COMMAND $(CMAKE_COMMAND) + -DWRAP_DST=${OE_INCDIR}/openenclave/libc/endian.h + -DWRAP_SRC=${CMAKE_CURRENT_LIST_DIR}/musl/include/endian.h + -DWRAP_PRE=${CMAKE_CURRENT_LIST_DIR}/endian.h.prefix + -DWRAP_SUF=${CMAKE_CURRENT_LIST_DIR}/endian.h.suffix + -P ${CMAKE_SOURCE_DIR}/cmake/wrap.cmake + BUILD_BYPRODUCTS ${OE_INCDIR}/openenclave/libc ${CMAKE_CURRENT_BINARY_DIR}/musl + INSTALL_COMMAND "" + ) + +# install-rule can be generated here, usage requirements defined in /libc/. +install (DIRECTORY ${OE_INCDIR}/openenclave/libc DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openenclave) + +# +# genearl tidbits follow - find a better home +# +# To get it to build on Windows - bypassing configure - we could: +# +#BUILD_COMMAND ${CMAKE_COMMAND} -E copy_directory +# ${CMAKE_CURRENT_SOURCE_DIR}/musl/include ${OE_INCDIR}/openenclave/libc +# COMMAND ${CMAKE_COMMAND} -E copy_directory +# ${CMAKE_CURRENT_SOURCE_DIR}/musl/arch/x86_64/bits ${OE_INCDIR}/openenclave/libc/bits +# +# still required creation of alltypes.h. Wrap as per above. + +# This does not work with an ExternalProject_Add'ed project +#target_include_directories(oelibc_includes_copy INTERFACE ${OE_INCDIR}/openenclave/libc) +# use an interface library instead + +# alternative to wrapping with newer CMake (3.10+) - use patch instead of wrap: +#find_package(Patch) +#if(!Patch_FOUND) +# message(FATAL_ERROR "Patch command not found") +#endif() + +#add_custom_command(TARGET oe_libc_includes PRE_BUILD +# COMMAND ${CMAKE_COMMAND} -E chdir ${OE_INCDIR}/openenclave/libc ${Patch_EXECUTABLE} -p1 < ${CMAKE_SOURCE_DIR}/endian.h.patch +# ) diff --git a/CMakeLists.txt b/CMakeLists.txt index 75d19bf7c1..5a7c6a958f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,16 +3,27 @@ # cmake_minimum_required(VERSION 3.5.1) -include(GNUInstallDirs) +# allow simpler include() of our scripts +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") + +# sanitize build type +string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE) -enable_language(C ASM) +enable_testing() +enable_language(ASM C CXX) -set(OE_OUTPUT_DIR ${CMAKE_BINARY_DIR}/output CACHE PATH "Path to the intermittent output tree") +include(GNUInstallDirs) +set(OE_OUTPUT_DIR ${CMAKE_BINARY_DIR}/output CACHE PATH "Path to the intermittent collector tree") set(OE_BINDIR ${OE_OUTPUT_DIR}/bin CACHE PATH "Binary collector") set(OE_INCDIR ${OE_OUTPUT_DIR}/include CACHE PATH "Include collector") set(OE_LIBDIR ${OE_OUTPUT_DIR}/lib CACHE PATH "Library collector") +add_subdirectory(3rdparty) add_subdirectory(enclave) -add_subdirectory(host) -add_subdirectory(include) +add_subdirectory(host) # convertable to Windows +add_subdirectory(idl) +add_subdirectory(include) # convertable to Windows add_subdirectory(libc) +add_subdirectory(libcxx) +add_subdirectory(tests) +add_subdirectory(tools) diff --git a/cmake/add_enclave_executable.cmake b/cmake/add_enclave_executable.cmake new file mode 100644 index 0000000000..eece80ca9f --- /dev/null +++ b/cmake/add_enclave_executable.cmake @@ -0,0 +1,52 @@ + +# Helper function to create enclave binary +# +# Generates a target for an enclave binary +# +# Usage: +# +# add_enclave_executable( +# +# source1 [source2...] +# +# Target properties can be set on , see add_executable for details. +# +# Restrictions: A number of subtleties are not handled, such as +# - RUNTIME_OUTPUT_DIRECTORY property is not handled correctly +# - the resulting binary name is not reflected by the target +# (complicating install rules) +# +function(add_enclave_executable BIN SIGNCONF KEYFILE) + add_executable(${BIN} ${ARGN}) + + # enclave-specific compile options + # these should perhaps go to oeenclave usage properties + target_compile_options(${BIN} PRIVATE + -m64 -nostdinc -fPIC -fno-stack-protector + $<$:-std=c++14 -nostdinc++> + ) + # enclave-specific link options + # these should perhaps go to oeenclave usage properties + target_link_libraries(${BIN} + -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles + -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--export-dynamic -Wl,-pie -Wl,-eOE_Main + ) + + # enclaves depend on the oeenclave lib + target_link_libraries(${BIN} oeenclave) + + # custom rule to symlink the the binary to a name oesign understands + add_custom_command(OUTPUT ${BIN}.so + COMMAND ln -sf ${BIN} $.so + ) + # custom rule to sign the binary + add_custom_command(OUTPUT ${BIN}.signed.so + COMMAND oesign $.so ${SIGNCONF} ${KEYFILE} + DEPENDS oesign $.so ${BIN} ${SIGNCONF} ${KEYFILE} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + # signed binary is a default target + add_custom_target(${BIN}-signed ALL + DEPENDS ${BIN}.signed.so + ) +endfunction(add_enclave_executable) diff --git a/cmake/oeidl_file.cmake b/cmake/oeidl_file.cmake new file mode 100644 index 0000000000..424399f874 --- /dev/null +++ b/cmake/oeidl_file.cmake @@ -0,0 +1,54 @@ +# +# Helper function to handle IDL (gen) files +# +# Create custom-command to generate .c/.h-file for a given IDL-file +# into CMAKE_CURRENT_BINARY_DIR and set misc properties on files. +# +# Usage: +# +# oeidl_file( +# +# +# Arguments: +# idl_file - name of the IDL file +# type - type of files to genreate ("enclave" or "host") +# out_files_var - variable to get the generated files added to +# +function(oeidl_file IDL_FILE TYPE OUT_FILES_VAR) + if(${TYPE} STREQUAL "enclave") + set(type_id "t") + elseif(${TYPE} STREQUAL "host") + set(type_id "u") + else() + message(FATAL_ERROR "unknown IDL generation type ${TYPE} - must be \"enclave\" or \"host\"") + endif() + + get_filename_component(idl_base ${IDL_FILE} NAME_WE) + get_filename_component(in_path ${IDL_FILE} PATH) + + set(h_file ${CMAKE_CURRENT_BINARY_DIR}/${idl_base}_${type_id}.h) + set(c_file ${CMAKE_CURRENT_BINARY_DIR}/${idl_base}_${type_id}.c) + + add_custom_command( + OUTPUT ${h_file} ${c_file} + DEPENDS ${IDL_FILE} + COMMAND oegen -${type_id} -d ${CMAKE_CURRENT_BINARY_DIR} ${IDL_FILE} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + + set_source_files_properties( + ${h_file} ${c_file} + PROPERTIES GENERATED TRUE + ) + set_source_files_properties( + ${IDL_FILE} + PROPERTIES HEADER_FILE_ONLY TRUE + ) + + # append h_file,c_file to output var + list(APPEND ${OUT_FILES_VAR} ${h_file} ${c_file}) + set(${OUT_FILES_VAR} ${${OUT_FILES_VAR}} PARENT_SCOPE) + + #message("h_file=${h_file} c_file=${c_file} IDL_FILE=${IDL_FILE} OUT_FILES=${${OUT_FILES_VAR}}") +endfunction(oeidl_file) + diff --git a/cmake/wrap.cmake b/cmake/wrap.cmake new file mode 100644 index 0000000000..e4dcb0b922 --- /dev/null +++ b/cmake/wrap.cmake @@ -0,0 +1,21 @@ +# CMAKE-script to wrap sources with pre- and suffix (all files) +# +# Args: +# - WRAP_DST - Output file +# - WRAP_SRC - Input file +# - WRAP_PRE - Prefix file +# - WRAP_SUF - Suffix file +# +# Reulting file (WRAP_DST) will be the contents of WRAP_PRE, WRAP_SRC, WRAP_SUF + +function(wrap output input pre post) + file(READ ${pre} pre_cont) + file(READ ${input} input_cont) + file(READ ${post} post_cont) + + file(WRITE ${output} "${pre_cont}") + file(APPEND ${output} "${input_cont}") + file(APPEND ${output} "${post_cont}") +endfunction(wrap) + +wrap(${WRAP_DST} ${WRAP_SRC} ${WRAP_PRE} ${WRAP_SUF}) diff --git a/common/README.md b/common/README.md new file mode 100644 index 0000000000..202a8baa05 --- /dev/null +++ b/common/README.md @@ -0,0 +1,2 @@ +Sources shared by both the Enclave and Host libraries. + diff --git a/doc/README.cmake.txt b/doc/README.cmake.txt new file mode 100644 index 0000000000..d6b87347df --- /dev/null +++ b/doc/README.cmake.txt @@ -0,0 +1,39 @@ +Build is generally out-of-tree (in-tree is possible, though you would not +want that). To build, pick a dir to build under ("build/" below) +* mkdir build/ +* cd build/ +* cmake .. +* make + +If things break, "make VERBOSE=1" gives all the gory details. You can build +from within a subtree of the build-tree, CMake is pretty good about chasing +dependencies. "make clean" works as well and is handy before a spot-rebuild +in verbose mode. + +Tests are executed via ctest, see "man ctest" for details. +* From the build-tree, simply run "ctest" +* If things go wrong "ctest -V" gives details +* Executing ctest from a sub-dir executes the tests underneath +* libcxx tests are omitted by default due to their huge cost on building + (30mins+). Enable by including "-DENABLE_LIBCXX_TESTS=1" on the cmake line + - cmake -DENABLE_LIBCXX_TESTS=ON .. +* if you are in a hurry, disable libc tests with "-DENABLE_LIBC_TESTS=0". + +Installation: +Either by passing the install-prefix (default /usr/local on Linux) on the +cmake call: +* cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/openenclave .. +* (then build via "make") +* make install + +On Linux, there is also the DESTDIR mechanism, prepending the install prefix +with the given path: +* (cmake .. && make) +* make install DESTDIR=foo + +Different configurations (Debug, Release, RelWithDebInfo) are supported by +CMake pretty much out-of-the-box. Select when calling cmake, like so: +* cmake -DMAKE_BUILD_TYPE=relwithdebinfo .. + +The default (none) results in no optimization, no non-debug flags, and no +debug symbols. diff --git a/enclave/CMakeLists.txt b/enclave/CMakeLists.txt index fb549a2dda..8f3d7f63cc 100644 --- a/enclave/CMakeLists.txt +++ b/enclave/CMakeLists.txt @@ -31,5 +31,5 @@ target_compile_options(oeenclave PRIVATE target_compile_definitions(oeenclave PRIVATE -DOE_BUILD_ENCLAVE) -set_property(TARGET oeenclave PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${OE_LIBDIR}/enclave) -install (TARGETS oeenclave ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/enclave) +set_property(TARGET oeenclave PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${OE_LIBDIR}/openenclave/enclave) +install (TARGETS oeenclave ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/openenclave/enclave) diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index d8337f9c63..5cf3aeef2a 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -25,15 +25,20 @@ add_library(oehost STATIC entersim.S ) +# we and dependents need the OE includes to compile target_link_libraries(oehost oe_includes) +# linking also requires a number of libs on the host +target_link_libraries(oehost -lcrypto -ldl -lpthread) + target_compile_options(oehost PRIVATE -Wall -Werror -Wno-attributes -Wmissing-prototypes - -m64 -g -O2 + -m64 ) -# -fPIC - target_compile_definitions(oehost PRIVATE -DOE_BUILD_UNTRUSTED) -set_property(TARGET oehost PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${OE_LIBDIR}/host) -install (TARGETS oehost ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/host) +# assemble lib-archive into proper dir +set_property(TARGET oehost PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${OE_LIBDIR}/openenclave/host) + +# install lib-archive upon install-time +install (TARGETS oehost ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/openenclave/host) diff --git a/host/aesm.c b/host/aesm.c index 508082f6e8..8befcb51ff 100644 --- a/host/aesm.c +++ b/host/aesm.c @@ -11,11 +11,11 @@ #define TRACE 1 #endif -/* +/* **============================================================================== ** -** This module implements a socket client to AESM (SGX Application Enclave -** Services Manager). On linux, this service is called 'aesmd'. See if it +** This module implements a socket client to AESM (SGX Application Enclave +** Services Manager). On linux, this service is called 'aesmd'. See if it ** is running with this command: ** ** $ services aesmd status @@ -57,7 +57,7 @@ static uint32_t _MakeTag( unsigned int fieldnum, unsigned int wiretype) { - return (fieldnum << 3) | wiretype; + return (fieldnum << 3) | wiretype; } static int _PackVariantUint32( @@ -68,7 +68,7 @@ static int _PackVariantUint32( uint8_t* p = data; const uint8_t* end = data + sizeof(data); - while (x >= 0x80) + while (x >= 0x80) { if (p == end) return -1; @@ -123,7 +123,7 @@ static ssize_t _UnpackVariantUint32( p = (const uint8_t*)mem_ptr_at(buf, pos); - do + do { /* Check for overflow */ if (count == sizeof(uint32_t)) @@ -220,7 +220,7 @@ static OE_Result _UnpackLengthDelimited( size_t dataSize) { OE_Result result = OE_UNEXPECTED; - uint8_t tag; + uint8_t tag = 0; uint32_t size; if ((*pos = _UnpackTag(buf, *pos, &tag)) == -1) @@ -251,7 +251,7 @@ static int _Read( size_t size) { ssize_t n; - + if ((n = read(sock, data, size)) != size) return -1; @@ -264,7 +264,7 @@ static int _Write( size_t size) { ssize_t n; - + if ((n = write(sock, data, size)) != size) return -1; @@ -295,7 +295,7 @@ static OE_Result _WriteRequest( /* Send message size */ if (_Write(aesm->sock, &size, sizeof(uint32_t)) != 0) OE_THROW(OE_FAILURE); - + /* Send message data */ if (_Write(aesm->sock, mem_ptr(&envelope), mem_size(&envelope)) != 0) OE_THROW(OE_FAILURE); @@ -449,7 +449,7 @@ OE_Result AESMGetLaunchToken( OE_TRY(_PackBytes(&request, 2, modulus, OE_KEY_SIZE)); /* Pack ATTRIBUTES */ - OE_TRY(_PackBytes(&request, 3, attributes, + OE_TRY(_PackBytes(&request, 3, attributes, sizeof(SGX_Attributes))); /* Pack TIMEOUT */ @@ -469,7 +469,7 @@ OE_Result AESMGetLaunchToken( /* Unpack the error code */ { uint32_t errcode; - OE_TRY(_UnpackVarInt(&response, &pos, 1, &errcode)); + OE_TRY(_UnpackVarInt(&response, &pos, 1, &errcode)); if (errcode != 0) OE_THROW(OE_FAILURE); @@ -526,7 +526,7 @@ OE_Result AESMInitQuote( /* Unpack the error code */ { uint32_t errcode; - OE_TRY(_UnpackVarInt(&response, &pos, 1, &errcode)); + OE_TRY(_UnpackVarInt(&response, &pos, 1, &errcode)); if (errcode != 0) OE_THROW(OE_FAILURE); @@ -616,7 +616,7 @@ OE_Result AESMGetQuote( /* Unpack the error code */ { uint32_t errcode; - OE_TRY(_UnpackVarInt(&response, &pos, 1, &errcode)); + OE_TRY(_UnpackVarInt(&response, &pos, 1, &errcode)); if (errcode != 0) OE_THROW(OE_FAILURE); @@ -628,7 +628,7 @@ OE_Result AESMGetQuote( /* Unpack optional reportOut */ if (reportOut) { - OE_TRY(_UnpackLengthDelimited(&response, &pos, 3, reportOut, + OE_TRY(_UnpackLengthDelimited(&response, &pos, 3, reportOut, sizeof(SGX_Report))); } } diff --git a/idl/CMakeLists.txt b/idl/CMakeLists.txt new file mode 100644 index 0000000000..979c79b8f5 --- /dev/null +++ b/idl/CMakeLists.txt @@ -0,0 +1,33 @@ +# Build the IDL enclave library + +add_library(oeidl STATIC + typeinfo.c + ) + +target_compile_options(oeidl PRIVATE + -Wall + -Werror + -m64 + -nostdinc + -Wno-attributes + -fPIC + -fno-stack-protector + -fvisibility=hidden + -Wmissing-prototypes + -Wstrict-prototypes + -fno-builtin-memcpy + -fno-builtin-memset + -fno-builtin-__vfprintf_chk + -fno-builtin-__memset_chk + ) + +target_compile_definitions(oeidl PRIVATE -DOE_BUILD_ENCLAVE) + +# this project (and is dependents) require the enclave headers+lib +target_link_libraries(oeidl oelibc) + +# assemble lib-archive into proper dir +set_property(TARGET oeidl PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${OE_LIBDIR}/openenclave/enclave) + +# install lib-archive upon install-time +install (TARGETS oeidl ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/openenclave/enclave) diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index cfaf21fa39..24dc426f7d 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -1,3 +1,5 @@ +# Build the C library, using local sources and sources from MUSL + set (MUSLSRC ${CMAKE_SOURCE_DIR}/3rdparty/musl/musl/src) add_library(oelibc STATIC @@ -526,12 +528,6 @@ add_library(oelibc STATIC ${MUSLSRC}/setjmp/x86_64/longjmp.s ) -#INCLUDES += -I$(TOP)/include/openenclave/libc -#INCLUDES += -I$(CURDIR)/internal -#INCLUDES += -I$(MUSLSRC)/internal - -target_link_libraries(oelibc oe_includes) - target_compile_options(oelibc PRIVATE -nostdinc @@ -548,8 +544,6 @@ target_compile_options(oelibc PRIVATE -std=c99 -m64 - -g - -O2 -fPIC -fno-stack-protector -fvisibility=hidden @@ -562,6 +556,21 @@ target_compile_options(oelibc PRIVATE target_compile_definitions(oelibc PRIVATE -D_XOPEN_SOURCE=700) -set_property(TARGET oelibc PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${OE_LIBDIR}/enclave) -install (TARGETS oelibc ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/enclave) +# this project (and is dependents) require the enclave headers+lib +target_link_libraries(oelibc oeenclave) + +# as a pre-build step, place the musl LIBC headers +add_dependencies(oelibc oelibc_includes) + +# this project and its dependents require include/libc in the include path +target_include_directories(oelibc PUBLIC ${OE_INCDIR}/openenclave/libc) + +# when building this project, we also need a number of internal includes +target_include_directories(oelibc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/internal) +target_include_directories(oelibc PRIVATE ${CMAKE_BINARY_DIR}/3rdparty/musl/musl/src/internal) + +# assemble lib-archive into proper dir +set_property(TARGET oelibc PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${OE_LIBDIR}/openenclave/enclave) +# install lib-archive upon install-time +install (TARGETS oelibc ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/openenclave/enclave) diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt new file mode 100644 index 0000000000..a93e4e96fe --- /dev/null +++ b/libcxx/CMakeLists.txt @@ -0,0 +1,44 @@ +# CMake project for CXX lib - re-archive the objects from +# external libcxx, libcxxrt, libunwind and wrap in easy-to-use CMake target +# +# Note: This approach might not work on Windows. +# Solutions are either to convert to OBJECT libraries (see below), or +# place/install all three libs (cxx, rt, unwind) and link against all +# three. + +# Use intermediate project and add properties later using an interface library +include (ExternalProject) +ExternalProject_Add(oelibcxx_tmp + DEPENDS cxxrt-static oelibcxx_unwind oelibcxx_cxx + DOWNLOAD_COMMAND "" + CONFIGURE_COMMAND "" + BUILD_COMMAND sh -c "rm -f *.o ${OE_LIBDIR}/enclave/liboelibcxx.a" + COMMAND ar x $ + COMMAND ar x ${CMAKE_BINARY_DIR}/3rdparty/libunwind/libunwind/src/.libs/libunwind.a + COMMAND ar x $ + COMMAND sh -c "ar qs ${OE_LIBDIR}/openenclave/enclave/liboelibcxx.a *.o" + INSTALL_COMMAND "" + ) + +# Interface lib to propagate includes&lib and install-rule +add_library(oelibcxx INTERFACE) +add_dependencies(oelibcxx oelibcxx_tmp) +target_link_libraries(oelibcxx INTERFACE ${OE_LIBDIR}/openenclave/enclave/liboelibcxx.a) +target_link_libraries(oelibcxx INTERFACE oelibcxx_cxx) +install (FILES ${OE_LIBDIR}/openenclave/enclave/liboelibcxx.a DESTINATION ${CMAKE_INSTALL_LIBDIR}/openenclave/enclave) + + +# At some point, we should convert the 3rdparty-libs into true CMake OBJECT libs, +# so we could source the objects directly like this: +#add_library(oelibcxx STATIC +# $ +# $ +# $ +# ) +#target_link_libraries(oelibcxx cxxrt-static) +#target_link_libraries(oelibcxx oelibcxx_unwind) +#target_link_libraries(oelibcxx oelibcxx_cxx) +# assemble lib-archive into proper dir +#set_property(TARGET oelibcxx PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${OE_LIBDIR}/enclave) +# install lib-archive upon install-time +#install (TARGETS oelibcxx ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/enclave) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000000..ce942e38b4 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,42 @@ +option(ENABLE_LIBC_TESTS "Build libc tests and include in test list" ON) +option(ENABLE_LIBCXX_TESTS "Build libcxx tests and include in test list" OFF) + +# The tests rely on assert() for both functional correctness and test +# validation. +STRING(APPEND CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE} " -UNDEBUG") +STRING(APPEND CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE} " -UNDEBUG") + +add_subdirectory(aesm) +add_subdirectory(ecall) +add_subdirectory(echo) +add_subdirectory(file) + +if(ENABLE_LIBC_TESTS) + add_subdirectory(libc) +else() + message("ENABLE_LIBC_TESTS not set - omit libc tests") +endif() + +if(ENABLE_LIBCXX_TESTS) + add_subdirectory(libcxx) +else() + message("ENABLE_LIBCXX_TESTS not set - omit libcxx tests") +endif() + +add_subdirectory(load) +add_subdirectory(mbed) +add_subdirectory(mem) +add_subdirectory(ocall) +add_subdirectory(pingpong) +add_subdirectory(print) +add_subdirectory(report) +add_subdirectory(ricochet) +add_subdirectory(SampleApp) +add_subdirectory(SampleAppAttestation) +add_subdirectory(SampleAppCRT) +add_subdirectory(stdc) +add_subdirectory(stdcxx) +add_subdirectory(str) +add_subdirectory(tester) +add_subdirectory(thread) +add_subdirectory(typeinfo) diff --git a/tests/SampleApp/CMakeLists.txt b/tests/SampleApp/CMakeLists.txt new file mode 100644 index 0000000000..a4a87d642e --- /dev/null +++ b/tests/SampleApp/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(SampleApp) +add_subdirectory(SampleAppHost) + +add_test(tests/SampleApp SampleAppHost/SampleAppHost SampleApp/SampleApp.signed.so) diff --git a/tests/SampleApp/SampleApp/CMakeLists.txt b/tests/SampleApp/SampleApp/CMakeLists.txt new file mode 100644 index 0000000000..ebaecfed6e --- /dev/null +++ b/tests/SampleApp/SampleApp/CMakeLists.txt @@ -0,0 +1,7 @@ +include(add_enclave_executable) +add_enclave_executable(SampleApp sign.conf private.pem + CallWrappers.cpp + SampleApp.cpp + ) + +target_compile_options(SampleApp PRIVATE -Wall -Werror) diff --git a/tests/SampleApp/SampleAppHost/CMakeLists.txt b/tests/SampleApp/SampleAppHost/CMakeLists.txt new file mode 100644 index 0000000000..a947b89bf4 --- /dev/null +++ b/tests/SampleApp/SampleAppHost/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(SampleAppHost CallWrappers.cpp SampleAppHost.cpp) + +target_link_libraries(SampleAppHost oehost) + +target_compile_options(SampleAppHost PRIVATE -Wall -Werror) +target_link_libraries(SampleAppHost -rdynamic) diff --git a/tests/SampleAppAttestation/CMakeLists.txt b/tests/SampleAppAttestation/CMakeLists.txt new file mode 100644 index 0000000000..a3f7aa06a3 --- /dev/null +++ b/tests/SampleAppAttestation/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(SampleAppAttestation) +add_subdirectory(SampleAppAttestationHost) + +add_test(tests/SampleAppAttestation SampleAppAttestationHost/SampleAppAttestationHost ./SampleAppAttestation/SampleAppAttestationenc.signed.so) diff --git a/tests/SampleAppAttestation/SampleAppAttestation/CMakeLists.txt b/tests/SampleAppAttestation/SampleAppAttestation/CMakeLists.txt new file mode 100644 index 0000000000..23bbf48756 --- /dev/null +++ b/tests/SampleAppAttestation/SampleAppAttestation/CMakeLists.txt @@ -0,0 +1,7 @@ +include(add_enclave_executable) +add_enclave_executable(SampleAppAttestation sign.conf private.pem + SampleAppAttestation.cpp + ) + +target_compile_options(SampleAppAttestation PRIVATE -Wall -Werror) +target_link_libraries(SampleAppAttestation oelibc) diff --git a/tests/SampleAppAttestation/SampleAppAttestationHost/CMakeLists.txt b/tests/SampleAppAttestation/SampleAppAttestationHost/CMakeLists.txt new file mode 100644 index 0000000000..94aa1abc9e --- /dev/null +++ b/tests/SampleAppAttestation/SampleAppAttestationHost/CMakeLists.txt @@ -0,0 +1,7 @@ +add_executable(SampleAppAttestationHost SampleAppAttestationHost.cpp) + +target_link_libraries(SampleAppAttestationHost oehost) + +target_compile_features(SampleAppAttestationHost PRIVATE cxx_generalized_initializers) +target_compile_options(SampleAppAttestationHost PRIVATE -Wall -Werror) +target_link_libraries(SampleAppAttestationHost -rdynamic) diff --git a/tests/SampleAppCRT/CMakeLists.txt b/tests/SampleAppCRT/CMakeLists.txt new file mode 100644 index 0000000000..15432a3dbe --- /dev/null +++ b/tests/SampleAppCRT/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(SampleAppCRT) +add_subdirectory(SampleAppCRTHost) + +add_test(tests/SampleAppCRT SampleAppCRTHost/SampleAppCRTHost SampleAppCRT/SampleAppCRT.signed.so) diff --git a/tests/SampleAppCRT/SampleAppCRT/CMakeLists.txt b/tests/SampleAppCRT/SampleAppCRT/CMakeLists.txt new file mode 100644 index 0000000000..f8885c7fdd --- /dev/null +++ b/tests/SampleAppCRT/SampleAppCRT/CMakeLists.txt @@ -0,0 +1,8 @@ +include(add_enclave_executable) + +add_enclave_executable(SampleAppCRT sign.conf private.pem + SampleAppCRT.cpp + ) + +target_compile_options(SampleAppCRT PRIVATE -Wall -Werror) +target_link_libraries(SampleAppCRT oelibc) diff --git a/tests/SampleAppCRT/SampleAppCRTHost/CMakeLists.txt b/tests/SampleAppCRT/SampleAppCRTHost/CMakeLists.txt new file mode 100644 index 0000000000..38ebe2bec0 --- /dev/null +++ b/tests/SampleAppCRT/SampleAppCRTHost/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(SampleAppCRTHost SampleAppCRTHost.cpp) + +target_link_libraries(SampleAppCRTHost oehost) + +target_compile_options(SampleAppCRTHost PRIVATE -Wall -Werror) +target_link_libraries(SampleAppCRTHost -rdynamic) diff --git a/tests/aesm/CMakeLists.txt b/tests/aesm/CMakeLists.txt new file mode 100644 index 0000000000..2c756b7c5f --- /dev/null +++ b/tests/aesm/CMakeLists.txt @@ -0,0 +1,7 @@ +add_executable(aesm main.cpp) + +target_link_libraries(aesm oehost) + +target_compile_options(aesm PRIVATE -Wall -Werror) + +add_test(NAME tests/aesm COMMAND ./aesm) diff --git a/tests/attic/dead.txt b/tests/attic/dead.txt new file mode 100644 index 0000000000..f87be6209c --- /dev/null +++ b/tests/attic/dead.txt @@ -0,0 +1 @@ +Not building, could be removed, left for the time being. diff --git a/tests/ecall/CMakeLists.txt b/tests/ecall/CMakeLists.txt new file mode 100644 index 0000000000..3983495b28 --- /dev/null +++ b/tests/ecall/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(enc) +add_subdirectory(host) + +add_test(tests/ecall host/ecallhost ./enc/ecallenc.signed.so) diff --git a/tests/ecall/enc/CMakeLists.txt b/tests/ecall/enc/CMakeLists.txt new file mode 100644 index 0000000000..350f982f1c --- /dev/null +++ b/tests/ecall/enc/CMakeLists.txt @@ -0,0 +1,6 @@ +include(add_enclave_executable) +add_enclave_executable(ecallenc sign.conf private.pem + enc.cpp + ) + +target_compile_options(ecallenc PRIVATE -Wall -Werror) diff --git a/tests/ecall/host/CMakeLists.txt b/tests/ecall/host/CMakeLists.txt new file mode 100644 index 0000000000..fa5401e1c6 --- /dev/null +++ b/tests/ecall/host/CMakeLists.txt @@ -0,0 +1,9 @@ +add_executable(ecallhost host.cpp) + +target_link_libraries(ecallhost oehost) + +target_compile_options(ecallhost PRIVATE + -Wall -Werror + -Wno-error=unused-but-set-variable + ) +target_link_libraries(ecallhost -rdynamic) diff --git a/tests/echo/CMakeLists.txt b/tests/echo/CMakeLists.txt new file mode 100644 index 0000000000..7f5f98daea --- /dev/null +++ b/tests/echo/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(enc) +add_subdirectory(host) + +add_test(tests/echo host/echohost ./enc/echoenc.signed.so) diff --git a/tests/echo/enc/CMakeLists.txt b/tests/echo/enc/CMakeLists.txt new file mode 100644 index 0000000000..a07b86ba96 --- /dev/null +++ b/tests/echo/enc/CMakeLists.txt @@ -0,0 +1,6 @@ +include(add_enclave_executable) +add_enclave_executable(echoenc sign.conf private.pem + enc.c + ) + +target_compile_options(echoenc PRIVATE -Wall -Werror) diff --git a/tests/echo/host/CMakeLists.txt b/tests/echo/host/CMakeLists.txt new file mode 100644 index 0000000000..f611ff9ea8 --- /dev/null +++ b/tests/echo/host/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(echohost host.c) + +target_link_libraries(echohost oehost) + +target_compile_options(echohost PRIVATE -Wall -Werror) +target_link_libraries(echohost -rdynamic) diff --git a/tests/eenter/dead.txt b/tests/eenter/dead.txt new file mode 100644 index 0000000000..f87be6209c --- /dev/null +++ b/tests/eenter/dead.txt @@ -0,0 +1 @@ +Not building, could be removed, left for the time being. diff --git a/tests/file/CMakeLists.txt b/tests/file/CMakeLists.txt new file mode 100644 index 0000000000..8dca860082 --- /dev/null +++ b/tests/file/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(enc) +add_subdirectory(host) + +add_test(tests/file host/filehost ./enc/fileenc.signed.so) diff --git a/tests/file/enc/CMakeLists.txt b/tests/file/enc/CMakeLists.txt new file mode 100644 index 0000000000..0f3d939e43 --- /dev/null +++ b/tests/file/enc/CMakeLists.txt @@ -0,0 +1,12 @@ +include(oeidl_file) +include(add_enclave_executable) + +oeidl_file(../file.idl enclave gen) +add_enclave_executable(fileenc sign.conf private.pem + enc.cpp + ${gen} + ) + +target_include_directories(fileenc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +target_compile_options(fileenc PRIVATE -Wall -Werror) +target_link_libraries(fileenc oeidl oelibc) diff --git a/tests/file/host/CMakeLists.txt b/tests/file/host/CMakeLists.txt new file mode 100644 index 0000000000..82ecadc595 --- /dev/null +++ b/tests/file/host/CMakeLists.txt @@ -0,0 +1,9 @@ +include(oeidl_file) +oeidl_file(../file.idl host gen) + +add_executable(filehost host.cpp ${gen}) + +target_include_directories(filehost PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +target_link_libraries(filehost oehost) +target_compile_options(filehost PRIVATE -Wall -Werror) +target_link_libraries(filehost -rdynamic) diff --git a/tests/hashstr/dead.txt b/tests/hashstr/dead.txt new file mode 100644 index 0000000000..f87be6209c --- /dev/null +++ b/tests/hashstr/dead.txt @@ -0,0 +1 @@ +Not building, could be removed, left for the time being. diff --git a/tests/libc/CMakeLists.txt b/tests/libc/CMakeLists.txt new file mode 100644 index 0000000000..e91b5b2787 --- /dev/null +++ b/tests/libc/CMakeLists.txt @@ -0,0 +1,12 @@ +# add a test-case for each file listed in tests.supported +include(${CMAKE_CURRENT_LIST_DIR}/get_testcase_name.cmake) + +# read tests.supported, sanitize the c-file, and create the test-case +file(STRINGS "tests.supported" alltests) +foreach(testcase ${alltests}) + get_testcase_name(${testcase} name) + add_test(tests/libc/${name} host/libchost ./enc/libctest-${name}.signed.so) +endforeach(testcase) + +add_subdirectory(enc) +add_subdirectory(host) diff --git a/tests/libc/enc/CMakeLists.txt b/tests/libc/enc/CMakeLists.txt new file mode 100644 index 0000000000..f56044e6dd --- /dev/null +++ b/tests/libc/enc/CMakeLists.txt @@ -0,0 +1,43 @@ +# create a binary for each testcase listed in ../tests.supported + +include(add_enclave_executable) +include(${CMAKE_CURRENT_LIST_DIR}/../get_testcase_name.cmake) + +# helper lib to contain file needed by some tests +add_library(libctest-support + mtest.c + rand.c + tls_align_dso.c + ) +target_compile_options(libctest-support PRIVATE + -m64 -nostdinc -fPIC -fno-stack-protector + $<$:-std=c++14 -nostdinc++> + ) +target_link_libraries(libctest-support PUBLIC oelibc) + +function(add_libc_test_enc NAME CFILE) + add_enclave_executable(libctest-${NAME} sign.conf private.pem + enc.c + main.c + ) + + target_include_directories(libctest-${NAME} PRIVATE + .. + ${CMAKE_SOURCE_DIR}/3rdparty/musl/libc-test/src/common + ) + target_compile_options(libctest-${NAME} PRIVATE + -Wall -Werror + -Wno-error=missing-braces + -Wno-error=overflow + -Wno-error=unused-value + -Wno-error=unused-variable + ) + target_compile_definitions(libctest-${NAME} PRIVATE -D__TEST__="${CFILE}") + target_link_libraries(libctest-${NAME} libctest-support) +endfunction(add_libc_test_enc) + +file(STRINGS "../tests.supported" alltests) +foreach(testcase ${alltests}) + get_testcase_name(${testcase} name) + add_libc_test_enc("${name}" "${testcase}") +endforeach(testcase) diff --git a/tests/libc/get_testcase_name.cmake b/tests/libc/get_testcase_name.cmake new file mode 100644 index 0000000000..696d376687 --- /dev/null +++ b/tests/libc/get_testcase_name.cmake @@ -0,0 +1,18 @@ +# Helper function to obtain name for a test-case. Given a filename, chop +# extension, dir-prefix, and replace special chars. +# +# Usage: +# +# get_testcase_name( ) +# +# Arguments: +# filename - filename containing the test +# namevar - variable to receive the testcase name +# +function(get_testcase_name FILENAME NAMEVAR) + string(REGEX REPLACE "\.c(pp)?$" "" n ${FILENAME}) + string(REGEX REPLACE "^\.\./\.\./3rdparty/(libcxx/libcxx/test/|musl/libc-test/src/)" "" n ${n}) + string(REGEX REPLACE "[/=]" "_" n ${n}) + string(REGEX REPLACE "[\!]" "-" n ${n}) + set(${NAMEVAR} ${n} PARENT_SCOPE) +endfunction(get_testcase_name) diff --git a/tests/libc/host/CMakeLists.txt b/tests/libc/host/CMakeLists.txt new file mode 100644 index 0000000000..adc7800705 --- /dev/null +++ b/tests/libc/host/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(libchost host.cpp) + +target_link_libraries(libchost oehost) + +target_compile_options(libchost PRIVATE -Wall -Werror) +target_link_libraries(libchost -rdynamic) diff --git a/tests/libc/host/host.cpp b/tests/libc/host/host.cpp index d7e0011427..cd849e680f 100644 --- a/tests/libc/host/host.cpp +++ b/tests/libc/host/host.cpp @@ -72,6 +72,7 @@ int main(int argc, const char* argv[]) // Check for the --sim option: if (_GetOpt(argc, argv, "--simulate") == 1) flags |= OE_FLAG_SIMULATE; + else flags = OE_GetCreateFlags(); // Check argument count: if (argc != 2) diff --git a/tests/libcxx/CMakeLists.txt b/tests/libcxx/CMakeLists.txt new file mode 100644 index 0000000000..95c91cb1e3 --- /dev/null +++ b/tests/libcxx/CMakeLists.txt @@ -0,0 +1,12 @@ +# add a test-case for each file listed in tests.supported +include(${CMAKE_CURRENT_LIST_DIR}/../libc/get_testcase_name.cmake) + +# read tests.supported, sanitize the cpp-file, and create the test-case +file(STRINGS "tests.supported" alltests) +foreach(testcase ${alltests}) + get_testcase_name(${testcase} name) + add_test(tests/libcxx/${name} sh -c "host/libcxxhost ./enc/libcxxtest-${name}.signed.so") +endforeach(testcase) + +add_subdirectory(enc) +add_subdirectory(host) diff --git a/tests/libcxx/enc/CMakeLists.txt b/tests/libcxx/enc/CMakeLists.txt new file mode 100644 index 0000000000..5790d3b843 --- /dev/null +++ b/tests/libcxx/enc/CMakeLists.txt @@ -0,0 +1,45 @@ +# create a binary for each testcase listed in ../tests.supported + +include(add_enclave_executable) +include(${CMAKE_CURRENT_LIST_DIR}/../../libc/get_testcase_name.cmake) + +# helper lib to contain file needed by some tests +add_library(libcxxtest-support + fuzzing.cpp + memory_resource.cpp + ) +target_compile_options(libcxxtest-support PRIVATE + -Wall -Werror + -m64 -nostdinc -fPIC -fno-stack-protector + $<$:-std=c++14 -nostdinc++> + ) +target_link_libraries(libcxxtest-support PUBLIC oelibcxx) + +# helper function to create enclave binary +function(add_libcxx_test_enc NAME CXXFILE) + #message("libcxx-test NAME=${NAME} CXXFILE=${CXXFILE}") + add_enclave_executable(libcxxtest-${NAME} sign.conf private.pem + enc.cpp + main.cpp + ) + + target_include_directories(libcxxtest-${NAME} PRIVATE + .. + ${CMAKE_SOURCE_DIR}/3rdparty/libcxx/libcxx/test + ${CMAKE_SOURCE_DIR}/3rdparty/libcxx/libcxx/test/support + ${CMAKE_SOURCE_DIR}/3rdparty/libcxx/libcxx/fuzzing + ) + + target_compile_options(libcxxtest-${NAME} PRIVATE -Wall) + set_source_files_properties(enc.cpp PROPERTIES COMPILE_FLAGS -Werror) + set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS WITH_MAIN) + target_compile_definitions(libcxxtest-${NAME} PRIVATE -D__TEST__="${CXXFILE}") + target_link_libraries(libcxxtest-${NAME} libcxxtest-support) +endfunction(add_libcxx_test_enc) + +# iterate over the supported tests and create a binary for each. +file(STRINGS "../tests.supported" alltests) +foreach(testcase ${alltests}) + get_testcase_name(${testcase} name) + add_libcxx_test_enc("${name}" "${testcase}") +endforeach(testcase) diff --git a/tests/libcxx/host/CMakeLists.txt b/tests/libcxx/host/CMakeLists.txt new file mode 100644 index 0000000000..61363e6a9a --- /dev/null +++ b/tests/libcxx/host/CMakeLists.txt @@ -0,0 +1,5 @@ +add_executable(libcxxhost host.cpp) + +target_link_libraries(libcxxhost oehost) +target_compile_options(libcxxhost PRIVATE -Wall -Werror) +target_link_libraries(libcxxhost -rdynamic) diff --git a/tests/libcxx/host/host.cpp b/tests/libcxx/host/host.cpp index d7e0011427..cd849e680f 100644 --- a/tests/libcxx/host/host.cpp +++ b/tests/libcxx/host/host.cpp @@ -72,6 +72,7 @@ int main(int argc, const char* argv[]) // Check for the --sim option: if (_GetOpt(argc, argv, "--simulate") == 1) flags |= OE_FLAG_SIMULATE; + else flags = OE_GetCreateFlags(); // Check argument count: if (argc != 2) diff --git a/tests/load/CMakeLists.txt b/tests/load/CMakeLists.txt new file mode 100644 index 0000000000..e4c7aac678 --- /dev/null +++ b/tests/load/CMakeLists.txt @@ -0,0 +1,7 @@ +add_executable(load main.cpp) + +target_link_libraries(load oehost) + +target_compile_options(echohost PRIVATE + -Wall -Werror -g -O2 + ) diff --git a/tests/load/dead.txt b/tests/load/dead.txt new file mode 100644 index 0000000000..f87be6209c --- /dev/null +++ b/tests/load/dead.txt @@ -0,0 +1 @@ +Not building, could be removed, left for the time being. diff --git a/tests/mbed/CMakeLists.txt b/tests/mbed/CMakeLists.txt new file mode 100644 index 0000000000..4f57507204 --- /dev/null +++ b/tests/mbed/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(enc) +add_subdirectory(host) + +add_test(tests/mbed host/mbedhost ./enc/mbedenc.signed.so) diff --git a/tests/mbed/enc/CMakeLists.txt b/tests/mbed/enc/CMakeLists.txt new file mode 100644 index 0000000000..cc6a5efab6 --- /dev/null +++ b/tests/mbed/enc/CMakeLists.txt @@ -0,0 +1,7 @@ +include(add_enclave_executable) +add_enclave_executable(mbedenc sign.conf private.pem + enc.c + ) + +target_compile_options(mbedenc PRIVATE -Wall -Werror) +target_link_libraries(mbedenc mbedcrypto oelibc) diff --git a/tests/mbed/host/CMakeLists.txt b/tests/mbed/host/CMakeLists.txt new file mode 100644 index 0000000000..03cc3fc45b --- /dev/null +++ b/tests/mbed/host/CMakeLists.txt @@ -0,0 +1,9 @@ +add_executable(mbedhost host.c) + +target_link_libraries(mbedhost oehost) + +target_compile_options(mbedhost PRIVATE + -Wall -Werror -Wall + -Werror -Wno-error=unused-variable + ) +target_link_libraries(mbedhost -rdynamic) diff --git a/tests/measure/dead.txt b/tests/measure/dead.txt new file mode 100644 index 0000000000..f87be6209c --- /dev/null +++ b/tests/measure/dead.txt @@ -0,0 +1 @@ +Not building, could be removed, left for the time being. diff --git a/tests/mem/CMakeLists.txt b/tests/mem/CMakeLists.txt new file mode 100644 index 0000000000..42eb902afb --- /dev/null +++ b/tests/mem/CMakeLists.txt @@ -0,0 +1,8 @@ +add_executable(mem main.c) + +target_link_libraries(mem oehost) + +target_compile_options(echohost PRIVATE -Wall -Werror) + +add_test(tests/mem mem) + diff --git a/tests/ocall/CMakeLists.txt b/tests/ocall/CMakeLists.txt new file mode 100644 index 0000000000..b81108c7cf --- /dev/null +++ b/tests/ocall/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(enc) +add_subdirectory(host) + +add_test(tests/ocall host/ocallhost ./enc/ocallenc.signed.so) diff --git a/tests/ocall/enc/CMakeLists.txt b/tests/ocall/enc/CMakeLists.txt new file mode 100644 index 0000000000..0cc0fec90e --- /dev/null +++ b/tests/ocall/enc/CMakeLists.txt @@ -0,0 +1,6 @@ +include(add_enclave_executable) +add_enclave_executable(ocallenc sign.conf private.pem + enc.cpp + ) + +target_compile_options(ocallenc PRIVATE -Wall -Werror) diff --git a/tests/ocall/host/CMakeLists.txt b/tests/ocall/host/CMakeLists.txt new file mode 100644 index 0000000000..4a7d7df598 --- /dev/null +++ b/tests/ocall/host/CMakeLists.txt @@ -0,0 +1,9 @@ +add_executable(ocallhost host.cpp) + +target_link_libraries(ocallhost oehost) + +target_compile_options(ocallhost PRIVATE + -Wall -Werror + -Wno-error=unused-but-set-variable -Wno-error=unused-variable + ) +target_link_libraries(ocallhost -rdynamic) diff --git a/tests/pingpong/CMakeLists.txt b/tests/pingpong/CMakeLists.txt new file mode 100644 index 0000000000..e9fa574469 --- /dev/null +++ b/tests/pingpong/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(enc) +add_subdirectory(host) + +add_test(tests/pingpong host/pingponghost ./enc/pingpongenc.signed.so) diff --git a/tests/pingpong/enc/CMakeLists.txt b/tests/pingpong/enc/CMakeLists.txt new file mode 100644 index 0000000000..25f41a0020 --- /dev/null +++ b/tests/pingpong/enc/CMakeLists.txt @@ -0,0 +1,12 @@ +include(oeidl_file) +include(add_enclave_executable) + +oeidl_file(../pingpong.idl enclave gen) +add_enclave_executable(pingpongenc sign.conf private.pem + enc.cpp + ${gen} + ) + +target_include_directories(pingpongenc PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +target_compile_options(pingpongenc PRIVATE -Wall -Werror) +target_link_libraries(pingpongenc oeidl oelibc) diff --git a/tests/pingpong/host/CMakeLists.txt b/tests/pingpong/host/CMakeLists.txt new file mode 100644 index 0000000000..7cd00ba5d5 --- /dev/null +++ b/tests/pingpong/host/CMakeLists.txt @@ -0,0 +1,9 @@ +include(oeidl_file) +oeidl_file(../pingpong.idl host gen) + +add_executable(pingponghost host.cpp ${gen}) + +target_include_directories(pingponghost PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +target_link_libraries(pingponghost oehost) +target_compile_options(pingponghost PRIVATE -Wall -Werror) +target_link_libraries(pingponghost -rdynamic) diff --git a/tests/print/CMakeLists.txt b/tests/print/CMakeLists.txt new file mode 100644 index 0000000000..2a51b36d2a --- /dev/null +++ b/tests/print/CMakeLists.txt @@ -0,0 +1,10 @@ +add_subdirectory(enc) +add_subdirectory(host) + +# note: this is Linux-specific +add_test(NAME tests/print + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND sh -c "host/printhost ./enc/printenc.signed.so >testout.stdout 2>testout.stderr && + diff ${CMAKE_CURRENT_SOURCE_DIR}/printhost.stdout testout.stdout && + diff ${CMAKE_CURRENT_SOURCE_DIR}/printhost.stderr testout.stderr" + ) diff --git a/tests/print/enc/CMakeLists.txt b/tests/print/enc/CMakeLists.txt new file mode 100644 index 0000000000..a09cdcf148 --- /dev/null +++ b/tests/print/enc/CMakeLists.txt @@ -0,0 +1,15 @@ +include(add_enclave_executable) +add_enclave_executable(printenc sign.conf private.pem + enc.cpp + ) + +target_compile_options(printenc PRIVATE + -Wall -Werror + -Wno-error=unused-but-set-variable + -fno-builtin-strcpy + -fno-builtin-strcat + -fno-builtin-memcpy + -fno-builtin-memset + ) + +target_link_libraries(printenc -Wl,--whole-archive oelibc -Wl,--no-whole-archive) diff --git a/tests/print/host/CMakeLists.txt b/tests/print/host/CMakeLists.txt new file mode 100644 index 0000000000..82476733af --- /dev/null +++ b/tests/print/host/CMakeLists.txt @@ -0,0 +1,9 @@ +add_executable(printhost host.cpp) + +target_link_libraries(printhost oehost) + +target_compile_options(printhost PRIVATE + -Wall -Werror + -Wno-error=unused-but-set-variable + ) +target_link_libraries(printhost -rdynamic) diff --git a/tests/report/CMakeLists.txt b/tests/report/CMakeLists.txt new file mode 100644 index 0000000000..48810cc8ed --- /dev/null +++ b/tests/report/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(enc) +add_subdirectory(host) + +add_test(tests/report host/reporthost ./enc/reportenc.signed.so) diff --git a/tests/report/enc/CMakeLists.txt b/tests/report/enc/CMakeLists.txt new file mode 100644 index 0000000000..ecfc5411a9 --- /dev/null +++ b/tests/report/enc/CMakeLists.txt @@ -0,0 +1,6 @@ +include(add_enclave_executable) +add_enclave_executable(reportenc sign.conf private.pem + enc.cpp + ) + +target_compile_options(echoenc PRIVATE -Wall -Werror) diff --git a/tests/report/host/CMakeLists.txt b/tests/report/host/CMakeLists.txt new file mode 100644 index 0000000000..0bb878a1f8 --- /dev/null +++ b/tests/report/host/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(reporthost host.cpp) + +target_link_libraries(reporthost oehost) + +target_compile_options(reporthost PRIVATE -Wall -Werror) +target_link_libraries(reporthost -rdynamic) diff --git a/tests/ricochet/CMakeLists.txt b/tests/ricochet/CMakeLists.txt new file mode 100644 index 0000000000..87a1204131 --- /dev/null +++ b/tests/ricochet/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(enc) +add_subdirectory(host) + +add_test(tests/ricochet host/ricochethost ./enc/ricochetenc.signed.so) diff --git a/tests/ricochet/enc/CMakeLists.txt b/tests/ricochet/enc/CMakeLists.txt new file mode 100644 index 0000000000..050cfaf399 --- /dev/null +++ b/tests/ricochet/enc/CMakeLists.txt @@ -0,0 +1,6 @@ +include(add_enclave_executable) +add_enclave_executable(ricochetenc sign.conf private.pem + enc.c + ) + +target_compile_options(ricochetenc PRIVATE -Wall -Werror) diff --git a/tests/ricochet/host/CMakeLists.txt b/tests/ricochet/host/CMakeLists.txt new file mode 100644 index 0000000000..4fcf4d8c9a --- /dev/null +++ b/tests/ricochet/host/CMakeLists.txt @@ -0,0 +1,9 @@ +add_executable(ricochethost host.c) + +target_link_libraries(ricochethost oehost) + +target_compile_options(ricochethost PRIVATE + -Wall -Werror + -Wno-error=unused-variable + ) +target_link_libraries(ricochethost -rdynamic) diff --git a/tests/stdc/CMakeLists.txt b/tests/stdc/CMakeLists.txt new file mode 100644 index 0000000000..f7f7271c79 --- /dev/null +++ b/tests/stdc/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(enc) +add_subdirectory(host) + +add_test(tests/stdc host/stdchost ./enc/stdcenc.signed.so) diff --git a/tests/stdc/enc/CMakeLists.txt b/tests/stdc/enc/CMakeLists.txt new file mode 100644 index 0000000000..65c6adcf2a --- /dev/null +++ b/tests/stdc/enc/CMakeLists.txt @@ -0,0 +1,15 @@ +include(add_enclave_executable) +add_enclave_executable(stdcenc sign.conf private.pem + enc.cpp + ) + +target_compile_options(stdcenc PRIVATE -Wall -Werror + -Wno-error=unused-but-set-variable + -Wno-error=unused-variable + -fno-builtin-strcpy + -fno-builtin-strcat + -fno-builtin-memcpy + -fno-builtin-memset + ) + +target_link_libraries(stdcenc -Wl,--whole-archive oelibc -Wl,--no-whole-archive) diff --git a/tests/stdc/host/CMakeLists.txt b/tests/stdc/host/CMakeLists.txt new file mode 100644 index 0000000000..26a22e390e --- /dev/null +++ b/tests/stdc/host/CMakeLists.txt @@ -0,0 +1,9 @@ +add_executable(stdchost host.cpp) + +target_link_libraries(stdchost oehost) + +target_compile_options(stdchost PRIVATE + -Wno-error=unused-but-set-variable + -Wall -Werror + ) +target_link_libraries(stdchost -rdynamic) diff --git a/tests/stdcxx/CMakeLists.txt b/tests/stdcxx/CMakeLists.txt new file mode 100644 index 0000000000..c44b625549 --- /dev/null +++ b/tests/stdcxx/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(enc) +add_subdirectory(host) + +add_test(tests/stdcxx host/stdcxxhost ./enc/stdcxxenc.signed.so) diff --git a/tests/stdcxx/enc/CMakeLists.txt b/tests/stdcxx/enc/CMakeLists.txt new file mode 100644 index 0000000000..deb93d9e04 --- /dev/null +++ b/tests/stdcxx/enc/CMakeLists.txt @@ -0,0 +1,16 @@ +include(add_enclave_executable) +add_enclave_executable(stdcxxenc sign.conf private.pem + enc.cpp + f.cpp + ) + +target_compile_options(stdcxxenc PRIVATE -Wall -Werror + -fno-builtin-strcpy + -fno-builtin-strcat + -fno-builtin-memcpy + -fno-builtin-memset + -fno-builtin-fprintf + -fno-builtin-printf + ) + +target_link_libraries(stdcxxenc -Wl,--whole-archive oelibcxx oelibc -Wl,--no-whole-archive) diff --git a/tests/stdcxx/host/CMakeLists.txt b/tests/stdcxx/host/CMakeLists.txt new file mode 100644 index 0000000000..19e29a61a7 --- /dev/null +++ b/tests/stdcxx/host/CMakeLists.txt @@ -0,0 +1,9 @@ +add_executable(stdcxxhost host.cpp) + +target_link_libraries(stdcxxhost oehost) + +target_compile_options(stdcxxhost PRIVATE + -Wno-error=unused-but-set-variable + -Wall -Werror + ) +target_link_libraries(stdcxxhost -rdynamic) diff --git a/tests/str/CMakeLists.txt b/tests/str/CMakeLists.txt new file mode 100644 index 0000000000..a119371ccd --- /dev/null +++ b/tests/str/CMakeLists.txt @@ -0,0 +1,11 @@ +add_executable(str main.c) + +target_link_libraries(str oehost) + +target_compile_options(str PRIVATE + -Wall -Werror + -Wno-error=unused-variable + -Wno-error=unused-but-set-variable + ) + +add_test(NAME tests/str COMMAND str WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/tests/tester/CMakeLists.txt b/tests/tester/CMakeLists.txt new file mode 100644 index 0000000000..c1a7230f1e --- /dev/null +++ b/tests/tester/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(enc) +add_subdirectory(host) + +add_test(tests/tester host/testerhost ./enc/testerenc.signed.so) diff --git a/tests/tester/enc/CMakeLists.txt b/tests/tester/enc/CMakeLists.txt new file mode 100644 index 0000000000..4952601fad --- /dev/null +++ b/tests/tester/enc/CMakeLists.txt @@ -0,0 +1,12 @@ +include(oeidl_file) +include(add_enclave_executable) + +oeidl_file(../tester.idl enclave gen) +add_enclave_executable(testerenc sign.conf private.pem + enc.cpp + ${gen} + ) + +target_include_directories(testerenc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +target_compile_options(testerenc PRIVATE -Wall -Werror) +target_link_libraries(testerenc oeidl oelibc) diff --git a/tests/tester/host/CMakeLists.txt b/tests/tester/host/CMakeLists.txt new file mode 100644 index 0000000000..9d2d742348 --- /dev/null +++ b/tests/tester/host/CMakeLists.txt @@ -0,0 +1,9 @@ +include(oeidl_file) +oeidl_file(../tester.idl host gen) + +add_executable(testerhost host.cpp ${gen}) + +target_include_directories(testerhost PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +target_link_libraries(testerhost oehost) +target_compile_options(testerhost PRIVATE -Wall -Werror) +target_link_libraries(testerhost -rdynamic) diff --git a/tests/thread/CMakeLists.txt b/tests/thread/CMakeLists.txt new file mode 100644 index 0000000000..f275bb864b --- /dev/null +++ b/tests/thread/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(enc) +add_subdirectory(host) + +add_test(tests/thread host/threadhost ./enc/threadenc.signed.so) diff --git a/tests/thread/enc/CMakeLists.txt b/tests/thread/enc/CMakeLists.txt new file mode 100644 index 0000000000..f658d9fb6e --- /dev/null +++ b/tests/thread/enc/CMakeLists.txt @@ -0,0 +1,14 @@ +include(add_enclave_executable) +add_enclave_executable(threadenc sign.conf private.pem + enc.cpp + ) + +target_compile_options(threadenc PRIVATE + -fno-builtin-strcpy + -fno-builtin-strcat + -fno-builtin-memcpy + -fno-builtin-memset + -Wall -Werror) + +target_link_libraries(threadenc oelibc) + diff --git a/tests/thread/host/CMakeLists.txt b/tests/thread/host/CMakeLists.txt new file mode 100644 index 0000000000..bf32b7c8cc --- /dev/null +++ b/tests/thread/host/CMakeLists.txt @@ -0,0 +1,9 @@ +add_executable(threadhost host.cpp) + +target_link_libraries(threadhost oehost) + +target_compile_options(threadhost PRIVATE + -Wno-error=unused-variable + -Wall -Werror + ) +target_link_libraries(threadhost -rdynamic) diff --git a/tests/typeinfo/CMakeLists.txt b/tests/typeinfo/CMakeLists.txt new file mode 100644 index 0000000000..a82defc12a --- /dev/null +++ b/tests/typeinfo/CMakeLists.txt @@ -0,0 +1,13 @@ +include(oeidl_file) +oeidl_file(typeinfo.idl host idlfiles) + +add_executable(typeinfo + main.cpp + ${idlfiles} + ) + +target_include_directories(typeinfo PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +target_compile_options(typeinfo PRIVATE -Wall -Werror) +target_link_libraries(typeinfo oehost) + +add_test(tests/typeinfo typeinfo) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 0000000000..d92b5e6c74 --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,6 @@ +add_subdirectory(dox2md) +add_subdirectory(oedump) +add_subdirectory(oeelf) +add_subdirectory(oegen) +add_subdirectory(oesgx) +add_subdirectory(oesign) diff --git a/tools/dox2md/CMakeLists.txt b/tools/dox2md/CMakeLists.txt new file mode 100644 index 0000000000..baaea129dc --- /dev/null +++ b/tools/dox2md/CMakeLists.txt @@ -0,0 +1,13 @@ +add_executable(dox2md + element.cpp + err.cpp + main.cpp + ) + +target_compile_options(dox2md PRIVATE -Wall) +target_link_libraries(dox2md expat) + +# assemble into proper collector dir +set_property(TARGET dox2md PROPERTY RUNTIME_OUTPUT_DIRECTORY ${OE_BINDIR}) + +# no install rule - not distributed diff --git a/tools/oedump/CMakeLists.txt b/tools/oedump/CMakeLists.txt new file mode 100644 index 0000000000..0b06aff7bc --- /dev/null +++ b/tools/oedump/CMakeLists.txt @@ -0,0 +1,13 @@ +add_executable(oedump main.c) + +target_link_libraries(oedump oehost) + +# assemble into proper collector dir +set_property(TARGET oedump PROPERTY RUNTIME_OUTPUT_DIRECTORY ${OE_BINDIR}) + +# test-case +add_test(NAME tools/oedump + COMMAND oedump $.signed.so) + +# install rule +install (TARGETS oedump DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/tools/oeelf/CMakeLists.txt b/tools/oeelf/CMakeLists.txt new file mode 100644 index 0000000000..e336f0a477 --- /dev/null +++ b/tools/oeelf/CMakeLists.txt @@ -0,0 +1,12 @@ +add_executable(oeelf main.c) + +target_link_libraries(oeelf oehost) + +# assemble into proper collector dir +set_property(TARGET oeelf PROPERTY RUNTIME_OUTPUT_DIRECTORY ${OE_BINDIR}) + +# no install rule - not distributed +install (TARGETS oeelf DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_test(oeelf ${OE_BINDIR}/oeelf ${CMAKE_BINARY_DIR}/tests/echo/enc/echoenc.signed.so) + diff --git a/tools/oeelf/README.md b/tools/oeelf/README.md new file mode 100644 index 0000000000..2589438c53 --- /dev/null +++ b/tools/oeelf/README.md @@ -0,0 +1,3 @@ +Enclave binary inspection tool similar to readelf. + +Less useful for an enclave developer, yet valuable for elf lib debugging. diff --git a/tools/oegen/CMakeLists.txt b/tools/oegen/CMakeLists.txt new file mode 100644 index 0000000000..1aabe75286 --- /dev/null +++ b/tools/oegen/CMakeLists.txt @@ -0,0 +1,19 @@ +add_executable(oegen + files.cpp + generator.cpp + lexer.cpp + main.cpp + objects.cpp + parser.cpp + types.cpp + ) + +target_compile_options(oegen PRIVATE -Wall -Werror) +target_link_libraries(oegen oehost) + +# assemble into proper collector dir +set_property(TARGET oegen PROPERTY RUNTIME_OUTPUT_DIRECTORY ${OE_BINDIR}) + +# install rule +install (TARGETS oegen DESTINATION ${CMAKE_INSTALL_BINDIR}) + diff --git a/tools/oesgx/CMakeLists.txt b/tools/oesgx/CMakeLists.txt new file mode 100644 index 0000000000..5953e0db25 --- /dev/null +++ b/tools/oesgx/CMakeLists.txt @@ -0,0 +1,10 @@ +add_executable(oesgx oesgx.c) + +target_compile_options(oesgx PRIVATE -Wall -O2) + +# assemble into proper collector dir +set_property(TARGET oesgx PROPERTY RUNTIME_OUTPUT_DIRECTORY ${OE_BINDIR}) + +# install rule +install (TARGETS oesgx DESTINATION ${CMAKE_INSTALL_BINDIR}) + diff --git a/tools/oesign/CMakeLists.txt b/tools/oesign/CMakeLists.txt new file mode 100644 index 0000000000..eaff37bbce --- /dev/null +++ b/tools/oesign/CMakeLists.txt @@ -0,0 +1,10 @@ +add_executable(oesign main.c) + +target_link_libraries(oesign oehost) + +# assemble into proper collector dir +set_property(TARGET oesign PROPERTY RUNTIME_OUTPUT_DIRECTORY ${OE_BINDIR}) + +# install rule +install (TARGETS oesign DESTINATION ${CMAKE_INSTALL_BINDIR}) +