Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

CMakeLists.txt 6.0 KiB

3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. cmake_minimum_required(VERSION 3.13)
  2. project(optee_engine NONE)
  3. include(ExternalProject)
  4. enable_language(C)
  5. enable_language(CXX)
  6. set(CMAKE_VERBOSE_MAKEFILE ON)
  7. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "~/.cmake/Modules")
  8. set(CMAKE_CXX_STANDARD 11)
  9. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  10. set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
  11. set(OPTEE_ENGINE_INSTALL_DIR /opt)
  12. # OP-TEE
  13. if (NOT OPTEE_BUILD_DIR)
  14. message(FATAL_ERROR "Must specify -DOPTEE_BUILD_DIR")
  15. endif()
  16. if (NOT PLATFORM)
  17. message(FATAL_ERROR "Must specify -DPLATFORM=V where V is either qemu or hikey960")
  18. endif()
  19. set(OPTEE_ROOT_DIR ${OPTEE_BUILD_DIR})
  20. set(OPTEE_REE_LIB_DIR ${OPTEE_ROOT_DIR}/out-br/target/usr/lib)
  21. set(OPTEE_REE_INCLUDE_DIR ${OPTEE_ROOT_DIR}/optee_client/public)
  22. set(CMAKE_C_COMPILER ${OPTEE_ROOT_DIR}/toolchains/aarch64/bin/aarch64-linux-gnu-gcc CACHE PATH "" FORCE)
  23. set(CMAKE_CXX_COMPILER ${OPTEE_ROOT_DIR}/toolchains/aarch64/bin/aarch64-linux-gnu-g++ CACHE PATH "" FORCE)
  24. # 3rd Parties
  25. # OpenSSL config targets
  26. set(OPENSSL_CONFIG_CMD "Configure" CACHE STRING "Command used to configure OpenSSL (default ./config)")
  27. set(OPENSSL_CONFIG_TARGET "linux-aarch64" CACHE STRING "Platform for which OpenSSL should be compiled (default native)")
  28. add_subdirectory(3rd/openssl-cmake)
  29. # Gtest
  30. add_subdirectory(3rd/gtest)
  31. get_property(OPENSSL_INSTALL_DIR GLOBAL PROPERTY openssl_build_install_dir_property)
  32. set(OPENSSL_INCLUDE_DIR ${OPENSSL_INSTALL_DIR}/include)
  33. # Trusted Application sources
  34. set(TA_DELEGATOR_ROOT ${CMAKE_SOURCE_DIR}/src/ta)
  35. # Global configuration
  36. set(C_CXX_FLAGS "\
  37. -Wno-ignored-qualifiers \
  38. -Wpedantic \
  39. -Wall \
  40. -Werror \
  41. -Wshadow \
  42. -Wno-variadic-macros \
  43. -Wundef \
  44. -Wunused-result")
  45. # Control Debug/Release mode
  46. IF(${CMAKE_BUILD_TYPE} MATCHES "Debug")
  47. set(C_CXX_FLAGS "${C_CXX_FLAGS} -g3 -O0 -Wno-unused")
  48. else()
  49. set(C_CXX_FLAGS "${C_CXX_FLAGS} -O3")
  50. endif()
  51. set(CMAKE_C_FLAGS ${C_CXX_FLAGS})
  52. set(CMAKE_CXX_FLAGS ${C_CXX_FLAGS})
  53. # --- Build targets ---
  54. # lang specific settings
  55. set(CMAKE_C_FLAGS
  56. "${CMAKE_C_FLAGS} \
  57. -std=gnu99 \
  58. -Werror=implicit-function-declaration \
  59. -Wmissing-prototypes \
  60. -Wstrict-prototypes")
  61. # optee_eng
  62. set(OPTEE_ENGINE_SRC
  63. src/optee_engine/back.c
  64. src/optee_engine/front.c
  65. src/optee_engine/log.c
  66. )
  67. add_library(
  68. optee_eng SHARED
  69. ${OPTEE_ENGINE_SRC}
  70. )
  71. target_include_directories(
  72. optee_eng PRIVATE
  73. ${OPENSSL_INCLUDE_DIR}
  74. ${OPTEE_REE_INCLUDE_DIR}
  75. src
  76. )
  77. target_include_directories(
  78. optee_eng PUBLIC
  79. inc
  80. ${OPENSSL_INCLUDE_DIR}
  81. ${TA_DELEGATOR_ROOT}/include
  82. )
  83. target_link_directories(
  84. optee_eng PRIVATE
  85. ${OPTEE_REE_LIB_DIR})
  86. target_link_libraries(
  87. optee_eng
  88. OpenSSL_crypto_shared
  89. teec
  90. ${CMAKE_DL_LIBS})
  91. IF(${CMAKE_BUILD_TYPE} MATCHES "Debug")
  92. target_compile_definitions(optee_eng PRIVATE BUILD_DEBUG)
  93. endif()
  94. # Key management app
  95. add_executable(
  96. optee_keymgnt
  97. src/optee_engine/keymgnt.c
  98. )
  99. target_include_directories(
  100. optee_keymgnt PRIVATE
  101. ${OPENSSL_INCLUDE_DIR}
  102. ${OPTEE_REE_INCLUDE_DIR}
  103. ${TA_DELEGATOR_ROOT}/include)
  104. target_link_directories(
  105. optee_keymgnt PRIVATE
  106. ${OPTEE_REE_LIB_DIR})
  107. target_link_libraries(
  108. optee_keymgnt
  109. OpenSSL_crypto_shared
  110. teec
  111. ${OPTEE_ENG_LD_FLAGS}
  112. ${CMAKE_DL_LIBS})
  113. ExternalProject_Add(optee_eng_ta
  114. SOURCE_DIR ${TA_DELEGATOR_ROOT}
  115. CONFIGURE_COMMAND ""
  116. BUILD_COMMAND OPTEE_ROOT=${OPTEE_BUILD_DIR} O=${CMAKE_CURRENT_BINARY_DIR} ${MAKE_PROGRAM}
  117. BUILD_IN_SOURCE TRUE
  118. INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/ta
  119. INSTALL_COMMAND ""
  120. BUILD_ALWAYS TRUE
  121. )
  122. # Google benchmark settings
  123. set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
  124. # Target for benchmark - it also builds gtest library
  125. set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Enable testing of the benchmark library." FORCE)
  126. set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark tests" FORCE)
  127. set(GOOGLETEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/3rd/gtest" CACHE PATH "Path to the gtest sources" FORCE)
  128. set(BENCHMARK_OS_WINDOWS OFF CACHE BOOL "" FORCE)
  129. set(HAVE_POSIX_REGEX OFF CACHE BOOL "" FORCE)
  130. set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "" FORCE)
  131. set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
  132. add_subdirectory(3rd/gbench)
  133. add_executable(
  134. speed
  135. src/optee_engine/speed.cc)
  136. target_include_directories(
  137. speed PRIVATE
  138. ${OPENSSL_INCLUDE_DIR}
  139. )
  140. target_link_libraries(
  141. speed
  142. gtest
  143. pthread
  144. OpenSSL_crypto_shared
  145. benchmark::benchmark)
  146. # Install copies needed files to the buildroot overlay.
  147. # OpenVPN config
  148. install(FILES ${PROJECT_SOURCE_DIR}/cfg/openvpn_cli.conf
  149. DESTINATION ${OPTEE_ROOT_DIR}/build/br-ext/board/${PLATFORM}/overlay/etc/openvpn/
  150. RENAME client.conf)
  151. install(FILES
  152. ${PROJECT_SOURCE_DIR}/cfg/certs/ca.cert
  153. ${PROJECT_SOURCE_DIR}/cfg/certs/client.cert
  154. ${PROJECT_SOURCE_DIR}/cfg/certs/client.key
  155. DESTINATION ${OPTEE_ROOT_DIR}/build/br-ext/board/${PLATFORM}/overlay/etc/openvpn/certs/)
  156. # OpenSSL config
  157. install(FILES ${PROJECT_SOURCE_DIR}/cfg/openssl_optee.cnf
  158. DESTINATION ${OPTEE_ROOT_DIR}/build/br-ext/board/${PLATFORM}/overlay/etc/ssl/
  159. RENAME openssl.cnf)
  160. # OpTEE engine
  161. install(TARGETS optee_eng
  162. LIBRARY DESTINATION ${OPTEE_ROOT_DIR}/build/br-ext/board/${PLATFORM}/overlay/opt/
  163. PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
  164. # TA
  165. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/8aaaf200-2450-11e4-0060-0dc0ffee0000.ta
  166. DESTINATION ${OPTEE_ROOT_DIR}/build/br-ext/board/${PLATFORM}/overlay/lib/optee_armtz)
  167. # Must be empty and have same name as the TEE key ID
  168. install(FILES /dev/null
  169. DESTINATION ${OPTEE_ROOT_DIR}/build/br-ext/board/${PLATFORM}/overlay/etc/openvpn/
  170. RENAME vpn.testlab.com)
  171. # Key management app
  172. install(TARGETS optee_keymgnt
  173. RUNTIME DESTINATION ${OPTEE_ROOT_DIR}/build/br-ext/board/${PLATFORM}/overlay/usr/bin/
  174. PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ WORLD_READ)
  175. # Speed app
  176. install(TARGETS speed
  177. RUNTIME DESTINATION ${OPTEE_ROOT_DIR}/build/br-ext/board/${PLATFORM}/overlay/usr/bin/
  178. PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ WORLD_READ)