mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-24 12:15:28 +00:00
8dd1690993
Resolve conflicts by performing the following operations: - Reject changes related to building a crypto submodule, since Mbed Crypto is the crypto submodule. - Reject X.509, NET, and SSL changes. - Reject changes to README, as Mbed Crypto is a different project from Mbed TLS, with a different README. - Avoid adding mention of ssl-opt.sh in a comment near some modified code in include/CMakeLists.txt (around where ENABLE_TESTING as added). - Align config.pl in Mbed TLS with config.pl in Mbed Crypto where PSA options are concerned, to make future merging easier. There is no reason for the two to be different in this regard, now that Mbed TLS always depends on Mbed Crypto. Remaining differences are only the PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER option and the absence of X.509, NET, and SSL related options in Mbed Crypto's config.pl. - Align config.h in Mbed Crypto with Mbed TLS's copy, with a few notable exceptions: - Leave CMAC on by default. - Leave storage on by default (including ITS emulation). - Avoid documenting the PSA Crypto API as is in beta stage in documentation for MBEDTLS_PSA_CRYPTO_C. The only remaining differences are a lack of X.509, NET, and SSL options in Mbed Crypto's config.h, as well as an additional Mbed-Crypto-specific PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER option. Documentation for the check params feature and related macros is also updated to match Mbed TLS's description. - Reject tests/data_files/Makefile changes to generate DER versions of CRTs and keys, as none of those are used by Mbed Crypto tests. - Add the "no PEM and no filesystem" test to all.sh, without ssl-opt.sh run, as Mbed Crypto doesn't have ssl-opt.sh. Also remove use of PSA Crypto storage and ITS emulation, since those depend on filesystem support. - Reject addition of test when no ciphersuites have MAC to all.sh, as the option being tested, MBEDTLS_SSL_SOME_MODES_USE_MAC, is not present in Mbed Crypto. - Use baremetal config in all.sh, as Mbed Crypto's baremetal configuration does exclude the net module (as it doesn't exist in Mbed Crypto) - Reject cmake_subproject_build changes, continuing to link only libmbedcrypto. - Reject changes to visualc and associated templates. Mbed Crypto doesn't need additional logic to handle submodule-sourced headers. - Avoid adding fuzzers from Mbed TLS. The only relevant fuzzers are the privkey and pubkey fuzzers, but non-trivial work would be required to integrate those into Mbed Crypto (more than is comfortable in a merge commit). - Reject addition of Docker wrappers for compat.sh and ssl-opt.sh, as those are not present in Mbed Crypto. - Remove calls to SSL-related scripts from basic-in-docker.sh Fix test errors by performing the following: - Avoid using a link that Doxygen can't seem to resolve in Mbed Crypto, but can resolve in Mbed TLS. In documentation for MBEDTLS_CHECK_PARAMS, don't attempt to link to MBEDTLS_PARAM_FAILED. * origin/development: (339 commits) Do not build fuzz on windows No booleans and import config Removing space before opening parenthesis Style corrections Syntax fix Fixes warnings from MSVC Add a linker flag to enable gcov in basic-build-test.sh Update crypto submodule to a revision with the HAVEGE header changes Test with MBEDTLS_ECP_RESTARTABLE Allow TODO in code Use the docstring in the command line help Split _abi_compliance_command into smaller functions Record the commits that were compared Document how to build the typical argument for -s Allow running /somewhere/else/path/to/abi_check.py tests: Limit each log to 10 GiB Warn if VLAs are used Remove redundant compiler flag Consistently spell -Wextra Fix parsing issue when int parameter is in base 16 ...
235 lines
9.7 KiB
CMake
235 lines
9.7 KiB
CMake
cmake_minimum_required(VERSION 2.6)
|
|
if(TEST_CPP)
|
|
project("mbed TLS" C CXX)
|
|
else()
|
|
project("mbed TLS" C)
|
|
endif()
|
|
|
|
# Set the project root directory.
|
|
set(MBEDTLS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
option(ENABLE_PROGRAMS "Build mbed TLS programs." ON)
|
|
|
|
option(UNSAFE_BUILD "Allow unsafe builds. These builds ARE NOT SECURE." OFF)
|
|
|
|
string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}")
|
|
string(REGEX MATCH "GNU" CMAKE_COMPILER_IS_GNU "${CMAKE_C_COMPILER_ID}")
|
|
string(REGEX MATCH "IAR" CMAKE_COMPILER_IS_IAR "${CMAKE_C_COMPILER_ID}")
|
|
string(REGEX MATCH "MSVC" CMAKE_COMPILER_IS_MSVC "${CMAKE_C_COMPILER_ID}")
|
|
|
|
# the test suites currently have compile errors with MSVC
|
|
if(CMAKE_COMPILER_IS_MSVC)
|
|
option(ENABLE_TESTING "Build mbed TLS tests." OFF)
|
|
else()
|
|
option(ENABLE_TESTING "Build mbed TLS tests." ON)
|
|
endif()
|
|
|
|
# Warning string - created as a list for compatibility with CMake 2.8
|
|
set(WARNING_BORDER "*******************************************************\n")
|
|
set(NULL_ENTROPY_WARN_L1 "**** WARNING! MBEDTLS_TEST_NULL_ENTROPY defined!\n")
|
|
set(NULL_ENTROPY_WARN_L2 "**** THIS BUILD HAS NO DEFINED ENTROPY SOURCES\n")
|
|
set(NULL_ENTROPY_WARN_L3 "**** AND IS *NOT* SUITABLE FOR PRODUCTION USE\n")
|
|
|
|
set(NULL_ENTROPY_WARNING "${WARNING_BORDER}"
|
|
"${NULL_ENTROPY_WARN_L1}"
|
|
"${NULL_ENTROPY_WARN_L2}"
|
|
"${NULL_ENTROPY_WARN_L3}"
|
|
"${WARNING_BORDER}")
|
|
|
|
set(CTR_DRBG_128_BIT_KEY_WARN_L1 "**** WARNING! MBEDTLS_CTR_DRBG_USE_128_BIT_KEY defined!\n")
|
|
set(CTR_DRBG_128_BIT_KEY_WARN_L2 "**** Using 128-bit keys for CTR_DRBG limits the security of generated\n")
|
|
set(CTR_DRBG_128_BIT_KEY_WARN_L3 "**** keys and operations that use random values generated to 128-bit security\n")
|
|
|
|
set(CTR_DRBG_128_BIT_KEY_WARNING "${WARNING_BORDER}"
|
|
"${CTR_DRBG_128_BIT_KEY_WARN_L1}"
|
|
"${CTR_DRBG_128_BIT_KEY_WARN_L2}"
|
|
"${CTR_DRBG_128_BIT_KEY_WARN_L3}"
|
|
"${WARNING_BORDER}")
|
|
|
|
find_package(PythonInterp)
|
|
find_package(Perl)
|
|
if(PERL_FOUND)
|
|
|
|
# If 128-bit keys are configured for CTR_DRBG, display an appropriate warning
|
|
execute_process(COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/config.pl -f ${CMAKE_CURRENT_SOURCE_DIR}/include/mbedtls/config.h get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
|
|
RESULT_VARIABLE result)
|
|
if(${result} EQUAL 0)
|
|
message(WARNING ${CTR_DRBG_128_BIT_KEY_WARNING})
|
|
endif()
|
|
|
|
# If NULL Entropy is configured, display an appropriate warning
|
|
execute_process(COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/config.pl -f ${CMAKE_CURRENT_SOURCE_DIR}/include/mbedtls/config.h get MBEDTLS_TEST_NULL_ENTROPY
|
|
RESULT_VARIABLE result)
|
|
if(${result} EQUAL 0)
|
|
message(WARNING ${NULL_ENTROPY_WARNING})
|
|
|
|
if(NOT UNSAFE_BUILD)
|
|
message(FATAL_ERROR "\
|
|
\n\
|
|
Warning! You have enabled MBEDTLS_TEST_NULL_ENTROPY. \
|
|
This option is not safe for production use and negates all security \
|
|
It is intended for development use only. \
|
|
\n\
|
|
To confirm you want to build with this option, re-run cmake with the \
|
|
option: \n\
|
|
cmake -DUNSAFE_BUILD=ON ")
|
|
|
|
return()
|
|
endif()
|
|
endif()
|
|
endif()
|
|
|
|
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}
|
|
CACHE STRING "Choose the type of build: None Debug Release Coverage ASan ASanDbg MemSan MemSanDbg Check CheckFull"
|
|
FORCE)
|
|
|
|
# Create a symbolic link from ${base_name} in the binary directory
|
|
# to the corresponding path in the source directory.
|
|
function(link_to_source base_name)
|
|
# Get OS dependent path to use in `execute_process`
|
|
if (CMAKE_HOST_WIN32)
|
|
#mklink is an internal command of cmd.exe it can only work with \
|
|
string(REPLACE "/" "\\" link "${CMAKE_CURRENT_BINARY_DIR}/${base_name}")
|
|
string(REPLACE "/" "\\" target "${CMAKE_CURRENT_SOURCE_DIR}/${base_name}")
|
|
else()
|
|
set(link "${CMAKE_CURRENT_BINARY_DIR}/${base_name}")
|
|
set(target "${CMAKE_CURRENT_SOURCE_DIR}/${base_name}")
|
|
endif()
|
|
|
|
if (NOT EXISTS ${link})
|
|
if (CMAKE_HOST_UNIX)
|
|
set(command ln -s ${target} ${link})
|
|
else()
|
|
if (IS_DIRECTORY ${target})
|
|
set(command cmd.exe /c mklink /j ${link} ${target})
|
|
else()
|
|
set(command cmd.exe /c mklink /h ${link} ${target})
|
|
endif()
|
|
endif()
|
|
|
|
execute_process(COMMAND ${command}
|
|
RESULT_VARIABLE result
|
|
ERROR_VARIABLE output)
|
|
|
|
if (NOT ${result} EQUAL 0)
|
|
message(FATAL_ERROR "Could not create symbolic link for: ${target} --> ${output}")
|
|
endif()
|
|
endif()
|
|
endfunction(link_to_source)
|
|
|
|
string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}")
|
|
|
|
if(CMAKE_COMPILER_IS_GNU)
|
|
# some warnings we want are not available with old GCC versions
|
|
# note: starting with CMake 2.8 we could use CMAKE_C_COMPILER_VERSION
|
|
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
|
|
OUTPUT_VARIABLE GCC_VERSION)
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wwrite-strings")
|
|
if (GCC_VERSION VERSION_GREATER 4.3 OR GCC_VERSION VERSION_EQUAL 4.3)
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wvla")
|
|
endif()
|
|
if (GCC_VERSION VERSION_GREATER 4.5 OR GCC_VERSION VERSION_EQUAL 4.5)
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wlogical-op")
|
|
endif()
|
|
if (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8)
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
|
|
endif()
|
|
set(CMAKE_C_FLAGS_RELEASE "-O2")
|
|
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
|
|
set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
|
|
set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -O3")
|
|
set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls ")
|
|
set(CMAKE_C_FLAGS_CHECK "-Werror -Os")
|
|
set(CMAKE_C_FLAGS_CHECKFULL "${CMAKE_C_FLAGS_CHECK} -Wcast-qual")
|
|
endif(CMAKE_COMPILER_IS_GNU)
|
|
|
|
if(CMAKE_COMPILER_IS_CLANG)
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla")
|
|
set(CMAKE_C_FLAGS_RELEASE "-O2")
|
|
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
|
|
set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
|
|
set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O3")
|
|
set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover=all -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls ")
|
|
set(CMAKE_C_FLAGS_MEMSAN "-Werror -fsanitize=memory -O3")
|
|
set(CMAKE_C_FLAGS_MEMSANDBG "-Werror -fsanitize=memory -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2")
|
|
set(CMAKE_C_FLAGS_CHECK "-Werror -Os")
|
|
endif(CMAKE_COMPILER_IS_CLANG)
|
|
|
|
if(CMAKE_COMPILER_IS_IAR)
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --warn_about_c_style_casts --warnings_are_errors -Ohz")
|
|
endif(CMAKE_COMPILER_IS_IAR)
|
|
|
|
if(CMAKE_COMPILER_IS_MSVC)
|
|
# Strictest warnings, and treat as errors
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3")
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
|
|
endif(CMAKE_COMPILER_IS_MSVC)
|
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
|
|
if(CMAKE_COMPILER_IS_GNU OR CMAKE_COMPILER_IS_CLANG)
|
|
set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
|
|
endif(CMAKE_COMPILER_IS_GNU OR CMAKE_COMPILER_IS_CLANG)
|
|
endif(CMAKE_BUILD_TYPE STREQUAL "Coverage")
|
|
|
|
if(LIB_INSTALL_DIR)
|
|
else()
|
|
set(LIB_INSTALL_DIR lib)
|
|
endif()
|
|
|
|
include_directories(include/)
|
|
include_directories(library/)
|
|
|
|
add_subdirectory(library)
|
|
add_subdirectory(include)
|
|
|
|
if(ENABLE_PROGRAMS)
|
|
add_subdirectory(programs)
|
|
endif()
|
|
|
|
ADD_CUSTOM_TARGET(apidoc
|
|
COMMAND doxygen mbedtls.doxyfile
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doxygen)
|
|
|
|
if(ENABLE_TESTING)
|
|
enable_testing()
|
|
|
|
add_subdirectory(tests)
|
|
|
|
# additional convenience targets for Unix only
|
|
if(UNIX)
|
|
|
|
ADD_CUSTOM_TARGET(covtest
|
|
COMMAND make test
|
|
COMMAND programs/test/selftest
|
|
)
|
|
|
|
ADD_CUSTOM_TARGET(lcov
|
|
COMMAND rm -rf Coverage
|
|
COMMAND lcov --capture --initial --directory library/CMakeFiles/mbedtls.dir -o files.info
|
|
COMMAND lcov --capture --directory library/CMakeFiles/mbedtls.dir -o tests.info
|
|
COMMAND lcov --add-tracefile files.info --add-tracefile tests.info -o all.info
|
|
COMMAND lcov --remove all.info -o final.info '*.h'
|
|
COMMAND gendesc tests/Descriptions.txt -o descriptions
|
|
COMMAND genhtml --title "mbed TLS" --description-file descriptions --keep-descriptions --legend --no-branch-coverage -o Coverage final.info
|
|
COMMAND rm -f files.info tests.info all.info final.info descriptions
|
|
)
|
|
|
|
ADD_CUSTOM_TARGET(memcheck
|
|
COMMAND sed -i.bak s+/usr/bin/valgrind+`which valgrind`+ DartConfiguration.tcl
|
|
COMMAND ctest -O memcheck.log -D ExperimentalMemCheck
|
|
COMMAND tail -n1 memcheck.log | grep 'Memory checking results:' > /dev/null
|
|
COMMAND rm -f memcheck.log
|
|
COMMAND mv DartConfiguration.tcl.bak DartConfiguration.tcl
|
|
)
|
|
endif(UNIX)
|
|
|
|
# Make scripts needed for testing available in an out-of-source build.
|
|
if (NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
|
|
link_to_source(scripts)
|
|
# Copy (don't link) DartConfiguration.tcl, needed for memcheck, to
|
|
# keep things simple with the sed commands in the memcheck target.
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/DartConfiguration.tcl
|
|
${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl COPYONLY)
|
|
endif()
|
|
endif()
|