You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

141 lines
3.3 KiB

  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 /usr/local/softs)
  12. # --- Configuration ---
  13. # Arch settings
  14. if(CMAKE_C_COMPILER_ID MATCHES "Clang")
  15. set(CLANG 1)
  16. endif()
  17. if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  18. set(CMAKE_C_COMPILER /usr/bin/cc CACHE PATH "" FORCE)
  19. set(CMAKE_CXX_COMPILER /usr/bin/c++ CACHE PATH "" FORCE)
  20. set(OPTEE_ENG_LD_FLAGS "-Wl")
  21. else()
  22. set(OPTEE_ENG_LD_FLAGS "-W")
  23. endif()
  24. # Build OpenSSL if not provided, otherwise define
  25. # OpenSSL_ssl_shared and OpenSSL_crypto_shared
  26. if (BUILD_OPENSSL)
  27. add_subdirectory(3rd/openssl-cmake)
  28. else()
  29. if (NOT OPENSSL_INSTALL_DIR)
  30. message(FATAL_ERROR "Must specify -DOPENSSL_INSTALL_DIR")
  31. endif()
  32. set(OPENSSL_BUILD_INSTALL_ROOT ${OPENSSL_INSTALL_DIR})
  33. set(OPENSSL_PREFIX_OPENSSLDIR ${CMAKE_INSTALL_PREFIX}${OPTEE_ENGINE_INSTALL_DIR}/openssl)
  34. include(3rd/openssl-cmake/libdefs.cmake)
  35. endif()
  36. get_property(OPENSSL_INSTALL_DIR GLOBAL PROPERTY openssl_build_install_dir_property)
  37. set(OPENSSL_INCLUDE_DIR ${OPENSSL_INSTALL_DIR}/include)
  38. # Trusted Application sources
  39. set(TA_DELEGATOR_ROOT ${CMAKE_SOURCE_DIR}/src/ta)
  40. # Build gtest
  41. add_subdirectory(3rd/gtest)
  42. # Global configuration
  43. set(C_CXX_FLAGS "\
  44. -Wno-ignored-qualifiers \
  45. -Wpedantic \
  46. -Wall \
  47. -Werror \
  48. -Wshadow \
  49. -Wno-variadic-macros \
  50. -Wundef \
  51. -Wunused-result")
  52. if(CLANG)
  53. set(C_CXX_FLAGS
  54. "-Wconditional-uninitialized \
  55. -Wmissing-variable-declarations")
  56. endif()
  57. # Control Debug/Release mode
  58. IF(${CMAKE_BUILD_TYPE} MATCHES "Debug")
  59. set(C_CXX_FLAGS "${C_CXX_FLAGS} -g3 -O0 -Wno-unused")
  60. else()
  61. set(C_CXX_FLAGS "${C_CXX_FLAGS} -O3")
  62. endif()
  63. # Add possibility to build Client Application with ASAN
  64. if(ASAN)
  65. set(CLANG 1)
  66. set(C_CXX_FLAGS "${C_CXX_FLAGS} -fsanitize=undefined,address,leak -fno-omit-frame-pointer")
  67. set(LDFLAGS "${LDFLAGS} -fsanitize=undefined,address,leak")
  68. endif()
  69. set(CMAKE_C_FLAGS ${C_CXX_FLAGS})
  70. set(CMAKE_CXX_FLAGS ${C_CXX_FLAGS})
  71. if(CLANG)
  72. if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang" OR NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  73. message(FATAL_ERROR "Clang required for this build")
  74. endif()
  75. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wnewline-eof -fcolor-diagnostics")
  76. endif()
  77. # --- Build targets ---
  78. # lang specific settings
  79. set(CMAKE_C_FLAGS
  80. "${CMAKE_C_FLAGS} \
  81. -std=gnu99 \
  82. -Werror=implicit-function-declaration \
  83. -Wmissing-prototypes \
  84. -Wstrict-prototypes")
  85. # optee_eng
  86. set(OPTEE_ENGINE_SRC
  87. src/optee_engine/back.c
  88. src/optee_engine/front.c
  89. src/optee_engine/log.c
  90. )
  91. add_library(
  92. optee_eng SHARED
  93. ${OPTEE_ENGINE_SRC}
  94. )
  95. target_include_directories(
  96. optee_eng PRIVATE
  97. ${OPENSSL_INCLUDE_DIR}
  98. ${OPTEE_REE_INCLUDE_DIR}
  99. src
  100. )
  101. target_include_directories(
  102. optee_eng PUBLIC
  103. inc
  104. ${OPENSSL_INCLUDE_DIR}
  105. ${TA_DELEGATOR_ROOT}/include
  106. )
  107. target_link_directories(
  108. optee_eng PRIVATE
  109. ${OPTEE_REE_LIB_DIR})
  110. target_link_libraries(
  111. optee_eng
  112. OpenSSL_crypto_shared
  113. ${CMAKE_DL_LIBS})
  114. IF(${CMAKE_BUILD_TYPE} MATCHES "Debug")
  115. target_compile_definitions(optee_eng PRIVATE BUILD_DEBUG)
  116. endif()