Ronald Cron | b1790af | 2020-05-20 15:34:47 +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. |
Shaun Case | 8b0ecbc | 2021-12-20 21:14:10 -0800 | [diff] [blame] | 9 | # + Use the PUBLIC and PRIVATE keywords to specify the scope of include |
Ronald Cron | b1790af | 2020-05-20 15:34:47 +0200 | [diff] [blame] | 10 | # directories. That way, a target linking to a library (using the |
bootstrap-prime | 6dbbf44 | 2022-05-17 19:30:44 -0400 | [diff] [blame] | 11 | # target_link_libraries command) inherits from the library PUBLIC include |
Ronald Cron | b1790af | 2020-05-20 15:34:47 +0200 | [diff] [blame] | 12 | # directories and not from the PRIVATE ones. |
Raef Coles | 995c66f | 2020-10-13 16:30:41 +0100 | [diff] [blame] | 13 | # - MBEDTLS_TARGET_PREFIX: CMake targets are designed to be alterable by calling |
| 14 | # CMake in order to avoid target name clashes, via the use of |
| 15 | # MBEDTLS_TARGET_PREFIX. The value of this variable is prefixed to the |
| 16 | # mbedtls, mbedx509, mbedcrypto and apidoc targets. |
Ronald Cron | b1790af | 2020-05-20 15:34:47 +0200 | [diff] [blame] | 17 | # |
| 18 | |
Dave Rodgman | be4af04 | 2021-06-04 17:04:20 +0100 | [diff] [blame] | 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) |
Paul Elliott | b250ac9 | 2020-09-18 18:15:07 +0100 | [diff] [blame] | 22 | |
Chris Kay | d259e34 | 2021-03-25 16:03:25 +0000 | [diff] [blame] | 23 | include(CMakePackageConfigHelpers) |
| 24 | |
Ronald Cron | 977766c | 2024-07-11 08:47:53 +0200 | [diff] [blame] | 25 | # Include convenience functions for printing properties and variables, like |
| 26 | # cmake_print_properties(), cmake_print_variables(). |
| 27 | include(CMakePrintHelpers) |
| 28 | |
Paul Elliott | b250ac9 | 2020-09-18 18:15:07 +0100 | [diff] [blame] | 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 | |
Andrzej Kurek | 0211c32 | 2018-03-15 05:16:24 -0400 | [diff] [blame] | 40 | if(TEST_CPP) |
Bill Roberts | aab7f7f | 2024-02-20 08:16:57 -0600 | [diff] [blame] | 41 | project("Mbed TLS" |
| 42 | LANGUAGES C CXX |
Minos Galanakis | e62ef05 | 2025-03-18 17:11:54 +0000 | [diff] [blame] | 43 | VERSION 3.6.3 |
Bill Roberts | aab7f7f | 2024-02-20 08:16:57 -0600 | [diff] [blame] | 44 | ) |
Andrzej Kurek | 0211c32 | 2018-03-15 05:16:24 -0400 | [diff] [blame] | 45 | else() |
Bill Roberts | aab7f7f | 2024-02-20 08:16:57 -0600 | [diff] [blame] | 46 | project("Mbed TLS" |
| 47 | LANGUAGES C |
Minos Galanakis | e62ef05 | 2025-03-18 17:11:54 +0000 | [diff] [blame] | 48 | VERSION 3.6.3 |
Bill Roberts | aab7f7f | 2024-02-20 08:16:57 -0600 | [diff] [blame] | 49 | ) |
Andrzej Kurek | 0211c32 | 2018-03-15 05:16:24 -0400 | [diff] [blame] | 50 | endif() |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 51 | |
Biswapriyo Nath | 0f2e87b | 2022-04-22 20:56:21 +0530 | [diff] [blame] | 52 | include(GNUInstallDirs) |
| 53 | |
Gilles Peskine | e820c0a | 2023-08-03 17:45:20 +0200 | [diff] [blame] | 54 | # Determine if Mbed TLS is being built as a subproject using add_subdirectory() |
Antonio de Angelis | 2869c67 | 2021-12-07 20:45:55 +0000 | [diff] [blame] | 55 | if(NOT DEFINED MBEDTLS_AS_SUBPROJECT) |
| 56 | set(MBEDTLS_AS_SUBPROJECT ON) |
| 57 | if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) |
| 58 | set(MBEDTLS_AS_SUBPROJECT OFF) |
| 59 | endif() |
| 60 | endif() |
| 61 | |
Ashley Duncan | d85a7e9 | 2019-04-29 20:35:06 +1200 | [diff] [blame] | 62 | # Set the project root directory. |
| 63 | set(MBEDTLS_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
Harry Ramsey | d358d6e | 2025-02-17 17:22:54 +0000 | [diff] [blame] | 64 | set(MBEDTLS_FRAMEWORK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/framework) |
Ashley Duncan | d85a7e9 | 2019-04-29 20:35:06 +1200 | [diff] [blame] | 65 | |
Gilles Peskine | e820c0a | 2023-08-03 17:45:20 +0200 | [diff] [blame] | 66 | option(ENABLE_PROGRAMS "Build Mbed TLS programs." ON) |
Manuel Pégourié-Gonnard | 5871910 | 2015-07-09 09:19:47 +0100 | [diff] [blame] | 67 | |
Simon Butcher | 1ceab6e | 2016-06-21 10:14:00 +0100 | [diff] [blame] | 68 | option(UNSAFE_BUILD "Allow unsafe builds. These builds ARE NOT SECURE." OFF) |
Carlos Gomes Martinho | a5f0bd3 | 2020-04-03 09:42:37 +0200 | [diff] [blame] | 69 | option(MBEDTLS_FATAL_WARNINGS "Compiler warnings treated as errors" ON) |
Anton Komlev | ca947a4 | 2022-04-14 15:22:11 +0100 | [diff] [blame] | 70 | if(CMAKE_HOST_WIN32) |
Gilles Peskine | ecc9961 | 2023-09-09 22:54:26 +0200 | [diff] [blame] | 71 | # N.B. The comment on the next line is significant! If you change it, |
| 72 | # edit the sed command in prepare_release.sh that modifies |
| 73 | # CMakeLists.txt. |
Gilles Peskine | eeed74e | 2023-09-09 21:00:30 +0200 | [diff] [blame] | 74 | option(GEN_FILES "Generate the auto-generated files as needed" OFF) # off in development |
David Horstmann | 7749651 | 2021-10-21 19:45:52 +0100 | [diff] [blame] | 75 | else() |
Minos Galanakis | 22098d4 | 2025-03-20 09:33:09 +0000 | [diff] [blame] | 76 | option(GEN_FILES "Generate the auto-generated files as needed" OFF) |
David Horstmann | 7749651 | 2021-10-21 19:45:52 +0100 | [diff] [blame] | 77 | endif() |
Manuel Pégourié-Gonnard | 5871910 | 2015-07-09 09:19:47 +0100 | [diff] [blame] | 78 | |
Antonio de Angelis | 2869c67 | 2021-12-07 20:45:55 +0000 | [diff] [blame] | 79 | option(DISABLE_PACKAGE_CONFIG_AND_INSTALL "Disable package configuration, target export and installation" ${MBEDTLS_AS_SUBPROJECT}) |
| 80 | |
Daan Timmer | 6c792ca | 2023-10-18 16:15:58 +0200 | [diff] [blame] | 81 | if (CMAKE_C_SIMULATE_ID) |
| 82 | set(COMPILER_ID ${CMAKE_C_SIMULATE_ID}) |
| 83 | else() |
| 84 | set(COMPILER_ID ${CMAKE_C_COMPILER_ID}) |
| 85 | endif(CMAKE_C_SIMULATE_ID) |
| 86 | |
| 87 | string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${COMPILER_ID}") |
| 88 | string(REGEX MATCH "GNU" CMAKE_COMPILER_IS_GNU "${COMPILER_ID}") |
| 89 | string(REGEX MATCH "IAR" CMAKE_COMPILER_IS_IAR "${COMPILER_ID}") |
| 90 | string(REGEX MATCH "MSVC" CMAKE_COMPILER_IS_MSVC "${COMPILER_ID}") |
Azim Khan | 45b79cf | 2018-05-23 16:55:16 +0100 | [diff] [blame] | 91 | |
Manuel Pégourié-Gonnard | 5871910 | 2015-07-09 09:19:47 +0100 | [diff] [blame] | 92 | # the test suites currently have compile errors with MSVC |
Azim Khan | 45b79cf | 2018-05-23 16:55:16 +0100 | [diff] [blame] | 93 | if(CMAKE_COMPILER_IS_MSVC) |
Gilles Peskine | e820c0a | 2023-08-03 17:45:20 +0200 | [diff] [blame] | 94 | option(ENABLE_TESTING "Build Mbed TLS tests." OFF) |
Manuel Pégourié-Gonnard | 5871910 | 2015-07-09 09:19:47 +0100 | [diff] [blame] | 95 | else() |
Gilles Peskine | e820c0a | 2023-08-03 17:45:20 +0200 | [diff] [blame] | 96 | option(ENABLE_TESTING "Build Mbed TLS tests." ON) |
Manuel Pégourié-Gonnard | 5871910 | 2015-07-09 09:19:47 +0100 | [diff] [blame] | 97 | endif() |
Manuel Pégourié-Gonnard | 0b4e2ac | 2015-07-08 22:10:38 +0100 | [diff] [blame] | 98 | |
Simon Butcher | 45103f3 | 2016-06-21 14:47:11 +0100 | [diff] [blame] | 99 | # Warning string - created as a list for compatibility with CMake 2.8 |
Nir Sonnenschein | b7ebbca | 2018-08-29 10:20:12 +0300 | [diff] [blame] | 100 | set(CTR_DRBG_128_BIT_KEY_WARN_L1 "**** WARNING! MBEDTLS_CTR_DRBG_USE_128_BIT_KEY defined!\n") |
| 101 | set(CTR_DRBG_128_BIT_KEY_WARN_L2 "**** Using 128-bit keys for CTR_DRBG limits the security of generated\n") |
| 102 | set(CTR_DRBG_128_BIT_KEY_WARN_L3 "**** keys and operations that use random values generated to 128-bit security\n") |
| 103 | |
| 104 | set(CTR_DRBG_128_BIT_KEY_WARNING "${WARNING_BORDER}" |
| 105 | "${CTR_DRBG_128_BIT_KEY_WARN_L1}" |
| 106 | "${CTR_DRBG_128_BIT_KEY_WARN_L2}" |
| 107 | "${CTR_DRBG_128_BIT_KEY_WARN_L3}" |
| 108 | "${WARNING_BORDER}") |
| 109 | |
Gilles Peskine | 9740929 | 2019-09-04 22:10:34 +0200 | [diff] [blame] | 110 | # Python 3 is only needed here to check for configuration warnings. |
okhowang(王沛文) | 3c1b090 | 2020-03-25 19:55:32 +0800 | [diff] [blame] | 111 | if(NOT CMAKE_VERSION VERSION_LESS 3.15.0) |
| 112 | set(Python3_FIND_STRATEGY LOCATION) |
| 113 | find_package(Python3 COMPONENTS Interpreter) |
| 114 | if(Python3_Interpreter_FOUND) |
| 115 | set(MBEDTLS_PYTHON_EXECUTABLE ${Python3_EXECUTABLE}) |
| 116 | endif() |
| 117 | else() |
| 118 | find_package(PythonInterp 3) |
| 119 | if(PYTHONINTERP_FOUND) |
| 120 | set(MBEDTLS_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}) |
| 121 | endif() |
| 122 | endif() |
| 123 | if(MBEDTLS_PYTHON_EXECUTABLE) |
Simon Butcher | 1ceab6e | 2016-06-21 10:14:00 +0100 | [diff] [blame] | 124 | |
Nir Sonnenschein | b7ebbca | 2018-08-29 10:20:12 +0300 | [diff] [blame] | 125 | # If 128-bit keys are configured for CTR_DRBG, display an appropriate warning |
Bence Szépkúti | bb0cfeb | 2021-05-28 09:42:25 +0200 | [diff] [blame] | 126 | execute_process(COMMAND ${MBEDTLS_PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/config.py -f ${CMAKE_CURRENT_SOURCE_DIR}/include/mbedtls/mbedtls_config.h get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY |
Nir Sonnenschein | b7ebbca | 2018-08-29 10:20:12 +0300 | [diff] [blame] | 127 | RESULT_VARIABLE result) |
| 128 | if(${result} EQUAL 0) |
| 129 | message(WARNING ${CTR_DRBG_128_BIT_KEY_WARNING}) |
| 130 | endif() |
| 131 | |
Simon Butcher | 1ceab6e | 2016-06-21 10:14:00 +0100 | [diff] [blame] | 132 | endif() |
| 133 | |
Paul Elliott | 7fd162e | 2024-01-24 18:05:53 +0000 | [diff] [blame] | 134 | # We now potentially need to link all executables against PThreads, if available |
| 135 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE) |
| 136 | set(THREADS_PREFER_PTHREAD_FLAG TRUE) |
| 137 | find_package(Threads) |
| 138 | |
Peter Toft | fdf3379 | 2020-10-14 17:19:02 +0200 | [diff] [blame] | 139 | # If this is the root project add longer list of available CMAKE_BUILD_TYPE values |
| 140 | if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
| 141 | set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} |
Paul Elliott | bbdfc8a | 2023-11-23 14:07:43 +0000 | [diff] [blame] | 142 | CACHE STRING "Choose the type of build: None Debug Release Coverage ASan ASanDbg MemSan MemSanDbg Check CheckFull TSan TSanDbg" |
Peter Toft | fdf3379 | 2020-10-14 17:19:02 +0200 | [diff] [blame] | 143 | FORCE) |
| 144 | endif() |
Manuel Pégourié-Gonnard | 0b4e2ac | 2015-07-08 22:10:38 +0100 | [diff] [blame] | 145 | |
David Horstmann | 0f1dd57 | 2023-02-15 14:44:25 +0000 | [diff] [blame] | 146 | # Make MBEDTLS_CONFIG_FILE and MBEDTLS_USER_CONFIG_FILE into PATHs |
| 147 | set(MBEDTLS_CONFIG_FILE "" CACHE FILEPATH "Mbed TLS config file (overrides default).") |
| 148 | set(MBEDTLS_USER_CONFIG_FILE "" CACHE FILEPATH "Mbed TLS user config file (appended to default).") |
David Horstmann | ae33ab8 | 2023-01-12 13:59:34 +0000 | [diff] [blame] | 149 | |
Gilles Peskine | 8405257 | 2018-03-21 12:12:47 +0100 | [diff] [blame] | 150 | # Create a symbolic link from ${base_name} in the binary directory |
| 151 | # to the corresponding path in the source directory. |
Dominik Gschwind | c6d1636 | 2022-08-10 16:27:14 +0200 | [diff] [blame] | 152 | # Note: Copies the file(s) on Windows. |
Gilles Peskine | 8405257 | 2018-03-21 12:12:47 +0100 | [diff] [blame] | 153 | function(link_to_source base_name) |
Dominik Gschwind | c6d1636 | 2022-08-10 16:27:14 +0200 | [diff] [blame] | 154 | set(link "${CMAKE_CURRENT_BINARY_DIR}/${base_name}") |
| 155 | set(target "${CMAKE_CURRENT_SOURCE_DIR}/${base_name}") |
Gilles Peskine | 8405257 | 2018-03-21 12:12:47 +0100 | [diff] [blame] | 156 | |
Dave Rodgman | a14f5d9 | 2022-07-20 11:09:17 +0100 | [diff] [blame] | 157 | # Linking to non-existent file is not desirable. At best you will have a |
Paul Elliott | 582f72b | 2022-07-12 14:55:01 +0100 | [diff] [blame] | 158 | # dangling link, but when building in tree, this can create a symbolic link |
| 159 | # to itself. |
| 160 | if (EXISTS ${target} AND NOT EXISTS ${link}) |
Gilles Peskine | 8405257 | 2018-03-21 12:12:47 +0100 | [diff] [blame] | 161 | if (CMAKE_HOST_UNIX) |
Dominik Gschwind | c6d1636 | 2022-08-10 16:27:14 +0200 | [diff] [blame] | 162 | execute_process(COMMAND ln -s ${target} ${link} |
| 163 | RESULT_VARIABLE result |
| 164 | ERROR_VARIABLE output) |
| 165 | |
| 166 | if (NOT ${result} EQUAL 0) |
| 167 | message(FATAL_ERROR "Could not create symbolic link for: ${target} --> ${output}") |
| 168 | endif() |
Gilles Peskine | 8405257 | 2018-03-21 12:12:47 +0100 | [diff] [blame] | 169 | else() |
Darryl Green | d75ee64 | 2018-06-07 11:55:50 +0100 | [diff] [blame] | 170 | if (IS_DIRECTORY ${target}) |
Dominik Gschwind | c6d1636 | 2022-08-10 16:27:14 +0200 | [diff] [blame] | 171 | file(GLOB_RECURSE files FOLLOW_SYMLINKS LIST_DIRECTORIES false RELATIVE ${target} "${target}/*") |
| 172 | foreach(file IN LISTS files) |
| 173 | configure_file("${target}/${file}" "${link}/${file}" COPYONLY) |
| 174 | endforeach(file) |
Darryl Green | d75ee64 | 2018-06-07 11:55:50 +0100 | [diff] [blame] | 175 | else() |
Dominik Gschwind | c6d1636 | 2022-08-10 16:27:14 +0200 | [diff] [blame] | 176 | configure_file(${target} ${link} COPYONLY) |
Darryl Green | d75ee64 | 2018-06-07 11:55:50 +0100 | [diff] [blame] | 177 | endif() |
Gilles Peskine | 8405257 | 2018-03-21 12:12:47 +0100 | [diff] [blame] | 178 | endif() |
Gilles Peskine | 8405257 | 2018-03-21 12:12:47 +0100 | [diff] [blame] | 179 | endif() |
| 180 | endfunction(link_to_source) |
| 181 | |
David Horstmann | b3a5424 | 2021-10-19 18:37:04 +0100 | [diff] [blame] | 182 | # Get the filename without the final extension (i.e. convert "a.b.c" to "a.b") |
| 183 | function(get_name_without_last_ext dest_var full_name) |
| 184 | # Split into a list on '.' (but a cmake list is just a ';'-separated string) |
| 185 | string(REPLACE "." ";" ext_parts "${full_name}") |
| 186 | # Remove the last item if there are more than one |
| 187 | list(LENGTH ext_parts ext_parts_len) |
| 188 | if (${ext_parts_len} GREATER "1") |
| 189 | math(EXPR ext_parts_last_item "${ext_parts_len} - 1") |
| 190 | list(REMOVE_AT ext_parts ${ext_parts_last_item}) |
| 191 | endif() |
| 192 | # Convert back to a string by replacing separators with '.' |
| 193 | string(REPLACE ";" "." no_ext_name "${ext_parts}") |
| 194 | # Copy into the desired variable |
| 195 | set(${dest_var} ${no_ext_name} PARENT_SCOPE) |
| 196 | endfunction(get_name_without_last_ext) |
| 197 | |
makise-homura | ac2fd65 | 2020-08-18 21:59:46 +0300 | [diff] [blame] | 198 | include(CheckCCompilerFlag) |
| 199 | |
Dave Rodgman | f5f1cfc | 2022-05-10 17:26:47 +0100 | [diff] [blame] | 200 | set(CMAKE_C_EXTENSIONS OFF) |
okhowang(王沛文) | df865c3 | 2020-09-03 16:21:30 +0800 | [diff] [blame] | 201 | set(CMAKE_C_STANDARD 99) |
| 202 | |
Azim Khan | 45b79cf | 2018-05-23 16:55:16 +0100 | [diff] [blame] | 203 | if(CMAKE_COMPILER_IS_GNU) |
Manuel Pégourié-Gonnard | bcb0460 | 2015-07-19 16:00:04 +0200 | [diff] [blame] | 204 | # some warnings we want are not available with old GCC versions |
| 205 | # note: starting with CMake 2.8 we could use CMAKE_C_COMPILER_VERSION |
| 206 | execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion |
| 207 | OUTPUT_VARIABLE GCC_VERSION) |
Michael Schuster | 4d0d0ec | 2024-06-05 01:45:54 +0200 | [diff] [blame] | 208 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wwrite-strings -Wmissing-prototypes") |
Paul Elliott | ea32d55 | 2020-12-09 14:34:47 +0000 | [diff] [blame] | 209 | if (GCC_VERSION VERSION_GREATER 3.0 OR GCC_VERSION VERSION_EQUAL 3.0) |
| 210 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat=2 -Wno-format-nonliteral") |
| 211 | endif() |
Gilles Peskine | be51716 | 2019-07-02 20:22:11 +0200 | [diff] [blame] | 212 | if (GCC_VERSION VERSION_GREATER 4.3 OR GCC_VERSION VERSION_EQUAL 4.3) |
| 213 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wvla") |
| 214 | endif() |
Manuel Pégourié-Gonnard | bcb0460 | 2015-07-19 16:00:04 +0200 | [diff] [blame] | 215 | if (GCC_VERSION VERSION_GREATER 4.5 OR GCC_VERSION VERSION_EQUAL 4.5) |
| 216 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wlogical-op") |
| 217 | endif() |
Manuel Pégourié-Gonnard | 824ba72 | 2015-08-27 23:00:49 +0200 | [diff] [blame] | 218 | if (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8) |
okhowang(王沛文) | 0cd8e0f | 2020-07-03 11:41:38 +0800 | [diff] [blame] | 219 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow") |
| 220 | endif() |
| 221 | if (GCC_VERSION VERSION_GREATER 5.0) |
makise-homura | ac2fd65 | 2020-08-18 21:59:46 +0300 | [diff] [blame] | 222 | CHECK_C_COMPILER_FLAG("-Wformat-signedness" C_COMPILER_SUPPORTS_WFORMAT_SIGNEDNESS) |
| 223 | if(C_COMPILER_SUPPORTS_WFORMAT_SIGNEDNESS) |
| 224 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-signedness") |
| 225 | endif() |
| 226 | endif() |
Paul Elliott | ea32d55 | 2020-12-09 14:34:47 +0000 | [diff] [blame] | 227 | if (GCC_VERSION VERSION_GREATER 7.0 OR GCC_VERSION VERSION_EQUAL 7.0) |
Paul Elliott | 2065a8d | 2021-03-17 13:12:22 +0000 | [diff] [blame] | 228 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-overflow=2 -Wformat-truncation") |
Paul Elliott | ea32d55 | 2020-12-09 14:34:47 +0000 | [diff] [blame] | 229 | endif() |
Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 230 | set(CMAKE_C_FLAGS_RELEASE "-O2") |
| 231 | set(CMAKE_C_FLAGS_DEBUG "-O0 -g3") |
| 232 | set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage") |
Gilles Peskine | 765da15 | 2024-10-15 12:03:26 +0200 | [diff] [blame] | 233 | # Old GCC versions hit a performance problem with test_suite_pkwrite |
| 234 | # "Private keey write check EC" tests when building with Asan+UBSan |
| 235 | # and -O3: those tests take more than 100x time than normal, with |
| 236 | # test_suite_pkwrite taking >3h on the CI. Observed with GCC 5.4 on |
| 237 | # Ubuntu 16.04 x86_64 and GCC 6.5 on Ubuntu 18.04 x86_64. |
| 238 | # GCC 7.5 and above on Ubuntu 18.04 appear fine. |
Valerio Setti | bdca1fe | 2024-10-16 13:28:44 +0200 | [diff] [blame] | 239 | # To avoid the performance problem, we use -O2 when GCC version is lower than 7.0. |
| 240 | # It doesn't slow down much even with modern compiler versions. |
| 241 | if (GCC_VERSION VERSION_LESS 7.0) |
| 242 | message(STATUS "USING O2") |
| 243 | set(CMAKE_C_FLAGS_ASAN "-fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O2") |
| 244 | else() |
| 245 | message(STATUS "USING O3") |
| 246 | set(CMAKE_C_FLAGS_ASAN "-fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O3") |
| 247 | endif() |
Carlos Gomes Martinho | a5f0bd3 | 2020-04-03 09:42:37 +0200 | [diff] [blame] | 248 | set(CMAKE_C_FLAGS_ASANDBG "-fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls") |
Paul Elliott | bbdfc8a | 2023-11-23 14:07:43 +0000 | [diff] [blame] | 249 | set(CMAKE_C_FLAGS_TSAN "-fsanitize=thread -O3") |
| 250 | set(CMAKE_C_FLAGS_TSANDBG "-fsanitize=thread -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls") |
Carlos Gomes Martinho | a5f0bd3 | 2020-04-03 09:42:37 +0200 | [diff] [blame] | 251 | set(CMAKE_C_FLAGS_CHECK "-Os") |
Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 252 | set(CMAKE_C_FLAGS_CHECKFULL "${CMAKE_C_FLAGS_CHECK} -Wcast-qual") |
Azim Khan | 45b79cf | 2018-05-23 16:55:16 +0100 | [diff] [blame] | 253 | endif(CMAKE_COMPILER_IS_GNU) |
Paul Bakker | 76f0311 | 2013-11-28 17:20:04 +0100 | [diff] [blame] | 254 | |
Paul Bakker | 92bc875 | 2013-12-30 17:56:23 +0100 | [diff] [blame] | 255 | if(CMAKE_COMPILER_IS_CLANG) |
Michael Schuster | 4d0d0ec | 2024-06-05 01:45:54 +0200 | [diff] [blame] | 256 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wwrite-strings -Wmissing-prototypes -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral") |
Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 257 | set(CMAKE_C_FLAGS_RELEASE "-O2") |
| 258 | set(CMAKE_C_FLAGS_DEBUG "-O0 -g3") |
| 259 | set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage") |
Carlos Gomes Martinho | a5f0bd3 | 2020-04-03 09:42:37 +0200 | [diff] [blame] | 260 | set(CMAKE_C_FLAGS_ASAN "-fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O3") |
| 261 | set(CMAKE_C_FLAGS_ASANDBG "-fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls") |
| 262 | set(CMAKE_C_FLAGS_MEMSAN "-fsanitize=memory -O3") |
| 263 | set(CMAKE_C_FLAGS_MEMSANDBG "-fsanitize=memory -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2") |
Paul Elliott | bbdfc8a | 2023-11-23 14:07:43 +0000 | [diff] [blame] | 264 | set(CMAKE_C_FLAGS_TSAN "-fsanitize=thread -O3") |
| 265 | set(CMAKE_C_FLAGS_TSANDBG "-fsanitize=thread -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls") |
Carlos Gomes Martinho | a5f0bd3 | 2020-04-03 09:42:37 +0200 | [diff] [blame] | 266 | set(CMAKE_C_FLAGS_CHECK "-Os") |
Paul Bakker | 92bc875 | 2013-12-30 17:56:23 +0100 | [diff] [blame] | 267 | endif(CMAKE_COMPILER_IS_CLANG) |
| 268 | |
Azim Khan | 45b79cf | 2018-05-23 16:55:16 +0100 | [diff] [blame] | 269 | if(CMAKE_COMPILER_IS_IAR) |
TTornblom | e4f6d79 | 2020-04-16 13:53:38 +0200 | [diff] [blame] | 270 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --warn_about_c_style_casts") |
| 271 | set(CMAKE_C_FLAGS_RELEASE "-Ohz") |
| 272 | set(CMAKE_C_FLAGS_DEBUG "--debug -On") |
Azim Khan | 45b79cf | 2018-05-23 16:55:16 +0100 | [diff] [blame] | 273 | endif(CMAKE_COMPILER_IS_IAR) |
| 274 | |
| 275 | if(CMAKE_COMPILER_IS_MSVC) |
Andrea Pappacoda | 9202909 | 2021-12-27 22:41:21 +0100 | [diff] [blame] | 276 | # Strictest warnings, UTF-8 source and execution charset |
| 277 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /utf-8") |
Azim Khan | 45b79cf | 2018-05-23 16:55:16 +0100 | [diff] [blame] | 278 | endif(CMAKE_COMPILER_IS_MSVC) |
Manuel Pégourié-Gonnard | 3083053 | 2015-07-01 17:06:28 +0200 | [diff] [blame] | 279 | |
Carlos Gomes Martinho | a5f0bd3 | 2020-04-03 09:42:37 +0200 | [diff] [blame] | 280 | if(MBEDTLS_FATAL_WARNINGS) |
| 281 | if(CMAKE_COMPILER_IS_MSVC) |
| 282 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX") |
| 283 | endif(CMAKE_COMPILER_IS_MSVC) |
| 284 | |
| 285 | if(CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNU) |
| 286 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") |
Carlos Gomes Martinho | e150c77 | 2020-04-21 22:15:01 +0200 | [diff] [blame] | 287 | if(UNSAFE_BUILD) |
| 288 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=cpp") |
| 289 | set(CMAKE_C_FLAGS_ASAN "${CMAKE_C_FLAGS_ASAN} -Wno-error=cpp") |
| 290 | set(CMAKE_C_FLAGS_ASANDBG "${CMAKE_C_FLAGS_ASANDBG} -Wno-error=cpp") |
| 291 | endif(UNSAFE_BUILD) |
Carlos Gomes Martinho | a5f0bd3 | 2020-04-03 09:42:37 +0200 | [diff] [blame] | 292 | endif(CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNU) |
savent | 5d8adab | 2022-06-17 18:06:30 +0800 | [diff] [blame] | 293 | |
| 294 | if (CMAKE_COMPILER_IS_IAR) |
Robin Kastberg | e5eb33d | 2023-05-26 15:57:37 +0200 | [diff] [blame] | 295 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --warnings_are_errors") |
savent | 5d8adab | 2022-06-17 18:06:30 +0800 | [diff] [blame] | 296 | endif(CMAKE_COMPILER_IS_IAR) |
Carlos Gomes Martinho | a5f0bd3 | 2020-04-03 09:42:37 +0200 | [diff] [blame] | 297 | endif(MBEDTLS_FATAL_WARNINGS) |
| 298 | |
Gilles Peskine | f5db72b | 2024-06-06 22:12:06 +0200 | [diff] [blame] | 299 | if(CMAKE_BUILD_TYPE STREQUAL "Check" AND TEST_CPP) |
| 300 | set(CMAKE_CXX_STANDARD 11) |
| 301 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 302 | set(CMAKE_CXX_EXTENSIONS OFF) |
| 303 | if(CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNU) |
| 304 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") |
| 305 | endif() |
| 306 | endif() |
| 307 | |
Paul Bakker | 396c52f | 2009-07-11 19:54:40 +0000 | [diff] [blame] | 308 | if(CMAKE_BUILD_TYPE STREQUAL "Coverage") |
Azim Khan | 45b79cf | 2018-05-23 16:55:16 +0100 | [diff] [blame] | 309 | if(CMAKE_COMPILER_IS_GNU OR CMAKE_COMPILER_IS_CLANG) |
Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 310 | set(CMAKE_SHARED_LINKER_FLAGS "--coverage") |
Azim Khan | 45b79cf | 2018-05-23 16:55:16 +0100 | [diff] [blame] | 311 | endif(CMAKE_COMPILER_IS_GNU OR CMAKE_COMPILER_IS_CLANG) |
Paul Bakker | 396c52f | 2009-07-11 19:54:40 +0000 | [diff] [blame] | 312 | endif(CMAKE_BUILD_TYPE STREQUAL "Coverage") |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 313 | |
Paul Bakker | 091e287 | 2011-07-13 11:45:58 +0000 | [diff] [blame] | 314 | if(LIB_INSTALL_DIR) |
Biswapriyo Nath | 0f2e87b | 2022-04-22 20:56:21 +0530 | [diff] [blame] | 315 | set(CMAKE_INSTALL_LIBDIR "${LIB_INSTALL_DIR}") |
Paul Bakker | 091e287 | 2011-07-13 11:45:58 +0000 | [diff] [blame] | 316 | endif() |
| 317 | |
Gilles Peskine | f9bbe0d | 2024-03-04 16:25:14 +0100 | [diff] [blame] | 318 | if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/framework/CMakeLists.txt") |
Harry Ramsey | f0dedba | 2024-12-10 15:32:04 +0000 | [diff] [blame] | 319 | if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") |
Harry Ramsey | e3fdd0a | 2024-11-04 15:14:53 +0000 | [diff] [blame] | 320 | message(FATAL_ERROR "${CMAKE_CURRENT_SOURCE_DIR}CMakeLists.txt not found (and does appear to be a git checkout). Run `git submodule update --init` from the source tree to fetch the submodule contents.") |
Harry Ramsey | d532a66 | 2024-11-04 10:50:30 +0000 | [diff] [blame] | 321 | else () |
Harry Ramsey | e3fdd0a | 2024-11-04 15:14:53 +0000 | [diff] [blame] | 322 | message(FATAL_ERROR "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt not found (and does not appear to be a git checkout). Please ensure you have downloaded the right archive from the release page on GitHub.") |
Harry Ramsey | d532a66 | 2024-11-04 10:50:30 +0000 | [diff] [blame] | 323 | endif() |
Gilles Peskine | f9bbe0d | 2024-03-04 16:25:14 +0100 | [diff] [blame] | 324 | endif() |
Gilles Peskine | 469f781 | 2024-02-29 18:19:56 +0100 | [diff] [blame] | 325 | add_subdirectory(framework) |
| 326 | |
Christoph M. Wintersteiger | 7b747fc | 2019-04-08 17:00:34 +0100 | [diff] [blame] | 327 | add_subdirectory(include) |
| 328 | |
Christoph M. Wintersteiger | 62dddd0 | 2018-12-14 13:07:50 +0000 | [diff] [blame] | 329 | add_subdirectory(3rdparty) |
Christoph M. Wintersteiger | 6ea2dea1 | 2019-01-21 17:26:19 +0000 | [diff] [blame] | 330 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 331 | add_subdirectory(library) |
Paul Bakker | 2015eac | 2011-07-27 16:52:28 +0000 | [diff] [blame] | 332 | |
Bill Roberts | a4d17b3 | 2024-01-09 13:10:05 -0600 | [diff] [blame] | 333 | add_subdirectory(pkgconfig) |
| 334 | |
Ronald Cron | dd6bdb5 | 2020-06-26 16:37:02 +0200 | [diff] [blame] | 335 | # |
David Horstmann | dcf42a0 | 2024-11-08 14:40:12 +0000 | [diff] [blame] | 336 | # The C files in framework/tests/src directory contain test code shared among test suites |
Ronald Cron | dd6bdb5 | 2020-06-26 16:37:02 +0200 | [diff] [blame] | 337 | # and programs. This shared test code is compiled and linked to test suites and |
| 338 | # programs objects as a set of compiled objects. The compiled objects are NOT |
| 339 | # built into a library that the test suite and program objects would link |
| 340 | # against as they link against the mbedcrypto, mbedx509 and mbedtls libraries. |
| 341 | # The reason is that such library is expected to have mutual dependencies with |
| 342 | # the aforementioned libraries and that there is as of today no portable way of |
| 343 | # handling such dependencies (only toolchain specific solutions). |
| 344 | # |
| 345 | # Thus the below definition of the `mbedtls_test` CMake library of objects |
| 346 | # target. This library of objects is used by tests and programs CMake files |
| 347 | # to define the test executables. |
| 348 | # |
Ronald Cron | ddaf99c | 2020-06-19 11:27:26 +0200 | [diff] [blame] | 349 | if(ENABLE_TESTING OR ENABLE_PROGRAMS) |
Yanray Wang | b458b8c | 2022-10-28 11:49:33 +0800 | [diff] [blame] | 350 | file(GLOB MBEDTLS_TEST_FILES |
David Horstmann | 0e8cc11 | 2024-11-04 14:13:37 +0000 | [diff] [blame] | 351 | ${CMAKE_CURRENT_SOURCE_DIR}/tests/src/*.c |
David Horstmann | dcf42a0 | 2024-11-08 14:40:12 +0000 | [diff] [blame] | 352 | ${CMAKE_CURRENT_SOURCE_DIR}/framework/tests/src/*.c |
| 353 | ${CMAKE_CURRENT_SOURCE_DIR}/framework/tests/src/drivers/*.c) |
Valerio Setti | 911363e | 2024-04-15 09:11:28 +0200 | [diff] [blame] | 354 | add_library(mbedtls_test OBJECT ${MBEDTLS_TEST_FILES}) |
| 355 | if(GEN_FILES) |
David Horstmann | 58b660c | 2024-05-10 14:23:16 +0100 | [diff] [blame] | 356 | add_custom_command( |
| 357 | OUTPUT |
Ronald Cron | 4eaf54e | 2024-12-09 18:46:11 +0100 | [diff] [blame] | 358 | ${CMAKE_CURRENT_SOURCE_DIR}/framework/tests/include/test/test_keys.h |
David Horstmann | 58b660c | 2024-05-10 14:23:16 +0100 | [diff] [blame] | 359 | WORKING_DIRECTORY |
| 360 | ${CMAKE_CURRENT_SOURCE_DIR}/tests |
| 361 | COMMAND |
| 362 | "${MBEDTLS_PYTHON_EXECUTABLE}" |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 363 | "${CMAKE_CURRENT_SOURCE_DIR}/framework/scripts/generate_test_keys.py" |
David Horstmann | 58b660c | 2024-05-10 14:23:16 +0100 | [diff] [blame] | 364 | "--output" |
Ronald Cron | 4eaf54e | 2024-12-09 18:46:11 +0100 | [diff] [blame] | 365 | "${CMAKE_CURRENT_SOURCE_DIR}/framework/tests/include/test/test_keys.h" |
David Horstmann | 58b660c | 2024-05-10 14:23:16 +0100 | [diff] [blame] | 366 | DEPENDS |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 367 | ${CMAKE_CURRENT_SOURCE_DIR}/framework/scripts/generate_test_keys.py |
David Horstmann | 58b660c | 2024-05-10 14:23:16 +0100 | [diff] [blame] | 368 | ) |
Ronald Cron | 4eaf54e | 2024-12-09 18:46:11 +0100 | [diff] [blame] | 369 | add_custom_target(test_keys_header DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/framework/tests/include/test/test_keys.h) |
David Horstmann | 58b660c | 2024-05-10 14:23:16 +0100 | [diff] [blame] | 370 | add_custom_command( |
| 371 | OUTPUT |
| 372 | ${CMAKE_CURRENT_SOURCE_DIR}/tests/src/test_certs.h |
| 373 | WORKING_DIRECTORY |
| 374 | ${CMAKE_CURRENT_SOURCE_DIR}/tests |
| 375 | COMMAND |
| 376 | "${MBEDTLS_PYTHON_EXECUTABLE}" |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 377 | "${CMAKE_CURRENT_SOURCE_DIR}/framework/scripts/generate_test_cert_macros.py" |
David Horstmann | 58b660c | 2024-05-10 14:23:16 +0100 | [diff] [blame] | 378 | "--output" |
| 379 | "${CMAKE_CURRENT_SOURCE_DIR}/tests/src/test_certs.h" |
| 380 | DEPENDS |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 381 | ${CMAKE_CURRENT_SOURCE_DIR}/framework/scripts/generate_test_cert_macros.py |
David Horstmann | 58b660c | 2024-05-10 14:23:16 +0100 | [diff] [blame] | 382 | ) |
| 383 | add_custom_target(test_certs_header DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/src/test_certs.h) |
Valerio Setti | 911363e | 2024-04-15 09:11:28 +0200 | [diff] [blame] | 384 | add_dependencies(mbedtls_test test_keys_header test_certs_header) |
| 385 | endif() |
Ronald Cron | ddaf99c | 2020-06-19 11:27:26 +0200 | [diff] [blame] | 386 | target_include_directories(mbedtls_test |
David Horstmann | dcf42a0 | 2024-11-08 14:40:12 +0000 | [diff] [blame] | 387 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/framework/tests/include |
David Horstmann | 0e8cc11 | 2024-11-04 14:13:37 +0000 | [diff] [blame] | 388 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests/include |
Ronald Cron | ddaf99c | 2020-06-19 11:27:26 +0200 | [diff] [blame] | 389 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include |
| 390 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/library) |
David Horstmann | c2ab398 | 2024-01-17 12:25:19 +0000 | [diff] [blame] | 391 | # Request C11, needed for memory poisoning tests |
| 392 | set_target_properties(mbedtls_test PROPERTIES C_STANDARD 11) |
Yanray Wang | b458b8c | 2022-10-28 11:49:33 +0800 | [diff] [blame] | 393 | |
| 394 | file(GLOB MBEDTLS_TEST_HELPER_FILES |
| 395 | ${CMAKE_CURRENT_SOURCE_DIR}/tests/src/test_helpers/*.c) |
| 396 | add_library(mbedtls_test_helpers OBJECT ${MBEDTLS_TEST_HELPER_FILES}) |
| 397 | target_include_directories(mbedtls_test_helpers |
David Horstmann | dcf42a0 | 2024-11-08 14:40:12 +0000 | [diff] [blame] | 398 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/framework/tests/include |
David Horstmann | 16b1c7b | 2024-10-31 15:48:28 +0000 | [diff] [blame] | 399 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests/include |
Yanray Wang | b458b8c | 2022-10-28 11:49:33 +0800 | [diff] [blame] | 400 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include |
| 401 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/library |
| 402 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/everest/include) |
David Horstmann | ae33ab8 | 2023-01-12 13:59:34 +0000 | [diff] [blame] | 403 | |
| 404 | # Pass-through MBEDTLS_CONFIG_FILE and MBEDTLS_USER_CONFIG_FILE |
David Horstmann | 0f1dd57 | 2023-02-15 14:44:25 +0000 | [diff] [blame] | 405 | if(MBEDTLS_CONFIG_FILE) |
David Horstmann | ae33ab8 | 2023-01-12 13:59:34 +0000 | [diff] [blame] | 406 | target_compile_definitions(mbedtls_test |
| 407 | PUBLIC MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}") |
| 408 | target_compile_definitions(mbedtls_test_helpers |
| 409 | PUBLIC MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}") |
| 410 | endif() |
David Horstmann | 0f1dd57 | 2023-02-15 14:44:25 +0000 | [diff] [blame] | 411 | if(MBEDTLS_USER_CONFIG_FILE) |
David Horstmann | ae33ab8 | 2023-01-12 13:59:34 +0000 | [diff] [blame] | 412 | target_compile_definitions(mbedtls_test |
| 413 | PUBLIC MBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}") |
| 414 | target_compile_definitions(mbedtls_test_helpers |
| 415 | PUBLIC MBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}") |
| 416 | endif() |
Ronald Cron | ddaf99c | 2020-06-19 11:27:26 +0200 | [diff] [blame] | 417 | endif() |
| 418 | |
Paul Bakker | df5024c | 2014-03-26 13:27:51 +0100 | [diff] [blame] | 419 | if(ENABLE_PROGRAMS) |
Gilles Peskine | 278b417 | 2024-09-24 19:09:57 +0200 | [diff] [blame] | 420 | set(ssl_opt_target "${MBEDTLS_TARGET_PREFIX}ssl-opt") |
| 421 | add_custom_target(${ssl_opt_target}) |
| 422 | |
Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 423 | add_subdirectory(programs) |
Paul Bakker | df5024c | 2014-03-26 13:27:51 +0100 | [diff] [blame] | 424 | endif() |
Paul Bakker | ccba9bc | 2011-01-05 15:30:32 +0000 | [diff] [blame] | 425 | |
Raef Coles | 995c66f | 2020-10-13 16:30:41 +0100 | [diff] [blame] | 426 | ADD_CUSTOM_TARGET(${MBEDTLS_TARGET_PREFIX}apidoc |
Krzysztof Stachowiak | a0188d6 | 2018-01-19 16:21:11 +0100 | [diff] [blame] | 427 | COMMAND doxygen mbedtls.doxyfile |
| 428 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doxygen) |
Manuel Pégourié-Gonnard | 7669f28 | 2013-09-07 16:52:42 +0200 | [diff] [blame] | 429 | |
Paul Bakker | 27f1cae | 2014-04-30 16:31:54 +0200 | [diff] [blame] | 430 | if(ENABLE_TESTING) |
Manuel Pégourié-Gonnard | 5fe51d7 | 2015-07-01 16:59:56 +0200 | [diff] [blame] | 431 | enable_testing() |
Manuel Pégourié-Gonnard | c8293b2 | 2015-06-25 09:22:25 +0200 | [diff] [blame] | 432 | |
Manuel Pégourié-Gonnard | 5fe51d7 | 2015-07-01 16:59:56 +0200 | [diff] [blame] | 433 | add_subdirectory(tests) |
Manuel Pégourié-Gonnard | 61137df | 2014-02-24 11:57:36 +0100 | [diff] [blame] | 434 | |
Manuel Pégourié-Gonnard | 5fe51d7 | 2015-07-01 16:59:56 +0200 | [diff] [blame] | 435 | # additional convenience targets for Unix only |
| 436 | if(UNIX) |
Manuel Pégourié-Gonnard | 546d86c | 2014-01-31 16:19:43 +0100 | [diff] [blame] | 437 | |
Gilles Peskine | 0ab6c8a | 2022-12-08 22:18:31 +0100 | [diff] [blame] | 438 | # For coverage testing: |
| 439 | # 1. Build with: |
| 440 | # cmake -D CMAKE_BUILD_TYPE=Coverage /path/to/source && make |
| 441 | # 2. Run the relevant tests for the part of the code you're interested in. |
| 442 | # For the reference coverage measurement, see |
| 443 | # tests/scripts/basic-build-test.sh |
| 444 | # 3. Run scripts/lcov.sh to generate an HTML report. |
Manuel Pégourié-Gonnard | 5fe51d7 | 2015-07-01 16:59:56 +0200 | [diff] [blame] | 445 | ADD_CUSTOM_TARGET(lcov |
Gilles Peskine | cb33076 | 2022-11-30 17:52:01 +0100 | [diff] [blame] | 446 | COMMAND scripts/lcov.sh |
Manuel Pégourié-Gonnard | 5fe51d7 | 2015-07-01 16:59:56 +0200 | [diff] [blame] | 447 | ) |
| 448 | |
| 449 | ADD_CUSTOM_TARGET(memcheck |
| 450 | COMMAND sed -i.bak s+/usr/bin/valgrind+`which valgrind`+ DartConfiguration.tcl |
| 451 | COMMAND ctest -O memcheck.log -D ExperimentalMemCheck |
| 452 | COMMAND tail -n1 memcheck.log | grep 'Memory checking results:' > /dev/null |
| 453 | COMMAND rm -f memcheck.log |
| 454 | COMMAND mv DartConfiguration.tcl.bak DartConfiguration.tcl |
| 455 | ) |
| 456 | endif(UNIX) |
Gilles Peskine | 8405257 | 2018-03-21 12:12:47 +0100 | [diff] [blame] | 457 | |
Renz Christian Bagaporo | d8a40b5 | 2019-04-28 13:51:37 +0800 | [diff] [blame] | 458 | # Make scripts needed for testing available in an out-of-source build. |
| 459 | if (NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) |
| 460 | link_to_source(scripts) |
| 461 | # Copy (don't link) DartConfiguration.tcl, needed for memcheck, to |
| 462 | # keep things simple with the sed commands in the memcheck target. |
| 463 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/DartConfiguration.tcl |
| 464 | ${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl COPYONLY) |
| 465 | endif() |
Gilles Peskine | 8405257 | 2018-03-21 12:12:47 +0100 | [diff] [blame] | 466 | endif() |
Chris Kay | d259e34 | 2021-03-25 16:03:25 +0000 | [diff] [blame] | 467 | |
Antonio de Angelis | 2869c67 | 2021-12-07 20:45:55 +0000 | [diff] [blame] | 468 | if(NOT DISABLE_PACKAGE_CONFIG_AND_INSTALL) |
| 469 | configure_package_config_file( |
| 470 | "cmake/MbedTLSConfig.cmake.in" |
| 471 | "cmake/MbedTLSConfig.cmake" |
| 472 | INSTALL_DESTINATION "cmake") |
Chris Kay | d259e34 | 2021-03-25 16:03:25 +0000 | [diff] [blame] | 473 | |
Antonio de Angelis | 2869c67 | 2021-12-07 20:45:55 +0000 | [diff] [blame] | 474 | write_basic_package_version_file( |
| 475 | "cmake/MbedTLSConfigVersion.cmake" |
| 476 | COMPATIBILITY SameMajorVersion |
Minos Galanakis | e62ef05 | 2025-03-18 17:11:54 +0000 | [diff] [blame] | 477 | VERSION 3.6.3) |
Chris Kay | d259e34 | 2021-03-25 16:03:25 +0000 | [diff] [blame] | 478 | |
Antonio de Angelis | 2869c67 | 2021-12-07 20:45:55 +0000 | [diff] [blame] | 479 | install( |
| 480 | FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/MbedTLSConfig.cmake" |
| 481 | "${CMAKE_CURRENT_BINARY_DIR}/cmake/MbedTLSConfigVersion.cmake" |
Issam E. Maghni | 760f3a0 | 2022-11-19 18:34:01 +0000 | [diff] [blame] | 482 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/MbedTLS") |
Chris Kay | d259e34 | 2021-03-25 16:03:25 +0000 | [diff] [blame] | 483 | |
Antonio de Angelis | 2869c67 | 2021-12-07 20:45:55 +0000 | [diff] [blame] | 484 | export( |
| 485 | EXPORT MbedTLSTargets |
| 486 | NAMESPACE MbedTLS:: |
| 487 | FILE "cmake/MbedTLSTargets.cmake") |
Chris Kay | d259e34 | 2021-03-25 16:03:25 +0000 | [diff] [blame] | 488 | |
Antonio de Angelis | 2869c67 | 2021-12-07 20:45:55 +0000 | [diff] [blame] | 489 | install( |
| 490 | EXPORT MbedTLSTargets |
| 491 | NAMESPACE MbedTLS:: |
Issam E. Maghni | 760f3a0 | 2022-11-19 18:34:01 +0000 | [diff] [blame] | 492 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/MbedTLS" |
Antonio de Angelis | 2869c67 | 2021-12-07 20:45:55 +0000 | [diff] [blame] | 493 | FILE "MbedTLSTargets.cmake") |
Chris Kay | d259e34 | 2021-03-25 16:03:25 +0000 | [diff] [blame] | 494 | |
Antonio de Angelis | 2869c67 | 2021-12-07 20:45:55 +0000 | [diff] [blame] | 495 | if(CMAKE_VERSION VERSION_GREATER 3.15 OR CMAKE_VERSION VERSION_EQUAL 3.15) |
| 496 | # Do not export the package by default |
| 497 | cmake_policy(SET CMP0090 NEW) |
Chris Kay | d259e34 | 2021-03-25 16:03:25 +0000 | [diff] [blame] | 498 | |
Antonio de Angelis | 2869c67 | 2021-12-07 20:45:55 +0000 | [diff] [blame] | 499 | # Make this package visible to the system |
| 500 | export(PACKAGE MbedTLS) |
| 501 | endif() |
Chris Kay | d259e34 | 2021-03-25 16:03:25 +0000 | [diff] [blame] | 502 | endif() |