| [20366] | 1 | cmake_minimum_required(VERSION 2.6)
|
|---|
| 2 | project("mbed TLS" C)
|
|---|
| 3 |
|
|---|
| 4 | option(USE_PKCS11_HELPER_LIBRARY "Build mbed TLS with the pkcs11-helper library." OFF)
|
|---|
| 5 | option(ENABLE_ZLIB_SUPPORT "Build mbed TLS with zlib library." OFF)
|
|---|
| 6 |
|
|---|
| 7 | option(ENABLE_PROGRAMS "Build mbed TLS programs." ON)
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 | # the test suites currently have compile errors with MSVC
|
|---|
| 11 | if(MSVC)
|
|---|
| 12 | option(ENABLE_TESTING "Build mbed TLS tests." OFF)
|
|---|
| 13 | else()
|
|---|
| 14 | option(ENABLE_TESTING "Build mbed TLS tests." ON)
|
|---|
| 15 | endif()
|
|---|
| 16 |
|
|---|
| 17 | set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}
|
|---|
| 18 | CACHE STRING "Choose the type of build: None Debug Release Coverage ASan ASanDbg MemSan MemSanDbg Check CheckFull"
|
|---|
| 19 | FORCE)
|
|---|
| 20 |
|
|---|
| 21 | string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}")
|
|---|
| 22 |
|
|---|
| 23 | if(CMAKE_COMPILER_IS_GNUCC)
|
|---|
| 24 | # some warnings we want are not available with old GCC versions
|
|---|
| 25 | # note: starting with CMake 2.8 we could use CMAKE_C_COMPILER_VERSION
|
|---|
| 26 | execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
|
|---|
| 27 | OUTPUT_VARIABLE GCC_VERSION)
|
|---|
| 28 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings")
|
|---|
| 29 | if (GCC_VERSION VERSION_GREATER 4.5 OR GCC_VERSION VERSION_EQUAL 4.5)
|
|---|
| 30 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wlogical-op")
|
|---|
| 31 | endif()
|
|---|
| 32 | if (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8)
|
|---|
| 33 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
|
|---|
| 34 | endif()
|
|---|
| 35 | set(CMAKE_C_FLAGS_RELEASE "-O2")
|
|---|
| 36 | set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
|
|---|
| 37 | set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
|
|---|
| 38 | set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -O3")
|
|---|
| 39 | set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls ")
|
|---|
| 40 | set(CMAKE_C_FLAGS_CHECK "-Werror -Os")
|
|---|
| 41 | set(CMAKE_C_FLAGS_CHECKFULL "${CMAKE_C_FLAGS_CHECK} -Wcast-qual")
|
|---|
| 42 | endif(CMAKE_COMPILER_IS_GNUCC)
|
|---|
| 43 |
|
|---|
| 44 | if(CMAKE_COMPILER_IS_CLANG)
|
|---|
| 45 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow")
|
|---|
| 46 | set(CMAKE_C_FLAGS_RELEASE "-O2")
|
|---|
| 47 | set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
|
|---|
| 48 | set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
|
|---|
| 49 | set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover -O3")
|
|---|
| 50 | 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 ")
|
|---|
| 51 | set(CMAKE_C_FLAGS_MEMSAN "-Werror -fsanitize=memory -O3")
|
|---|
| 52 | set(CMAKE_C_FLAGS_MEMSANDBG "-Werror -fsanitize=memory -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2")
|
|---|
| 53 | set(CMAKE_C_FLAGS_CHECK "-Werror -Os")
|
|---|
| 54 | endif(CMAKE_COMPILER_IS_CLANG)
|
|---|
| 55 |
|
|---|
| 56 | if(MSVC)
|
|---|
| 57 | set(CMAKE_C_FLAGS_CHECK "/WX")
|
|---|
| 58 | endif(MSVC)
|
|---|
| 59 |
|
|---|
| 60 | if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
|
|---|
| 61 | if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
|
|---|
| 62 | set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
|
|---|
| 63 | endif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
|
|---|
| 64 | endif(CMAKE_BUILD_TYPE STREQUAL "Coverage")
|
|---|
| 65 |
|
|---|
| 66 | if(LIB_INSTALL_DIR)
|
|---|
| 67 | else()
|
|---|
| 68 | set(LIB_INSTALL_DIR lib)
|
|---|
| 69 | endif()
|
|---|
| 70 |
|
|---|
| 71 | include_directories(include/)
|
|---|
| 72 |
|
|---|
| 73 | if(ENABLE_ZLIB_SUPPORT)
|
|---|
| 74 | find_package(ZLIB)
|
|---|
| 75 |
|
|---|
| 76 | if(ZLIB_FOUND)
|
|---|
| 77 | include_directories(${ZLIB_INCLUDE_DIR})
|
|---|
| 78 | endif(ZLIB_FOUND)
|
|---|
| 79 | endif(ENABLE_ZLIB_SUPPORT)
|
|---|
| 80 |
|
|---|
| 81 | add_subdirectory(library)
|
|---|
| 82 | add_subdirectory(include)
|
|---|
| 83 |
|
|---|
| 84 | if(ENABLE_PROGRAMS)
|
|---|
| 85 | add_subdirectory(programs)
|
|---|
| 86 | endif()
|
|---|
| 87 |
|
|---|
| 88 | # targets for doxygen only work on Unix
|
|---|
| 89 | if(UNIX)
|
|---|
| 90 | ADD_CUSTOM_TARGET(apidoc
|
|---|
| 91 | COMMAND mkdir -p apidoc
|
|---|
| 92 | COMMAND cp include/mbedtls/config.h include/mbedtls/config.h.bak
|
|---|
| 93 | COMMAND scripts/config.pl realfull
|
|---|
| 94 | COMMAND doxygen doxygen/mbedtls.doxyfile
|
|---|
| 95 | COMMAND mv include/mbedtls/config.h.bak include/mbedtls/config.h
|
|---|
| 96 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
|---|
| 97 |
|
|---|
| 98 | ADD_CUSTOM_TARGET(apidoc_clean
|
|---|
| 99 | COMMAND rm -rf apidoc
|
|---|
| 100 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
|---|
| 101 | endif(UNIX)
|
|---|
| 102 |
|
|---|
| 103 | if(ENABLE_TESTING)
|
|---|
| 104 | enable_testing()
|
|---|
| 105 |
|
|---|
| 106 | add_subdirectory(tests)
|
|---|
| 107 |
|
|---|
| 108 | # additional convenience targets for Unix only
|
|---|
| 109 | if(UNIX)
|
|---|
| 110 |
|
|---|
| 111 | ADD_CUSTOM_TARGET(covtest
|
|---|
| 112 | COMMAND make test
|
|---|
| 113 | COMMAND programs/test/selftest
|
|---|
| 114 | COMMAND tests/compat.sh
|
|---|
| 115 | COMMAND tests/ssl-opt.sh
|
|---|
| 116 | )
|
|---|
| 117 |
|
|---|
| 118 | ADD_CUSTOM_TARGET(lcov
|
|---|
| 119 | COMMAND rm -rf Coverage
|
|---|
| 120 | COMMAND lcov --capture --initial --directory library/CMakeFiles/mbedtls.dir -o files.info
|
|---|
| 121 | COMMAND lcov --capture --directory library/CMakeFiles/mbedtls.dir -o tests.info
|
|---|
| 122 | COMMAND lcov --add-tracefile files.info --add-tracefile tests.info -o all.info
|
|---|
| 123 | COMMAND lcov --remove all.info -o final.info '*.h'
|
|---|
| 124 | COMMAND gendesc tests/Descriptions.txt -o descriptions
|
|---|
| 125 | COMMAND genhtml --title "mbed TLS" --description-file descriptions --keep-descriptions --legend --no-branch-coverage -o Coverage final.info
|
|---|
| 126 | COMMAND rm -f files.info tests.info all.info final.info descriptions
|
|---|
| 127 | )
|
|---|
| 128 |
|
|---|
| 129 | ADD_CUSTOM_TARGET(memcheck
|
|---|
| 130 | COMMAND sed -i.bak s+/usr/bin/valgrind+`which valgrind`+ DartConfiguration.tcl
|
|---|
| 131 | COMMAND ctest -O memcheck.log -D ExperimentalMemCheck
|
|---|
| 132 | COMMAND tail -n1 memcheck.log | grep 'Memory checking results:' > /dev/null
|
|---|
| 133 | COMMAND rm -f memcheck.log
|
|---|
| 134 | COMMAND mv DartConfiguration.tcl.bak DartConfiguration.tcl
|
|---|
| 135 | )
|
|---|
| 136 | endif(UNIX)
|
|---|
| 137 | endif()
|
|---|