| Ronald Cron | d3b33a2 | 2024-10-19 14:27:48 +0200 | [diff] [blame^] | 1 | # |
| 2 | # CMake build system design considerations: |
| 3 | # |
| 4 | # - Include directories: |
| 5 | # + Do not define include directories globally using the include_directories |
| 6 | # command but rather at the target level using the |
| 7 | # target_include_directories command. That way, it is easier to guarantee |
| 8 | # that targets are built using the proper list of include directories. |
| 9 | # + Use the PUBLIC and PRIVATE keywords to specify the scope of include |
| 10 | # directories. That way, a target linking to a library (using the |
| 11 | # target_link_libraries command) inherits from the library PUBLIC include |
| 12 | # directories and not from the PRIVATE ones. |
| 13 | # - TF_PSA_CRYPTO_TARGET_PREFIX: CMake targets are designed to be alterable by |
| 14 | # calling CMake in order to avoid target name clashes, via the use of |
| 15 | # TF_PSA_CRYPTO_TARGET_PREFIX. The value of this variable is prefixed to the |
| 16 | # tfpsacrypto and tfpsacrypto-apidoc targets. |
| 17 | # |
| 18 | |
| 19 | # We specify a minimum requirement of 3.10.2, but for now use 3.5.1 here |
| 20 | # until our infrastructure catches up. |
| 21 | cmake_minimum_required(VERSION 3.5.1) |
| 22 | |
| Ronald Cron | f85882d | 2024-10-11 19:56:38 +0200 | [diff] [blame] | 23 | include(CMakePackageConfigHelpers) |
| Ronald Cron | d3b33a2 | 2024-10-19 14:27:48 +0200 | [diff] [blame^] | 24 | |
| 25 | # Include convenience functions for printing properties and variables, like |
| 26 | # cmake_print_properties(), cmake_print_variables(). |
| 27 | include(CMakePrintHelpers) |
| 28 | |
| 29 | # https://cmake.org/cmake/help/latest/policy/CMP0011.html |
| 30 | # Setting this policy is required in CMake >= 3.18.0, otherwise a warning is generated. The OLD |
| 31 | # policy setting is deprecated, and will be removed in future versions. |
| 32 | cmake_policy(SET CMP0011 NEW) |
| 33 | # https://cmake.org/cmake/help/latest/policy/CMP0012.html |
| 34 | # Setting the CMP0012 policy to NEW is required for FindPython3 to work with CMake 3.18.2 |
| 35 | # (there is a bug in this particular version), otherwise, setting the CMP0012 policy is required |
| 36 | # for CMake versions >= 3.18.3 otherwise a deprecated warning is generated. The OLD policy setting |
| 37 | # is deprecated and will be removed in future versions. |
| 38 | cmake_policy(SET CMP0012 NEW) |
| 39 | |
| 40 | set(TF_PSA_CRYPTO_VERSION 0.1.0) |
| 41 | set(TF_PSA_CRYPTO_SOVERSION 0) |
| 42 | |
| 43 | if(TEST_CPP) |
| 44 | project("TF-PSA-Crypto" |
| 45 | LANGUAGES C CXX |
| 46 | VERSION ${TF_PSA_CRYPTO_VERSION} |
| 47 | ) |
| 48 | else() |
| 49 | project("TF-PSA-Crypto" |
| 50 | LANGUAGES C |
| 51 | VERSION ${TF_PSA_CRYPTO_VERSION} |
| 52 | ) |
| 53 | endif() |
| 54 | |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 55 | include(GNUInstallDirs) |
| 56 | |
| Ronald Cron | 9c84726 | 2024-07-20 14:56:49 +0200 | [diff] [blame] | 57 | # Determine if TF-PSA-Crypto is being built as a subproject using add_subdirectory() |
| 58 | if(NOT DEFINED TF_PSA_CRYPTO_AS_SUBPROJECT) |
| 59 | set(TF_PSA_CRYPTO_AS_SUBPROJECT ON) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 60 | if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) |
| Ronald Cron | 9c84726 | 2024-07-20 14:56:49 +0200 | [diff] [blame] | 61 | set(TF_PSA_CRYPTO_AS_SUBPROJECT OFF) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 62 | endif() |
| 63 | endif() |
| 64 | |
| Ronald Cron | 9c84726 | 2024-07-20 14:56:49 +0200 | [diff] [blame] | 65 | # Set the project, Mbed TLS and framework root directory. |
| 66 | set(TF_PSA_CRYPTO_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 67 | set(MBEDTLS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..) |
| 68 | set(MBEDTLS_FRAMEWORK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../framework) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 69 | |
| Ronald Cron | b58c225 | 2024-10-04 17:19:50 +0200 | [diff] [blame] | 70 | # Put the version numbers into relevant files |
| 71 | set(version_number_files |
| 72 | doxygen/input/doc_mainpage.h |
| 73 | doxygen/tfpsacrypto.doxyfile) |
| 74 | foreach(file ${version_number_files}) |
| 75 | configure_file(${file}.in |
| 76 | ${TF_PSA_CRYPTO_DIR}/${file}) |
| 77 | endforeach(file) |
| 78 | |
| Ronald Cron | a9219ff | 2024-10-23 09:23:46 +0200 | [diff] [blame] | 79 | ADD_CUSTOM_TARGET(${TF_PSA_CRYPTO_TARGET_PREFIX}tfpsacrypto-apidoc |
| Ronald Cron | b58c225 | 2024-10-04 17:19:50 +0200 | [diff] [blame] | 80 | COMMAND doxygen tfpsacrypto.doxyfile |
| 81 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doxygen) |
| 82 | |
| Ronald Cron | 9c84726 | 2024-07-20 14:56:49 +0200 | [diff] [blame] | 83 | option(ENABLE_PROGRAMS "Build TF-PSA-Crypto programs." ON) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 84 | |
| Ronald Cron | 9c84726 | 2024-07-20 14:56:49 +0200 | [diff] [blame] | 85 | option(TF_PSA_CRYPTO_FATAL_WARNINGS "Compiler warnings treated as errors" ON) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 86 | if(CMAKE_HOST_WIN32) |
| 87 | # N.B. The comment on the next line is significant! If you change it, |
| 88 | # edit the sed command in prepare_release.sh that modifies |
| 89 | # CMakeLists.txt. |
| 90 | option(GEN_FILES "Generate the auto-generated files as needed" OFF) # off in development |
| 91 | else() |
| 92 | option(GEN_FILES "Generate the auto-generated files as needed" ON) |
| 93 | endif() |
| 94 | |
| Ronald Cron | 4c3fa0a | 2024-07-30 10:50:39 +0200 | [diff] [blame] | 95 | # Support for package config and install to be added later. |
| Ronald Cron | f85882d | 2024-10-11 19:56:38 +0200 | [diff] [blame] | 96 | option(DISABLE_PACKAGE_CONFIG_AND_INSTALL "Disable package configuration, target export and installation" ${TF_PSA_CRYPTO_AS_SUBPROJECT}) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 97 | |
| 98 | if (CMAKE_C_SIMULATE_ID) |
| 99 | set(COMPILER_ID ${CMAKE_C_SIMULATE_ID}) |
| 100 | else() |
| 101 | set(COMPILER_ID ${CMAKE_C_COMPILER_ID}) |
| 102 | endif(CMAKE_C_SIMULATE_ID) |
| 103 | |
| 104 | string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${COMPILER_ID}") |
| 105 | string(REGEX MATCH "GNU" CMAKE_COMPILER_IS_GNU "${COMPILER_ID}") |
| 106 | string(REGEX MATCH "IAR" CMAKE_COMPILER_IS_IAR "${COMPILER_ID}") |
| 107 | string(REGEX MATCH "MSVC" CMAKE_COMPILER_IS_MSVC "${COMPILER_ID}") |
| 108 | |
| 109 | # the test suites currently have compile errors with MSVC |
| 110 | if(CMAKE_COMPILER_IS_MSVC) |
| Ronald Cron | 9c84726 | 2024-07-20 14:56:49 +0200 | [diff] [blame] | 111 | option(ENABLE_TESTING "Build TF-PSA-Crypto tests." OFF) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 112 | else() |
| Ronald Cron | 9c84726 | 2024-07-20 14:56:49 +0200 | [diff] [blame] | 113 | option(ENABLE_TESTING "Build TF-PSA-Crypto tests." ON) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 114 | endif() |
| 115 | |
| Ronald Cron | 9c84726 | 2024-07-20 14:56:49 +0200 | [diff] [blame] | 116 | option(USE_STATIC_TF_PSA_CRYPTO_LIBRARY "Build TF-PSA-Crypto static library." ON) |
| 117 | option(USE_SHARED_TF_PSA_CRYPTO_LIBRARY "Build TF-PSA-Crypto shared library." OFF) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 118 | option(LINK_WITH_PTHREAD "Explicitly link Mbed TLS library to pthread." OFF) |
| 119 | option(LINK_WITH_TRUSTED_STORAGE "Explicitly link Mbed TLS library to trusted_storage." OFF) |
| 120 | |
| Ronald Cron | 9c84726 | 2024-07-20 14:56:49 +0200 | [diff] [blame] | 121 | set(mbedcrypto_target "${TF_PSA_CRYPTO_TARGET_PREFIX}mbedcrypto") |
| 122 | if (USE_STATIC_TF_PSA_CRYPTO_LIBRARY) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 123 | set(mbedcrypto_static_target ${mbedcrypto_target}) |
| 124 | endif() |
| Ronald Cron | 9c84726 | 2024-07-20 14:56:49 +0200 | [diff] [blame] | 125 | if(USE_STATIC_TF_PSA_CRYPTO_LIBRARY AND USE_SHARED_TF_PSA_CRYPTO_LIBRARY) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 126 | string(APPEND mbedcrypto_static_target "_static") |
| 127 | endif() |
| 128 | |
| 129 | # Warning string - created as a list for compatibility with CMake 2.8 |
| 130 | set(CTR_DRBG_128_BIT_KEY_WARN_L1 "**** WARNING! MBEDTLS_CTR_DRBG_USE_128_BIT_KEY defined!\n") |
| 131 | set(CTR_DRBG_128_BIT_KEY_WARN_L2 "**** Using 128-bit keys for CTR_DRBG limits the security of generated\n") |
| 132 | set(CTR_DRBG_128_BIT_KEY_WARN_L3 "**** keys and operations that use random values generated to 128-bit security\n") |
| 133 | |
| 134 | set(CTR_DRBG_128_BIT_KEY_WARNING "${WARNING_BORDER}" |
| 135 | "${CTR_DRBG_128_BIT_KEY_WARN_L1}" |
| 136 | "${CTR_DRBG_128_BIT_KEY_WARN_L2}" |
| 137 | "${CTR_DRBG_128_BIT_KEY_WARN_L3}" |
| 138 | "${WARNING_BORDER}") |
| 139 | |
| 140 | # Python 3 is only needed here to check for configuration warnings. |
| 141 | if(NOT CMAKE_VERSION VERSION_LESS 3.15.0) |
| 142 | set(Python3_FIND_STRATEGY LOCATION) |
| 143 | find_package(Python3 COMPONENTS Interpreter) |
| 144 | if(Python3_Interpreter_FOUND) |
| Ronald Cron | 9c84726 | 2024-07-20 14:56:49 +0200 | [diff] [blame] | 145 | set(TF_PSA_CRYPTO_PYTHON_EXECUTABLE ${Python3_EXECUTABLE}) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 146 | endif() |
| 147 | else() |
| 148 | find_package(PythonInterp 3) |
| 149 | if(PYTHONINTERP_FOUND) |
| Ronald Cron | 9c84726 | 2024-07-20 14:56:49 +0200 | [diff] [blame] | 150 | set(TF_PSA_CRYPTO_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 151 | endif() |
| 152 | endif() |
| Ronald Cron | 9c84726 | 2024-07-20 14:56:49 +0200 | [diff] [blame] | 153 | if(TF_PSA_CRYPTO_PYTHON_EXECUTABLE) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 154 | |
| 155 | # If 128-bit keys are configured for CTR_DRBG, display an appropriate warning |
| Ronald Cron | e9e7b76 | 2024-07-20 15:28:39 +0200 | [diff] [blame] | 156 | execute_process(COMMAND ${TF_PSA_CRYPTO_PYTHON_EXECUTABLE} ${MBEDTLS_DIR}/scripts/config.py -f ${MBEDTLS_DIR}/include/mbedtls/mbedtls_config.h get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 157 | RESULT_VARIABLE result) |
| 158 | if(${result} EQUAL 0) |
| 159 | message(WARNING ${CTR_DRBG_128_BIT_KEY_WARNING}) |
| 160 | endif() |
| 161 | |
| 162 | endif() |
| 163 | |
| 164 | # We now potentially need to link all executables against PThreads, if available |
| 165 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE) |
| 166 | set(THREADS_PREFER_PTHREAD_FLAG TRUE) |
| 167 | find_package(Threads) |
| 168 | |
| 169 | # If this is the root project add longer list of available CMAKE_BUILD_TYPE values |
| Ronald Cron | f584e97 | 2024-10-07 11:38:17 +0200 | [diff] [blame] | 170 | if(NOT TF_PSA_CRYPTO_AS_SUBPROJECT) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 171 | set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} |
| 172 | CACHE STRING "Choose the type of build: None Debug Release Coverage ASan ASanDbg MemSan MemSanDbg Check CheckFull TSan TSanDbg" |
| 173 | FORCE) |
| 174 | endif() |
| 175 | |
| Ronald Cron | 9c84726 | 2024-07-20 14:56:49 +0200 | [diff] [blame] | 176 | # Make TF_PSA_CRYPTO_CONFIG_FILE and TF_PSA_CRYPTO_USER_CONFIG_FILE into PATHs |
| 177 | set(TF_PSA_CRYPTO_CONFIG_FILE "" CACHE FILEPATH "TF-PSA-Crypto config file (overrides default).") |
| 178 | set(TF_PSA_CRYPTO_USER_CONFIG_FILE "" CACHE FILEPATH "TF-PSA-Crypto user config file (appended to default).") |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 179 | |
| 180 | # Create a symbolic link from ${base_name} in the binary directory |
| 181 | # to the corresponding path in the source directory. |
| 182 | # Note: Copies the file(s) on Windows. |
| 183 | function(link_to_source base_name) |
| 184 | set(link "${CMAKE_CURRENT_BINARY_DIR}/${base_name}") |
| 185 | set(target "${CMAKE_CURRENT_SOURCE_DIR}/${base_name}") |
| 186 | |
| 187 | # Linking to non-existent file is not desirable. At best you will have a |
| 188 | # dangling link, but when building in tree, this can create a symbolic link |
| 189 | # to itself. |
| 190 | if (EXISTS ${target} AND NOT EXISTS ${link}) |
| 191 | if (CMAKE_HOST_UNIX) |
| 192 | execute_process(COMMAND ln -s ${target} ${link} |
| 193 | RESULT_VARIABLE result |
| 194 | ERROR_VARIABLE output) |
| 195 | |
| 196 | if (NOT ${result} EQUAL 0) |
| 197 | message(FATAL_ERROR "Could not create symbolic link for: ${target} --> ${output}") |
| 198 | endif() |
| 199 | else() |
| 200 | if (IS_DIRECTORY ${target}) |
| 201 | file(GLOB_RECURSE files FOLLOW_SYMLINKS LIST_DIRECTORIES false RELATIVE ${target} "${target}/*") |
| 202 | foreach(file IN LISTS files) |
| 203 | configure_file("${target}/${file}" "${link}/${file}" COPYONLY) |
| 204 | endforeach(file) |
| 205 | else() |
| 206 | configure_file(${target} ${link} COPYONLY) |
| 207 | endif() |
| 208 | endif() |
| 209 | endif() |
| 210 | endfunction(link_to_source) |
| 211 | |
| 212 | # Get the filename without the final extension (i.e. convert "a.b.c" to "a.b") |
| 213 | function(get_name_without_last_ext dest_var full_name) |
| 214 | # Split into a list on '.' (but a cmake list is just a ';'-separated string) |
| 215 | string(REPLACE "." ";" ext_parts "${full_name}") |
| 216 | # Remove the last item if there are more than one |
| 217 | list(LENGTH ext_parts ext_parts_len) |
| 218 | if (${ext_parts_len} GREATER "1") |
| 219 | math(EXPR ext_parts_last_item "${ext_parts_len} - 1") |
| 220 | list(REMOVE_AT ext_parts ${ext_parts_last_item}) |
| 221 | endif() |
| 222 | # Convert back to a string by replacing separators with '.' |
| 223 | string(REPLACE ";" "." no_ext_name "${ext_parts}") |
| 224 | # Copy into the desired variable |
| 225 | set(${dest_var} ${no_ext_name} PARENT_SCOPE) |
| 226 | endfunction(get_name_without_last_ext) |
| 227 | |
| 228 | include(CheckCCompilerFlag) |
| 229 | |
| 230 | set(CMAKE_C_EXTENSIONS OFF) |
| 231 | set(CMAKE_C_STANDARD 99) |
| 232 | |
| Ronald Cron | b247898 | 2024-10-07 16:17:07 +0200 | [diff] [blame] | 233 | function(set_base_compile_options target) |
| 234 | if(CMAKE_COMPILER_IS_GNU) |
| 235 | set_gnu_base_compile_options(${target}) |
| Ronald Cron | d9e1109 | 2024-10-09 10:01:46 +0200 | [diff] [blame] | 236 | elseif(CMAKE_COMPILER_IS_CLANG) |
| 237 | set_clang_base_compile_options(${target}) |
| Ronald Cron | 6f9d508 | 2024-10-09 14:54:43 +0200 | [diff] [blame] | 238 | elseif(CMAKE_COMPILER_IS_IAR) |
| 239 | set_iar_base_compile_options(${target}) |
| 240 | elseif(CMAKE_COMPILER_IS_MSVC) |
| 241 | set_msvc_base_compile_options(${target}) |
| Ronald Cron | b247898 | 2024-10-07 16:17:07 +0200 | [diff] [blame] | 242 | endif() |
| 243 | endfunction(set_base_compile_options) |
| 244 | |
| 245 | function(set_gnu_base_compile_options target) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 246 | # some warnings we want are not available with old GCC versions |
| 247 | # note: starting with CMake 2.8 we could use CMAKE_C_COMPILER_VERSION |
| 248 | execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion |
| 249 | OUTPUT_VARIABLE GCC_VERSION) |
| Ronald Cron | b247898 | 2024-10-07 16:17:07 +0200 | [diff] [blame] | 250 | target_compile_options(${target} PRIVATE -Wall -Wextra -Wwrite-strings -Wmissing-prototypes) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 251 | if (GCC_VERSION VERSION_GREATER 3.0 OR GCC_VERSION VERSION_EQUAL 3.0) |
| Ronald Cron | b247898 | 2024-10-07 16:17:07 +0200 | [diff] [blame] | 252 | target_compile_options(${target} PRIVATE -Wformat=2 -Wno-format-nonliteral) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 253 | endif() |
| 254 | if (GCC_VERSION VERSION_GREATER 4.3 OR GCC_VERSION VERSION_EQUAL 4.3) |
| Ronald Cron | b247898 | 2024-10-07 16:17:07 +0200 | [diff] [blame] | 255 | target_compile_options(${target} PRIVATE -Wvla) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 256 | endif() |
| 257 | if (GCC_VERSION VERSION_GREATER 4.5 OR GCC_VERSION VERSION_EQUAL 4.5) |
| Ronald Cron | b247898 | 2024-10-07 16:17:07 +0200 | [diff] [blame] | 258 | target_compile_options(${target} PRIVATE -Wlogical-op) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 259 | endif() |
| 260 | if (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8) |
| Ronald Cron | b247898 | 2024-10-07 16:17:07 +0200 | [diff] [blame] | 261 | target_compile_options(${target} PRIVATE -Wshadow) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 262 | endif() |
| 263 | if (GCC_VERSION VERSION_GREATER 5.0) |
| 264 | CHECK_C_COMPILER_FLAG("-Wformat-signedness" C_COMPILER_SUPPORTS_WFORMAT_SIGNEDNESS) |
| 265 | if(C_COMPILER_SUPPORTS_WFORMAT_SIGNEDNESS) |
| Ronald Cron | b247898 | 2024-10-07 16:17:07 +0200 | [diff] [blame] | 266 | target_compile_options(${target} PRIVATE -Wformat-signedness) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 267 | endif() |
| 268 | endif() |
| 269 | if (GCC_VERSION VERSION_GREATER 7.0 OR GCC_VERSION VERSION_EQUAL 7.0) |
| Ronald Cron | b247898 | 2024-10-07 16:17:07 +0200 | [diff] [blame] | 270 | target_compile_options(${target} PRIVATE -Wformat-overflow=2 -Wformat-truncation) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 271 | endif() |
| Ronald Cron | b247898 | 2024-10-07 16:17:07 +0200 | [diff] [blame] | 272 | target_compile_options(${target} PRIVATE $<$<CONFIG:Release>:-O2>) |
| 273 | target_compile_options(${target} PRIVATE $<$<CONFIG:Debug>:-O0 -g3>) |
| 274 | target_compile_options(${target} PRIVATE $<$<CONFIG:Coverage>:-O0 -g3 --coverage>) |
| Ronald Cron | 4ae24f4 | 2024-10-08 17:53:13 +0200 | [diff] [blame] | 275 | set_target_properties(${target} PROPERTIES LINK_FLAGS_COVERAGE "--coverage") |
| Ronald Cron | b247898 | 2024-10-07 16:17:07 +0200 | [diff] [blame] | 276 | # Old GCC versions hit a performance problem with test_suite_pkwrite |
| 277 | # "Private keey write check EC" tests when building with Asan+UBSan |
| 278 | # and -O3: those tests take more than 100x time than normal, with |
| 279 | # test_suite_pkwrite taking >3h on the CI. Observed with GCC 5.4 on |
| 280 | # Ubuntu 16.04 x86_64 and GCC 6.5 on Ubuntu 18.04 x86_64. |
| 281 | # GCC 7.5 and above on Ubuntu 18.04 appear fine. |
| 282 | # To avoid the performance problem, we use -O2 when GCC version is lower than 7.0. |
| 283 | # It doesn't slow down much even with modern compiler versions. |
| 284 | target_compile_options(${target} PRIVATE $<$<CONFIG:ASan>:-fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all>) |
| 285 | if (GCC_VERSION VERSION_LESS 7.0) |
| 286 | target_compile_options(${target} PRIVATE $<$<CONFIG:ASan>:-O2>) |
| 287 | else() |
| 288 | target_compile_options(${target} PRIVATE $<$<CONFIG:ASan>:-O3>) |
| 289 | endif() |
| Ronald Cron | 4ae24f4 | 2024-10-08 17:53:13 +0200 | [diff] [blame] | 290 | set_target_properties(${target} PROPERTIES LINK_FLAGS_ASAN "-fsanitize=address -fsanitize=undefined") |
| Ronald Cron | b247898 | 2024-10-07 16:17:07 +0200 | [diff] [blame] | 291 | target_compile_options(${target} PRIVATE $<$<CONFIG:ASanDbg>:-fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls>) |
| Ronald Cron | 4ae24f4 | 2024-10-08 17:53:13 +0200 | [diff] [blame] | 292 | set_target_properties(${target} PROPERTIES LINK_FLAGS_ASANDBG "-fsanitize=address -fsanitize=undefined") |
| Ronald Cron | b247898 | 2024-10-07 16:17:07 +0200 | [diff] [blame] | 293 | target_compile_options(${target} PRIVATE $<$<CONFIG:TSan>:-fsanitize=thread -O3>) |
| Ronald Cron | 4ae24f4 | 2024-10-08 17:53:13 +0200 | [diff] [blame] | 294 | set_target_properties(${target} PROPERTIES LINK_FLAGS_TSAN "-fsanitize=thread") |
| Ronald Cron | b247898 | 2024-10-07 16:17:07 +0200 | [diff] [blame] | 295 | target_compile_options(${target} PRIVATE $<$<CONFIG:TSanDbg>:-fsanitize=thread -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls>) |
| Ronald Cron | 4ae24f4 | 2024-10-08 17:53:13 +0200 | [diff] [blame] | 296 | set_target_properties(${target} PROPERTIES LINK_FLAGS_TSANDBG "-fsanitize=thread") |
| Ronald Cron | b247898 | 2024-10-07 16:17:07 +0200 | [diff] [blame] | 297 | target_compile_options(${target} PRIVATE $<$<CONFIG:Check>:-Os>) |
| 298 | target_compile_options(${target} PRIVATE $<$<CONFIG:CheckFull>:-Os -Wcast-qual>) |
| Ronald Cron | d77fad2 | 2024-10-08 09:24:31 +0200 | [diff] [blame] | 299 | |
| 300 | if(TF_PSA_CRYPTO_FATAL_WARNINGS) |
| Ronald Cron | b247898 | 2024-10-07 16:17:07 +0200 | [diff] [blame] | 301 | target_compile_options(${target} PRIVATE -Werror) |
| Ronald Cron | d77fad2 | 2024-10-08 09:24:31 +0200 | [diff] [blame] | 302 | endif(TF_PSA_CRYPTO_FATAL_WARNINGS) |
| Ronald Cron | b247898 | 2024-10-07 16:17:07 +0200 | [diff] [blame] | 303 | endfunction(set_gnu_base_compile_options) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 304 | |
| Ronald Cron | d9e1109 | 2024-10-09 10:01:46 +0200 | [diff] [blame] | 305 | function(set_clang_base_compile_options target) |
| 306 | target_compile_options(${target} PRIVATE -Wall -Wextra -Wwrite-strings -Wmissing-prototypes -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral) |
| 307 | target_compile_options(${target} PRIVATE $<$<CONFIG:Release>:-O2>) |
| 308 | target_compile_options(${target} PRIVATE $<$<CONFIG:Debug>:-O0 -g3>) |
| 309 | target_compile_options(${target} PRIVATE $<$<CONFIG:Coverage>:-O0 -g3 --coverage>) |
| 310 | set_target_properties(${target} PROPERTIES LINK_FLAGS_COVERAGE "--coverage") |
| 311 | target_compile_options(${target} PRIVATE $<$<CONFIG:ASan>:-fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O3>) |
| 312 | set_target_properties(${target} PROPERTIES LINK_FLAGS_ASAN "-fsanitize=address -fsanitize=undefined") |
| 313 | target_compile_options(${target} PRIVATE $<$<CONFIG:ASanDbg>:-fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls>) |
| 314 | set_target_properties(${target} PROPERTIES LINK_FLAGS_ASANDBG "-fsanitize=address -fsanitize=undefined") |
| 315 | target_compile_options(${target} PRIVATE $<$<CONFIG:MemSan>:-fsanitize=memory>) |
| 316 | set_target_properties(${target} PROPERTIES LINK_FLAGS_MEMSAN "-fsanitize=memory") |
| 317 | target_compile_options(${target} PRIVATE $<$<CONFIG:MemSanDbg>:-fsanitize=memory -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2>) |
| 318 | set_target_properties(${target} PROPERTIES LINK_FLAGS_MEMSANDBG "-fsanitize=memory") |
| 319 | target_compile_options(${target} PRIVATE $<$<CONFIG:TSan>:-fsanitize=thread -O3>) |
| 320 | set_target_properties(${target} PROPERTIES LINK_FLAGS_TSAN "-fsanitize=thread") |
| 321 | target_compile_options(${target} PRIVATE $<$<CONFIG:TSanDbg>:-fsanitize=thread -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls>) |
| 322 | set_target_properties(${target} PROPERTIES LINK_FLAGS_TSANDBG "-fsanitize=thread") |
| 323 | target_compile_options(${target} PRIVATE $<$<CONFIG:Check>:-Os>) |
| Ronald Cron | d77fad2 | 2024-10-08 09:24:31 +0200 | [diff] [blame] | 324 | |
| Ronald Cron | d9e1109 | 2024-10-09 10:01:46 +0200 | [diff] [blame] | 325 | if(MBEDTLS_FATAL_WARNINGS) |
| 326 | target_compile_options(${target} PRIVATE -Werror) |
| 327 | endif(MBEDTLS_FATAL_WARNINGS) |
| 328 | endfunction(set_clang_base_compile_options) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 329 | |
| Ronald Cron | 6f9d508 | 2024-10-09 14:54:43 +0200 | [diff] [blame] | 330 | function(set_iar_base_compile_options target) |
| 331 | target_compile_options(${target} PRIVATE --warn_about_c_style_casts) |
| 332 | target_compile_options(${target} PRIVATE $<$<CONFIG:Release>:-Ohz>) |
| 333 | target_compile_options(${target} PRIVATE $<$<CONFIG:Debug>:--debug -On>) |
| Ronald Cron | d77fad2 | 2024-10-08 09:24:31 +0200 | [diff] [blame] | 334 | |
| Ronald Cron | 6f9d508 | 2024-10-09 14:54:43 +0200 | [diff] [blame] | 335 | if(MBEDTLS_FATAL_WARNINGS) |
| 336 | target_compile_options(${target} PRIVATE --warnings_are_errors) |
| 337 | endif(MBEDTLS_FATAL_WARNINGS) |
| 338 | endfunction(set_iar_base_compile_options) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 339 | |
| Ronald Cron | 6f9d508 | 2024-10-09 14:54:43 +0200 | [diff] [blame] | 340 | function(set_msvc_base_compile_options target) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 341 | # Strictest warnings, UTF-8 source and execution charset |
| Ronald Cron | 6f9d508 | 2024-10-09 14:54:43 +0200 | [diff] [blame] | 342 | target_compile_options(${target} PRIVATE /W3 /utf-8) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 343 | |
| Ronald Cron | 6f9d508 | 2024-10-09 14:54:43 +0200 | [diff] [blame] | 344 | if(MBEDTLS_FATAL_WARNINGS) |
| 345 | target_compile_options(${target} PRIVATE /WX) |
| 346 | endif(MBEDTLS_FATAL_WARNINGS) |
| 347 | endfunction(set_msvc_base_compile_options) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 348 | |
| Ronald Cron | 211bf6d | 2024-10-23 14:22:03 +0200 | [diff] [blame] | 349 | function(set_config_files_compile_definitions target) |
| 350 | # Pass-through MBEDTLS_CONFIG_FILE, MBEDTLS_USER_CONFIG_FILE, |
| 351 | # MBEDTLS_PSA_CRYPTO_CONFIG_FILE and MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE |
| 352 | if(MBEDTLS_CONFIG_FILE) |
| 353 | target_compile_definitions(${target} |
| 354 | PUBLIC MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}") |
| 355 | endif() |
| 356 | if(MBEDTLS_USER_CONFIG_FILE) |
| 357 | target_compile_definitions(${target} |
| 358 | PUBLIC MBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}") |
| 359 | endif() |
| 360 | if(MBEDTLS_PSA_CRYPTO_CONFIG_FILE) |
| 361 | target_compile_definitions(${target} |
| 362 | PUBLIC MBEDTLS_PSA_CRYPTO_CONFIG_FILE="${MBEDTLS_PSA_CRYPTO_CONFIG_FILE}") |
| 363 | endif() |
| 364 | if(MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE) |
| 365 | target_compile_definitions(${target} |
| 366 | PUBLIC MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE="${MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE}") |
| 367 | endif() |
| 368 | endfunction(set_config_files_compile_definitions) |
| 369 | |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 370 | if(CMAKE_BUILD_TYPE STREQUAL "Check" AND TEST_CPP) |
| 371 | set(CMAKE_CXX_STANDARD 11) |
| 372 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 373 | set(CMAKE_CXX_EXTENSIONS OFF) |
| 374 | if(CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNU) |
| 375 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") |
| 376 | endif() |
| 377 | endif() |
| 378 | |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 379 | if (NOT EXISTS "${MBEDTLS_FRAMEWORK_DIR}/CMakeLists.txt") |
| 380 | message(FATAL_ERROR "${MBEDTLS_FRAMEWORK_DIR}/CMakeLists.txt not found. Run `git submodule update --init` from the source tree to fetch the submodule contents.") |
| 381 | endif() |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 382 | |
| 383 | add_subdirectory(include) |
| Ronald Cron | 31829a8 | 2024-07-29 19:06:40 +0200 | [diff] [blame] | 384 | add_subdirectory(core) |
| 385 | add_subdirectory(drivers) |
| Ronald Cron | f85882d | 2024-10-11 19:56:38 +0200 | [diff] [blame] | 386 | add_subdirectory(pkgconfig) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 387 | |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 388 | # |
| 389 | # The C files in tests/src directory contain test code shared among test suites |
| 390 | # and programs. This shared test code is compiled and linked to test suites and |
| 391 | # programs objects as a set of compiled objects. The compiled objects are NOT |
| 392 | # built into a library that the test suite and program objects would link |
| Ronald Cron | 9c84726 | 2024-07-20 14:56:49 +0200 | [diff] [blame] | 393 | # against as they link against the tfpsacrypto library. The reason is that such |
| Ronald Cron | 97d05e5 | 2024-07-20 15:02:50 +0200 | [diff] [blame] | 394 | # library is expected to have mutual dependencies with the aforementioned |
| 395 | # library and that there is as of today no portable way of handling such |
| 396 | # dependencies (only toolchain specific solutions). |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 397 | # |
| Ronald Cron | 2609fe9 | 2024-10-07 09:58:57 +0200 | [diff] [blame] | 398 | # Thus the below definition of the `tf_psa_crypto_test` CMake library of |
| 399 | # objects target. This library of objects is used by tests and programs CMake |
| 400 | # files to define the test executables. |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 401 | # |
| 402 | if(ENABLE_TESTING OR ENABLE_PROGRAMS) |
| 403 | file(GLOB MBEDTLS_TEST_FILES |
| Ronald Cron | e9e7b76 | 2024-07-20 15:28:39 +0200 | [diff] [blame] | 404 | ${MBEDTLS_DIR}/tests/src/*.c |
| 405 | ${MBEDTLS_DIR}/tests/src/drivers/*.c) |
| Ronald Cron | 2609fe9 | 2024-10-07 09:58:57 +0200 | [diff] [blame] | 406 | add_library(tf_psa_crypto_test OBJECT ${MBEDTLS_TEST_FILES}) |
| 407 | set_base_compile_options(tf_psa_crypto_test) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 408 | if(GEN_FILES) |
| 409 | add_custom_command( |
| 410 | OUTPUT |
| Ronald Cron | e9e7b76 | 2024-07-20 15:28:39 +0200 | [diff] [blame] | 411 | ${MBEDTLS_DIR}/tests/src/test_keys.h |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 412 | WORKING_DIRECTORY |
| Ronald Cron | e9e7b76 | 2024-07-20 15:28:39 +0200 | [diff] [blame] | 413 | ${MBEDTLS_DIR}/tests |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 414 | COMMAND |
| Ronald Cron | 9c84726 | 2024-07-20 14:56:49 +0200 | [diff] [blame] | 415 | "${TF_PSA_CRYPTO_PYTHON_EXECUTABLE}" |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 416 | "${MBEDTLS_FRAMEWORK_DIR}/scripts/generate_test_keys.py" |
| 417 | "--output" |
| Ronald Cron | e9e7b76 | 2024-07-20 15:28:39 +0200 | [diff] [blame] | 418 | "${MBEDTLS_DIR}/tests/src/test_keys.h" |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 419 | DEPENDS |
| 420 | ${MBEDTLS_FRAMEWORK_DIR}/scripts/generate_test_keys.py |
| 421 | ) |
| Ronald Cron | 2609fe9 | 2024-10-07 09:58:57 +0200 | [diff] [blame] | 422 | add_custom_target(tf_psa_crypto_test_keys_header DEPENDS ${MBEDTLS_DIR}/tests/src/test_keys.h) |
| Ronald Cron | 97d05e5 | 2024-07-20 15:02:50 +0200 | [diff] [blame] | 423 | |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 424 | add_custom_command( |
| 425 | OUTPUT |
| Ronald Cron | e9e7b76 | 2024-07-20 15:28:39 +0200 | [diff] [blame] | 426 | ${MBEDTLS_DIR}/tests/src/test_certs.h |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 427 | WORKING_DIRECTORY |
| Ronald Cron | e9e7b76 | 2024-07-20 15:28:39 +0200 | [diff] [blame] | 428 | ${MBEDTLS_DIR}/tests |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 429 | COMMAND |
| Ronald Cron | 9c84726 | 2024-07-20 14:56:49 +0200 | [diff] [blame] | 430 | "${TF_PSA_CRYPTO_PYTHON_EXECUTABLE}" |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 431 | "${MBEDTLS_FRAMEWORK_DIR}/scripts/generate_test_cert_macros.py" |
| 432 | "--output" |
| Ronald Cron | e9e7b76 | 2024-07-20 15:28:39 +0200 | [diff] [blame] | 433 | "${MBEDTLS_DIR}/tests/src/test_certs.h" |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 434 | DEPENDS |
| 435 | ${MBEDTLS_FRAMEWORK_DIR}/scripts/generate_test_cert_macros.py |
| 436 | ) |
| Ronald Cron | 2609fe9 | 2024-10-07 09:58:57 +0200 | [diff] [blame] | 437 | add_custom_target(tf_psa_crypto_test_certs_header DEPENDS ${MBEDTLS_DIR}/tests/src/test_certs.h) |
| 438 | add_dependencies(tf_psa_crypto_test tf_psa_crypto_test_keys_header tf_psa_crypto_test_certs_header) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 439 | endif() |
| Ronald Cron | 2609fe9 | 2024-10-07 09:58:57 +0200 | [diff] [blame] | 440 | target_include_directories(tf_psa_crypto_test |
| Ronald Cron | e9e7b76 | 2024-07-20 15:28:39 +0200 | [diff] [blame] | 441 | PRIVATE ${MBEDTLS_DIR}/tests/include |
| 442 | PRIVATE ${MBEDTLS_DIR}/include |
| 443 | PRIVATE include |
| 444 | PRIVATE drivers/builtin/include |
| 445 | PRIVATE core |
| 446 | PRIVATE drivers/builtin/src) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 447 | # Request C11, needed for memory poisoning tests |
| Ronald Cron | 2609fe9 | 2024-10-07 09:58:57 +0200 | [diff] [blame] | 448 | set_target_properties(tf_psa_crypto_test PROPERTIES C_STANDARD 11) |
| 449 | set_config_files_compile_definitions(tf_psa_crypto_test) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 450 | endif() |
| 451 | |
| 452 | if(ENABLE_PROGRAMS) |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 453 | add_subdirectory(programs) |
| 454 | endif() |
| 455 | |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 456 | if(ENABLE_TESTING) |
| 457 | enable_testing() |
| 458 | |
| 459 | add_subdirectory(tests) |
| 460 | |
| 461 | # additional convenience targets for Unix only |
| Ronald Cron | 169393e | 2024-10-07 12:34:42 +0200 | [diff] [blame] | 462 | if(UNIX AND (NOT TF_PSA_CRYPTO_AS_SUBPROJECT)) |
| Ronald Cron | d916cc9 | 2024-10-17 18:33:59 +0200 | [diff] [blame] | 463 | # For coverage testing: |
| 464 | # 1. Build with: |
| 465 | # cmake -D CMAKE_BUILD_TYPE=Coverage /path/to/source && make |
| 466 | # 2. Run the relevant tests for the part of the code you're interested in. |
| 467 | # For the reference coverage measurement, see |
| 468 | # tests/scripts/basic-build-test.sh |
| 469 | # 3. Run scripts/lcov.sh to generate an HTML report. |
| 470 | ADD_CUSTOM_TARGET(lcov |
| 471 | COMMAND ${MBEDTLS_DIR}/scripts/lcov.sh |
| 472 | ) |
| 473 | |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 474 | ADD_CUSTOM_TARGET(memcheck |
| 475 | COMMAND sed -i.bak s+/usr/bin/valgrind+`which valgrind`+ DartConfiguration.tcl |
| 476 | COMMAND ctest -O memcheck.log -D ExperimentalMemCheck |
| 477 | COMMAND tail -n1 memcheck.log | grep 'Memory checking results:' > /dev/null |
| 478 | COMMAND rm -f memcheck.log |
| 479 | COMMAND mv DartConfiguration.tcl.bak DartConfiguration.tcl |
| 480 | ) |
| Ronald Cron | 169393e | 2024-10-07 12:34:42 +0200 | [diff] [blame] | 481 | endif() |
| Ronald Cron | 701faac | 2024-07-20 14:43:53 +0200 | [diff] [blame] | 482 | |
| 483 | # Make scripts needed for testing available in an out-of-source build. |
| 484 | if (NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) |
| 485 | link_to_source(scripts) |
| 486 | # Copy (don't link) DartConfiguration.tcl, needed for memcheck, to |
| 487 | # keep things simple with the sed commands in the memcheck target. |
| 488 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/DartConfiguration.tcl |
| 489 | ${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl COPYONLY) |
| 490 | endif() |
| 491 | endif() |
| Ronald Cron | f85882d | 2024-10-11 19:56:38 +0200 | [diff] [blame] | 492 | |
| 493 | if(NOT DISABLE_PACKAGE_CONFIG_AND_INSTALL) |
| 494 | configure_package_config_file( |
| 495 | "cmake/TF-PSA-CryptoConfig.cmake.in" |
| 496 | "cmake/TF-PSA-CryptoConfig.cmake" |
| 497 | INSTALL_DESTINATION "cmake") |
| 498 | |
| 499 | write_basic_package_version_file( |
| 500 | "cmake/TF-PSA-CryptoConfigVersion.cmake" |
| 501 | COMPATIBILITY SameMajorVersion |
| 502 | VERSION 0.1.0) |
| 503 | |
| 504 | install( |
| 505 | FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/TF-PSA-CryptoConfig.cmake" |
| 506 | "${CMAKE_CURRENT_BINARY_DIR}/cmake/TF-PSA-CryptoConfigVersion.cmake" |
| 507 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/TF-PSA-Crypto") |
| 508 | |
| 509 | export( |
| Ronald Cron | ba850f3 | 2024-10-11 19:39:49 +0200 | [diff] [blame] | 510 | EXPORT TF-PSA-CryptoTargets |
| Ronald Cron | f85882d | 2024-10-11 19:56:38 +0200 | [diff] [blame] | 511 | NAMESPACE TF-PSA-Crypto:: |
| 512 | FILE "cmake/TF-PSA-CryptoTargets.cmake") |
| 513 | |
| 514 | install( |
| Ronald Cron | ba850f3 | 2024-10-11 19:39:49 +0200 | [diff] [blame] | 515 | EXPORT TF-PSA-CryptoTargets |
| Ronald Cron | f85882d | 2024-10-11 19:56:38 +0200 | [diff] [blame] | 516 | NAMESPACE TF-PSA-Crypto:: |
| 517 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/TF-PSA-Crypto" |
| 518 | FILE "TF-PSA-CryptoTargets.cmake") |
| 519 | |
| 520 | if(CMAKE_VERSION VERSION_GREATER 3.15 OR CMAKE_VERSION VERSION_EQUAL 3.15) |
| 521 | # Do not export the package by default |
| 522 | cmake_policy(SET CMP0090 NEW) |
| 523 | |
| 524 | # Make this package visible to the system |
| 525 | export(PACKAGE TF-PSA-Crypto) |
| 526 | endif() |
| 527 | endif() |