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.
 
 
 
 
 
 

142 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. find_package(OpenSSL)
  37. get_property(OPENSSL_INSTALL_DIR GLOBAL PROPERTY openssl_build_install_dir_property)
  38. set(OPENSSL_INCLUDE_DIR ${OPENSSL_INSTALL_DIR}/include)
  39. # Trusted Application sources
  40. set(TA_DELEGATOR_ROOT ${CMAKE_SOURCE_DIR}/src/ta)
  41. # Build gtest
  42. add_subdirectory(3rd/gtest)
  43. # Global configuration
  44. set(C_CXX_FLAGS "\
  45. -Wno-ignored-qualifiers \
  46. -Wpedantic \
  47. -Wall \
  48. -Werror \
  49. -Wshadow \
  50. -Wno-variadic-macros \
  51. -Wundef \
  52. -Wunused-result")
  53. if(CLANG)
  54. set(C_CXX_FLAGS
  55. "-Wconditional-uninitialized \
  56. -Wmissing-variable-declarations")
  57. endif()
  58. # Control Debug/Release mode
  59. IF(${CMAKE_BUILD_TYPE} MATCHES "Debug")
  60. set(C_CXX_FLAGS "${C_CXX_FLAGS} -g3 -O0 -Wno-unused")
  61. else()
  62. set(C_CXX_FLAGS "${C_CXX_FLAGS} -O3")
  63. endif()
  64. # Add possibility to build Client Application with ASAN
  65. if(ASAN)
  66. set(CLANG 1)
  67. set(C_CXX_FLAGS "${C_CXX_FLAGS} -fsanitize=undefined,address,leak -fno-omit-frame-pointer")
  68. set(LDFLAGS "${LDFLAGS} -fsanitize=undefined,address,leak")
  69. endif()
  70. set(CMAKE_C_FLAGS ${C_CXX_FLAGS})
  71. set(CMAKE_CXX_FLAGS ${C_CXX_FLAGS})
  72. if(CLANG)
  73. if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang" OR NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  74. message(FATAL_ERROR "Clang required for this build")
  75. endif()
  76. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wnewline-eof -fcolor-diagnostics")
  77. endif()
  78. # --- Build targets ---
  79. # lang specific settings
  80. set(CMAKE_C_FLAGS
  81. "${CMAKE_C_FLAGS} \
  82. -std=gnu99 \
  83. -Werror=implicit-function-declaration \
  84. -Wmissing-prototypes \
  85. -Wstrict-prototypes")
  86. # optee_eng
  87. set(OPTEE_ENGINE_SRC
  88. src/optee_engine/back.c
  89. src/optee_engine/front.c
  90. src/optee_engine/log.c
  91. )
  92. add_library(
  93. optee_eng SHARED
  94. ${OPTEE_ENGINE_SRC}
  95. )
  96. target_include_directories(
  97. optee_eng PRIVATE
  98. ${OPENSSL_INCLUDE_DIR}
  99. ${OPTEE_REE_INCLUDE_DIR}
  100. src
  101. )
  102. target_include_directories(
  103. optee_eng PUBLIC
  104. inc
  105. ${OPENSSL_INCLUDE_DIR}
  106. ${TA_DELEGATOR_ROOT}/include
  107. )
  108. target_link_directories(
  109. optee_eng PRIVATE
  110. ${OPTEE_REE_LIB_DIR})
  111. target_link_libraries(
  112. optee_eng
  113. crypto
  114. ${CMAKE_DL_LIBS})
  115. IF(${CMAKE_BUILD_TYPE} MATCHES "Debug")
  116. target_compile_definitions(optee_eng PRIVATE BUILD_DEBUG)
  117. endif()