mbed TLS Build
CMakeLists.txt@0:cdf462088d13, 2017-01-05 (annotated)
- Committer:
- markrad
- Date:
- Thu Jan 05 00:18:44 2017 +0000
- Revision:
- 0:cdf462088d13
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
markrad | 0:cdf462088d13 | 1 | cmake_minimum_required(VERSION 2.6) |
markrad | 0:cdf462088d13 | 2 | project("mbed TLS" C) |
markrad | 0:cdf462088d13 | 3 | |
markrad | 0:cdf462088d13 | 4 | option(USE_PKCS11_HELPER_LIBRARY "Build mbed TLS with the pkcs11-helper library." OFF) |
markrad | 0:cdf462088d13 | 5 | option(ENABLE_ZLIB_SUPPORT "Build mbed TLS with zlib library." OFF) |
markrad | 0:cdf462088d13 | 6 | |
markrad | 0:cdf462088d13 | 7 | option(ENABLE_PROGRAMS "Build mbed TLS programs." ON) |
markrad | 0:cdf462088d13 | 8 | |
markrad | 0:cdf462088d13 | 9 | option(UNSAFE_BUILD "Allow unsafe builds. These builds ARE NOT SECURE." OFF) |
markrad | 0:cdf462088d13 | 10 | |
markrad | 0:cdf462088d13 | 11 | # the test suites currently have compile errors with MSVC |
markrad | 0:cdf462088d13 | 12 | if(MSVC) |
markrad | 0:cdf462088d13 | 13 | option(ENABLE_TESTING "Build mbed TLS tests." OFF) |
markrad | 0:cdf462088d13 | 14 | else() |
markrad | 0:cdf462088d13 | 15 | option(ENABLE_TESTING "Build mbed TLS tests." ON) |
markrad | 0:cdf462088d13 | 16 | endif() |
markrad | 0:cdf462088d13 | 17 | |
markrad | 0:cdf462088d13 | 18 | # Warning string - created as a list for compatibility with CMake 2.8 |
markrad | 0:cdf462088d13 | 19 | set(WARNING_BORDER "*******************************************************\n") |
markrad | 0:cdf462088d13 | 20 | set(NULL_ENTROPY_WARN_L1 "**** WARNING! MBEDTLS_TEST_NULL_ENTROPY defined!\n") |
markrad | 0:cdf462088d13 | 21 | set(NULL_ENTROPY_WARN_L2 "**** THIS BUILD HAS NO DEFINED ENTROPY SOURCES\n") |
markrad | 0:cdf462088d13 | 22 | set(NULL_ENTROPY_WARN_L3 "**** AND IS *NOT* SUITABLE FOR PRODUCTION USE\n") |
markrad | 0:cdf462088d13 | 23 | |
markrad | 0:cdf462088d13 | 24 | set(NULL_ENTROPY_WARNING "${WARNING_BORDER}" |
markrad | 0:cdf462088d13 | 25 | "${NULL_ENTROPY_WARN_L1}" |
markrad | 0:cdf462088d13 | 26 | "${NULL_ENTROPY_WARN_L2}" |
markrad | 0:cdf462088d13 | 27 | "${NULL_ENTROPY_WARN_L3}" |
markrad | 0:cdf462088d13 | 28 | "${WARNING_BORDER}") |
markrad | 0:cdf462088d13 | 29 | |
markrad | 0:cdf462088d13 | 30 | find_package(Perl) |
markrad | 0:cdf462088d13 | 31 | if(PERL_FOUND) |
markrad | 0:cdf462088d13 | 32 | |
markrad | 0:cdf462088d13 | 33 | # If NULL Entropy is configured, display an appropriate warning |
markrad | 0:cdf462088d13 | 34 | execute_process(COMMAND ${PERL_EXECUTABLE} ${CMAKE_SOURCE_DIR}/scripts/config.pl -f ${CMAKE_SOURCE_DIR}/include/mbedtls/config.h get MBEDTLS_TEST_NULL_ENTROPY |
markrad | 0:cdf462088d13 | 35 | RESULT_VARIABLE result) |
markrad | 0:cdf462088d13 | 36 | if(${result} EQUAL 0) |
markrad | 0:cdf462088d13 | 37 | message(WARNING ${NULL_ENTROPY_WARNING}) |
markrad | 0:cdf462088d13 | 38 | |
markrad | 0:cdf462088d13 | 39 | if(NOT UNSAFE_BUILD) |
markrad | 0:cdf462088d13 | 40 | message(FATAL_ERROR "\ |
markrad | 0:cdf462088d13 | 41 | \n\ |
markrad | 0:cdf462088d13 | 42 | Warning! You have enabled MBEDTLS_TEST_NULL_ENTROPY. \ |
markrad | 0:cdf462088d13 | 43 | This option is not safe for production use and negates all security \ |
markrad | 0:cdf462088d13 | 44 | It is intended for development use only. \ |
markrad | 0:cdf462088d13 | 45 | \n\ |
markrad | 0:cdf462088d13 | 46 | To confirm you want to build with this option, re-run cmake with the \ |
markrad | 0:cdf462088d13 | 47 | option: \n\ |
markrad | 0:cdf462088d13 | 48 | cmake -DUNSAFE_BUILD=ON ") |
markrad | 0:cdf462088d13 | 49 | |
markrad | 0:cdf462088d13 | 50 | return() |
markrad | 0:cdf462088d13 | 51 | endif() |
markrad | 0:cdf462088d13 | 52 | endif() |
markrad | 0:cdf462088d13 | 53 | endif() |
markrad | 0:cdf462088d13 | 54 | |
markrad | 0:cdf462088d13 | 55 | set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} |
markrad | 0:cdf462088d13 | 56 | CACHE STRING "Choose the type of build: None Debug Release Coverage ASan ASanDbg MemSan MemSanDbg Check CheckFull" |
markrad | 0:cdf462088d13 | 57 | FORCE) |
markrad | 0:cdf462088d13 | 58 | |
markrad | 0:cdf462088d13 | 59 | string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}") |
markrad | 0:cdf462088d13 | 60 | |
markrad | 0:cdf462088d13 | 61 | if(CMAKE_COMPILER_IS_GNUCC) |
markrad | 0:cdf462088d13 | 62 | # some warnings we want are not available with old GCC versions |
markrad | 0:cdf462088d13 | 63 | # note: starting with CMake 2.8 we could use CMAKE_C_COMPILER_VERSION |
markrad | 0:cdf462088d13 | 64 | execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion |
markrad | 0:cdf462088d13 | 65 | OUTPUT_VARIABLE GCC_VERSION) |
markrad | 0:cdf462088d13 | 66 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings") |
markrad | 0:cdf462088d13 | 67 | if (GCC_VERSION VERSION_GREATER 4.5 OR GCC_VERSION VERSION_EQUAL 4.5) |
markrad | 0:cdf462088d13 | 68 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wlogical-op") |
markrad | 0:cdf462088d13 | 69 | endif() |
markrad | 0:cdf462088d13 | 70 | if (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8) |
markrad | 0:cdf462088d13 | 71 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow") |
markrad | 0:cdf462088d13 | 72 | endif() |
markrad | 0:cdf462088d13 | 73 | set(CMAKE_C_FLAGS_RELEASE "-O2") |
markrad | 0:cdf462088d13 | 74 | set(CMAKE_C_FLAGS_DEBUG "-O0 -g3") |
markrad | 0:cdf462088d13 | 75 | set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage") |
markrad | 0:cdf462088d13 | 76 | set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -O3") |
markrad | 0:cdf462088d13 | 77 | set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls ") |
markrad | 0:cdf462088d13 | 78 | set(CMAKE_C_FLAGS_CHECK "-Werror -Os") |
markrad | 0:cdf462088d13 | 79 | set(CMAKE_C_FLAGS_CHECKFULL "${CMAKE_C_FLAGS_CHECK} -Wcast-qual") |
markrad | 0:cdf462088d13 | 80 | endif(CMAKE_COMPILER_IS_GNUCC) |
markrad | 0:cdf462088d13 | 81 | |
markrad | 0:cdf462088d13 | 82 | if(CMAKE_COMPILER_IS_CLANG) |
markrad | 0:cdf462088d13 | 83 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow") |
markrad | 0:cdf462088d13 | 84 | set(CMAKE_C_FLAGS_RELEASE "-O2") |
markrad | 0:cdf462088d13 | 85 | set(CMAKE_C_FLAGS_DEBUG "-O0 -g3") |
markrad | 0:cdf462088d13 | 86 | set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage") |
markrad | 0:cdf462088d13 | 87 | set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover -O3") |
markrad | 0:cdf462088d13 | 88 | set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls ") |
markrad | 0:cdf462088d13 | 89 | set(CMAKE_C_FLAGS_MEMSAN "-Werror -fsanitize=memory -O3") |
markrad | 0:cdf462088d13 | 90 | set(CMAKE_C_FLAGS_MEMSANDBG "-Werror -fsanitize=memory -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2") |
markrad | 0:cdf462088d13 | 91 | set(CMAKE_C_FLAGS_CHECK "-Werror -Os") |
markrad | 0:cdf462088d13 | 92 | endif(CMAKE_COMPILER_IS_CLANG) |
markrad | 0:cdf462088d13 | 93 | |
markrad | 0:cdf462088d13 | 94 | if(MSVC) |
markrad | 0:cdf462088d13 | 95 | # Strictest warnings, and treat as errors |
markrad | 0:cdf462088d13 | 96 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3") |
markrad | 0:cdf462088d13 | 97 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX") |
markrad | 0:cdf462088d13 | 98 | endif(MSVC) |
markrad | 0:cdf462088d13 | 99 | |
markrad | 0:cdf462088d13 | 100 | if(CMAKE_BUILD_TYPE STREQUAL "Coverage") |
markrad | 0:cdf462088d13 | 101 | if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) |
markrad | 0:cdf462088d13 | 102 | set(CMAKE_SHARED_LINKER_FLAGS "--coverage") |
markrad | 0:cdf462088d13 | 103 | endif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) |
markrad | 0:cdf462088d13 | 104 | endif(CMAKE_BUILD_TYPE STREQUAL "Coverage") |
markrad | 0:cdf462088d13 | 105 | |
markrad | 0:cdf462088d13 | 106 | if(LIB_INSTALL_DIR) |
markrad | 0:cdf462088d13 | 107 | else() |
markrad | 0:cdf462088d13 | 108 | set(LIB_INSTALL_DIR lib) |
markrad | 0:cdf462088d13 | 109 | endif() |
markrad | 0:cdf462088d13 | 110 | |
markrad | 0:cdf462088d13 | 111 | include_directories(include/) |
markrad | 0:cdf462088d13 | 112 | |
markrad | 0:cdf462088d13 | 113 | if(ENABLE_ZLIB_SUPPORT) |
markrad | 0:cdf462088d13 | 114 | find_package(ZLIB) |
markrad | 0:cdf462088d13 | 115 | |
markrad | 0:cdf462088d13 | 116 | if(ZLIB_FOUND) |
markrad | 0:cdf462088d13 | 117 | include_directories(${ZLIB_INCLUDE_DIR}) |
markrad | 0:cdf462088d13 | 118 | endif(ZLIB_FOUND) |
markrad | 0:cdf462088d13 | 119 | endif(ENABLE_ZLIB_SUPPORT) |
markrad | 0:cdf462088d13 | 120 | |
markrad | 0:cdf462088d13 | 121 | add_subdirectory(library) |
markrad | 0:cdf462088d13 | 122 | add_subdirectory(include) |
markrad | 0:cdf462088d13 | 123 | |
markrad | 0:cdf462088d13 | 124 | if(ENABLE_PROGRAMS) |
markrad | 0:cdf462088d13 | 125 | add_subdirectory(programs) |
markrad | 0:cdf462088d13 | 126 | endif() |
markrad | 0:cdf462088d13 | 127 | |
markrad | 0:cdf462088d13 | 128 | ADD_CUSTOM_TARGET(apidoc |
markrad | 0:cdf462088d13 | 129 | COMMAND doxygen doxygen/mbedtls.doxyfile |
markrad | 0:cdf462088d13 | 130 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
markrad | 0:cdf462088d13 | 131 | |
markrad | 0:cdf462088d13 | 132 | if(ENABLE_TESTING) |
markrad | 0:cdf462088d13 | 133 | enable_testing() |
markrad | 0:cdf462088d13 | 134 | |
markrad | 0:cdf462088d13 | 135 | add_subdirectory(tests) |
markrad | 0:cdf462088d13 | 136 | |
markrad | 0:cdf462088d13 | 137 | # additional convenience targets for Unix only |
markrad | 0:cdf462088d13 | 138 | if(UNIX) |
markrad | 0:cdf462088d13 | 139 | |
markrad | 0:cdf462088d13 | 140 | ADD_CUSTOM_TARGET(covtest |
markrad | 0:cdf462088d13 | 141 | COMMAND make test |
markrad | 0:cdf462088d13 | 142 | COMMAND programs/test/selftest |
markrad | 0:cdf462088d13 | 143 | COMMAND tests/compat.sh |
markrad | 0:cdf462088d13 | 144 | COMMAND tests/ssl-opt.sh |
markrad | 0:cdf462088d13 | 145 | ) |
markrad | 0:cdf462088d13 | 146 | |
markrad | 0:cdf462088d13 | 147 | ADD_CUSTOM_TARGET(lcov |
markrad | 0:cdf462088d13 | 148 | COMMAND rm -rf Coverage |
markrad | 0:cdf462088d13 | 149 | COMMAND lcov --capture --initial --directory library/CMakeFiles/mbedtls.dir -o files.info |
markrad | 0:cdf462088d13 | 150 | COMMAND lcov --capture --directory library/CMakeFiles/mbedtls.dir -o tests.info |
markrad | 0:cdf462088d13 | 151 | COMMAND lcov --add-tracefile files.info --add-tracefile tests.info -o all.info |
markrad | 0:cdf462088d13 | 152 | COMMAND lcov --remove all.info -o final.info '*.h' |
markrad | 0:cdf462088d13 | 153 | COMMAND gendesc tests/Descriptions.txt -o descriptions |
markrad | 0:cdf462088d13 | 154 | COMMAND genhtml --title "mbed TLS" --description-file descriptions --keep-descriptions --legend --no-branch-coverage -o Coverage final.info |
markrad | 0:cdf462088d13 | 155 | COMMAND rm -f files.info tests.info all.info final.info descriptions |
markrad | 0:cdf462088d13 | 156 | ) |
markrad | 0:cdf462088d13 | 157 | |
markrad | 0:cdf462088d13 | 158 | ADD_CUSTOM_TARGET(memcheck |
markrad | 0:cdf462088d13 | 159 | COMMAND sed -i.bak s+/usr/bin/valgrind+`which valgrind`+ DartConfiguration.tcl |
markrad | 0:cdf462088d13 | 160 | COMMAND ctest -O memcheck.log -D ExperimentalMemCheck |
markrad | 0:cdf462088d13 | 161 | COMMAND tail -n1 memcheck.log | grep 'Memory checking results:' > /dev/null |
markrad | 0:cdf462088d13 | 162 | COMMAND rm -f memcheck.log |
markrad | 0:cdf462088d13 | 163 | COMMAND mv DartConfiguration.tcl.bak DartConfiguration.tcl |
markrad | 0:cdf462088d13 | 164 | ) |
markrad | 0:cdf462088d13 | 165 | endif(UNIX) |
markrad | 0:cdf462088d13 | 166 | endif() |