blob: b88bdca0f47c6ff70c9c8bece3068aca6e9fd8c3 [file] [log] [blame]
Ronald Cron701faac2024-07-20 14:43:53 +02001#
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# - 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
Ronald Cron97d05e52024-07-20 15:02:50 +020016# mbedcrypto and apidoc targets.
Ronald Cron701faac2024-07-20 14:43:53 +020017#
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.
21cmake_minimum_required(VERSION 3.5.1)
22
23include(CMakePackageConfigHelpers)
24
25# Include convenience functions for printing properties and variables, like
26# cmake_print_properties(), cmake_print_variables().
27include(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.
32cmake_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.
38cmake_policy(SET CMP0012 NEW)
39
40if(TEST_CPP)
41 project("Mbed TLS"
42 LANGUAGES C CXX
43 VERSION 4.0.0
44 )
45else()
46 project("Mbed TLS"
47 LANGUAGES C
48 VERSION 4.0.0
49 )
50endif()
51
52include(GNUInstallDirs)
53
54# Determine if Mbed TLS is being built as a subproject using add_subdirectory()
55if(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()
60endif()
61
62# Set the project and framework root directory.
63set(MBEDTLS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
64set(MBEDTLS_FRAMEWORK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/framework)
65
66option(ENABLE_PROGRAMS "Build Mbed TLS programs." ON)
67
68option(UNSAFE_BUILD "Allow unsafe builds. These builds ARE NOT SECURE." OFF)
69option(MBEDTLS_FATAL_WARNINGS "Compiler warnings treated as errors" ON)
70if(CMAKE_HOST_WIN32)
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.
74 option(GEN_FILES "Generate the auto-generated files as needed" OFF) # off in development
75else()
76 option(GEN_FILES "Generate the auto-generated files as needed" ON)
77endif()
78
Ronald Cron4c3fa0a2024-07-30 10:50:39 +020079# Support for package config and install to be added later.
80option(DISABLE_PACKAGE_CONFIG_AND_INSTALL "Disable package configuration, target export and installation" ON)
Ronald Cron701faac2024-07-20 14:43:53 +020081
82if (CMAKE_C_SIMULATE_ID)
83 set(COMPILER_ID ${CMAKE_C_SIMULATE_ID})
84else()
85 set(COMPILER_ID ${CMAKE_C_COMPILER_ID})
86endif(CMAKE_C_SIMULATE_ID)
87
88string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${COMPILER_ID}")
89string(REGEX MATCH "GNU" CMAKE_COMPILER_IS_GNU "${COMPILER_ID}")
90string(REGEX MATCH "IAR" CMAKE_COMPILER_IS_IAR "${COMPILER_ID}")
91string(REGEX MATCH "MSVC" CMAKE_COMPILER_IS_MSVC "${COMPILER_ID}")
92
93# the test suites currently have compile errors with MSVC
94if(CMAKE_COMPILER_IS_MSVC)
95 option(ENABLE_TESTING "Build Mbed TLS tests." OFF)
96else()
97 option(ENABLE_TESTING "Build Mbed TLS tests." ON)
98endif()
99
100option(USE_STATIC_MBEDTLS_LIBRARY "Build Mbed TLS static library." ON)
101option(USE_SHARED_MBEDTLS_LIBRARY "Build Mbed TLS shared library." OFF)
102option(LINK_WITH_PTHREAD "Explicitly link Mbed TLS library to pthread." OFF)
103option(LINK_WITH_TRUSTED_STORAGE "Explicitly link Mbed TLS library to trusted_storage." OFF)
104
105set(mbedcrypto_target "${MBEDTLS_TARGET_PREFIX}mbedcrypto")
106if (USE_STATIC_MBEDTLS_LIBRARY)
107 set(mbedcrypto_static_target ${mbedcrypto_target})
108endif()
109if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
110 string(APPEND mbedcrypto_static_target "_static")
111endif()
112
113# Warning string - created as a list for compatibility with CMake 2.8
114set(CTR_DRBG_128_BIT_KEY_WARN_L1 "**** WARNING! MBEDTLS_CTR_DRBG_USE_128_BIT_KEY defined!\n")
115set(CTR_DRBG_128_BIT_KEY_WARN_L2 "**** Using 128-bit keys for CTR_DRBG limits the security of generated\n")
116set(CTR_DRBG_128_BIT_KEY_WARN_L3 "**** keys and operations that use random values generated to 128-bit security\n")
117
118set(CTR_DRBG_128_BIT_KEY_WARNING "${WARNING_BORDER}"
119 "${CTR_DRBG_128_BIT_KEY_WARN_L1}"
120 "${CTR_DRBG_128_BIT_KEY_WARN_L2}"
121 "${CTR_DRBG_128_BIT_KEY_WARN_L3}"
122 "${WARNING_BORDER}")
123
124# Python 3 is only needed here to check for configuration warnings.
125if(NOT CMAKE_VERSION VERSION_LESS 3.15.0)
126 set(Python3_FIND_STRATEGY LOCATION)
127 find_package(Python3 COMPONENTS Interpreter)
128 if(Python3_Interpreter_FOUND)
129 set(MBEDTLS_PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
130 endif()
131else()
132 find_package(PythonInterp 3)
133 if(PYTHONINTERP_FOUND)
134 set(MBEDTLS_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
135 endif()
136endif()
137if(MBEDTLS_PYTHON_EXECUTABLE)
138
139 # If 128-bit keys are configured for CTR_DRBG, display an appropriate warning
140 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
141 RESULT_VARIABLE result)
142 if(${result} EQUAL 0)
143 message(WARNING ${CTR_DRBG_128_BIT_KEY_WARNING})
144 endif()
145
146endif()
147
148# We now potentially need to link all executables against PThreads, if available
149set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
150set(THREADS_PREFER_PTHREAD_FLAG TRUE)
151find_package(Threads)
152
153# If this is the root project add longer list of available CMAKE_BUILD_TYPE values
154if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
155 set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}
156 CACHE STRING "Choose the type of build: None Debug Release Coverage ASan ASanDbg MemSan MemSanDbg Check CheckFull TSan TSanDbg"
157 FORCE)
158endif()
159
160# Make MBEDTLS_CONFIG_FILE and MBEDTLS_USER_CONFIG_FILE into PATHs
161set(MBEDTLS_CONFIG_FILE "" CACHE FILEPATH "Mbed TLS config file (overrides default).")
162set(MBEDTLS_USER_CONFIG_FILE "" CACHE FILEPATH "Mbed TLS user config file (appended to default).")
163
164# Create a symbolic link from ${base_name} in the binary directory
165# to the corresponding path in the source directory.
166# Note: Copies the file(s) on Windows.
167function(link_to_source base_name)
168 set(link "${CMAKE_CURRENT_BINARY_DIR}/${base_name}")
169 set(target "${CMAKE_CURRENT_SOURCE_DIR}/${base_name}")
170
171 # Linking to non-existent file is not desirable. At best you will have a
172 # dangling link, but when building in tree, this can create a symbolic link
173 # to itself.
174 if (EXISTS ${target} AND NOT EXISTS ${link})
175 if (CMAKE_HOST_UNIX)
176 execute_process(COMMAND ln -s ${target} ${link}
177 RESULT_VARIABLE result
178 ERROR_VARIABLE output)
179
180 if (NOT ${result} EQUAL 0)
181 message(FATAL_ERROR "Could not create symbolic link for: ${target} --> ${output}")
182 endif()
183 else()
184 if (IS_DIRECTORY ${target})
185 file(GLOB_RECURSE files FOLLOW_SYMLINKS LIST_DIRECTORIES false RELATIVE ${target} "${target}/*")
186 foreach(file IN LISTS files)
187 configure_file("${target}/${file}" "${link}/${file}" COPYONLY)
188 endforeach(file)
189 else()
190 configure_file(${target} ${link} COPYONLY)
191 endif()
192 endif()
193 endif()
194endfunction(link_to_source)
195
196# Get the filename without the final extension (i.e. convert "a.b.c" to "a.b")
197function(get_name_without_last_ext dest_var full_name)
198 # Split into a list on '.' (but a cmake list is just a ';'-separated string)
199 string(REPLACE "." ";" ext_parts "${full_name}")
200 # Remove the last item if there are more than one
201 list(LENGTH ext_parts ext_parts_len)
202 if (${ext_parts_len} GREATER "1")
203 math(EXPR ext_parts_last_item "${ext_parts_len} - 1")
204 list(REMOVE_AT ext_parts ${ext_parts_last_item})
205 endif()
206 # Convert back to a string by replacing separators with '.'
207 string(REPLACE ";" "." no_ext_name "${ext_parts}")
208 # Copy into the desired variable
209 set(${dest_var} ${no_ext_name} PARENT_SCOPE)
210endfunction(get_name_without_last_ext)
211
212include(CheckCCompilerFlag)
213
214set(CMAKE_C_EXTENSIONS OFF)
215set(CMAKE_C_STANDARD 99)
216
217if(CMAKE_COMPILER_IS_GNU)
218 # some warnings we want are not available with old GCC versions
219 # note: starting with CMake 2.8 we could use CMAKE_C_COMPILER_VERSION
220 execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
221 OUTPUT_VARIABLE GCC_VERSION)
222 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wwrite-strings -Wmissing-prototypes")
223 if (GCC_VERSION VERSION_GREATER 3.0 OR GCC_VERSION VERSION_EQUAL 3.0)
224 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat=2 -Wno-format-nonliteral")
225 endif()
226 if (GCC_VERSION VERSION_GREATER 4.3 OR GCC_VERSION VERSION_EQUAL 4.3)
227 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wvla")
228 endif()
229 if (GCC_VERSION VERSION_GREATER 4.5 OR GCC_VERSION VERSION_EQUAL 4.5)
230 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wlogical-op")
231 endif()
232 if (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8)
233 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
234 endif()
235 if (GCC_VERSION VERSION_GREATER 5.0)
236 CHECK_C_COMPILER_FLAG("-Wformat-signedness" C_COMPILER_SUPPORTS_WFORMAT_SIGNEDNESS)
237 if(C_COMPILER_SUPPORTS_WFORMAT_SIGNEDNESS)
238 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-signedness")
239 endif()
240 endif()
241 if (GCC_VERSION VERSION_GREATER 7.0 OR GCC_VERSION VERSION_EQUAL 7.0)
242 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-overflow=2 -Wformat-truncation")
243 endif()
244 set(CMAKE_C_FLAGS_RELEASE "-O2")
245 set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
246 set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
247 set(CMAKE_C_FLAGS_ASAN "-fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O3")
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")
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")
251 set(CMAKE_C_FLAGS_CHECK "-Os")
252 set(CMAKE_C_FLAGS_CHECKFULL "${CMAKE_C_FLAGS_CHECK} -Wcast-qual")
253endif(CMAKE_COMPILER_IS_GNU)
254
255if(CMAKE_COMPILER_IS_CLANG)
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")
257 set(CMAKE_C_FLAGS_RELEASE "-O2")
258 set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
259 set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
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")
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")
266 set(CMAKE_C_FLAGS_CHECK "-Os")
267endif(CMAKE_COMPILER_IS_CLANG)
268
269if(CMAKE_COMPILER_IS_IAR)
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")
273endif(CMAKE_COMPILER_IS_IAR)
274
275if(CMAKE_COMPILER_IS_MSVC)
276 # Strictest warnings, UTF-8 source and execution charset
277 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /utf-8")
278endif(CMAKE_COMPILER_IS_MSVC)
279
280if(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")
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)
292 endif(CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNU)
293
294 if (CMAKE_COMPILER_IS_IAR)
295 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --warnings_are_errors")
296 endif(CMAKE_COMPILER_IS_IAR)
297endif(MBEDTLS_FATAL_WARNINGS)
298
299if(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()
306endif()
307
308if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
309 if(CMAKE_COMPILER_IS_GNU OR CMAKE_COMPILER_IS_CLANG)
310 set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
311 endif(CMAKE_COMPILER_IS_GNU OR CMAKE_COMPILER_IS_CLANG)
312endif(CMAKE_BUILD_TYPE STREQUAL "Coverage")
313
314if(LIB_INSTALL_DIR)
315 set(CMAKE_INSTALL_LIBDIR "${LIB_INSTALL_DIR}")
316endif()
317
318if (NOT EXISTS "${MBEDTLS_FRAMEWORK_DIR}/CMakeLists.txt")
319 message(FATAL_ERROR "${MBEDTLS_FRAMEWORK_DIR}/CMakeLists.txt not found. Run `git submodule update --init` from the source tree to fetch the submodule contents.")
320endif()
321add_subdirectory(framework)
322
323add_subdirectory(include)
324
325add_subdirectory(tf-psa-crypto)
326
327add_subdirectory(library)
328
Ronald Cron701faac2024-07-20 14:43:53 +0200329#
330# The C files in tests/src directory contain test code shared among test suites
331# and programs. This shared test code is compiled and linked to test suites and
332# programs objects as a set of compiled objects. The compiled objects are NOT
333# built into a library that the test suite and program objects would link
Ronald Cron97d05e52024-07-20 15:02:50 +0200334# against as they link against the mbedcrypto library. The reason is that such
335# library is expected to have mutual dependencies with the aforementioned
336# library and that there is as of today no portable way of handling such
337# dependencies (only toolchain specific solutions).
Ronald Cron701faac2024-07-20 14:43:53 +0200338#
339# Thus the below definition of the `mbedtls_test` CMake library of objects
340# target. This library of objects is used by tests and programs CMake files
341# to define the test executables.
342#
343if(ENABLE_TESTING OR ENABLE_PROGRAMS)
344 file(GLOB MBEDTLS_TEST_FILES
345 ${CMAKE_CURRENT_SOURCE_DIR}/tests/src/*.c
346 ${CMAKE_CURRENT_SOURCE_DIR}/tests/src/drivers/*.c)
347 add_library(mbedtls_test OBJECT ${MBEDTLS_TEST_FILES})
348 if(GEN_FILES)
349 add_custom_command(
350 OUTPUT
351 ${CMAKE_CURRENT_SOURCE_DIR}/tests/src/test_keys.h
352 WORKING_DIRECTORY
353 ${CMAKE_CURRENT_SOURCE_DIR}/tests
354 COMMAND
355 "${MBEDTLS_PYTHON_EXECUTABLE}"
356 "${MBEDTLS_FRAMEWORK_DIR}/scripts/generate_test_keys.py"
357 "--output"
358 "${CMAKE_CURRENT_SOURCE_DIR}/tests/src/test_keys.h"
359 DEPENDS
360 ${MBEDTLS_FRAMEWORK_DIR}/scripts/generate_test_keys.py
361 )
362 add_custom_target(test_keys_header DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/src/test_keys.h)
Ronald Cron97d05e52024-07-20 15:02:50 +0200363
Ronald Cron701faac2024-07-20 14:43:53 +0200364 add_custom_command(
365 OUTPUT
366 ${CMAKE_CURRENT_SOURCE_DIR}/tests/src/test_certs.h
367 WORKING_DIRECTORY
368 ${CMAKE_CURRENT_SOURCE_DIR}/tests
369 COMMAND
370 "${MBEDTLS_PYTHON_EXECUTABLE}"
371 "${MBEDTLS_FRAMEWORK_DIR}/scripts/generate_test_cert_macros.py"
372 "--output"
373 "${CMAKE_CURRENT_SOURCE_DIR}/tests/src/test_certs.h"
374 DEPENDS
375 ${MBEDTLS_FRAMEWORK_DIR}/scripts/generate_test_cert_macros.py
376 )
377 add_custom_target(test_certs_header DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/src/test_certs.h)
378 add_dependencies(mbedtls_test test_keys_header test_certs_header)
379 endif()
380 target_include_directories(mbedtls_test
381 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests/include
382 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
383 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tf-psa-crypto/include
384 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tf-psa-crypto/drivers/builtin/include
Ronald Cron701faac2024-07-20 14:43:53 +0200385 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tf-psa-crypto/core
386 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tf-psa-crypto/drivers/builtin/src)
387 # Request C11, needed for memory poisoning tests
388 set_target_properties(mbedtls_test PROPERTIES C_STANDARD 11)
389
Ronald Cron701faac2024-07-20 14:43:53 +0200390 # Pass-through MBEDTLS_CONFIG_FILE and MBEDTLS_USER_CONFIG_FILE
391 if(MBEDTLS_CONFIG_FILE)
392 target_compile_definitions(mbedtls_test
393 PUBLIC MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}")
Ronald Cron701faac2024-07-20 14:43:53 +0200394 endif()
395 if(MBEDTLS_USER_CONFIG_FILE)
396 target_compile_definitions(mbedtls_test
397 PUBLIC MBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}")
Ronald Cron701faac2024-07-20 14:43:53 +0200398 endif()
399endif()
400
401if(ENABLE_PROGRAMS)
Ronald Cron701faac2024-07-20 14:43:53 +0200402 add_subdirectory(programs)
403endif()
404
Ronald Cron701faac2024-07-20 14:43:53 +0200405if(ENABLE_TESTING)
406 enable_testing()
407
408 add_subdirectory(tests)
409
410 # additional convenience targets for Unix only
411 if(UNIX)
Ronald Cron701faac2024-07-20 14:43:53 +0200412 ADD_CUSTOM_TARGET(memcheck
413 COMMAND sed -i.bak s+/usr/bin/valgrind+`which valgrind`+ DartConfiguration.tcl
414 COMMAND ctest -O memcheck.log -D ExperimentalMemCheck
415 COMMAND tail -n1 memcheck.log | grep 'Memory checking results:' > /dev/null
416 COMMAND rm -f memcheck.log
417 COMMAND mv DartConfiguration.tcl.bak DartConfiguration.tcl
418 )
419 endif(UNIX)
420
421 # Make scripts needed for testing available in an out-of-source build.
422 if (NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
423 link_to_source(scripts)
424 # Copy (don't link) DartConfiguration.tcl, needed for memcheck, to
425 # keep things simple with the sed commands in the memcheck target.
426 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/DartConfiguration.tcl
427 ${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl COPYONLY)
428 endif()
429endif()