CMakeLists.txt 4.13 KB
Newer Older
1
cmake_minimum_required(VERSION 2.6)
2
project("mbed TLS" C)
3

4
string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}")
5

6
if(CMAKE_COMPILER_IS_GNUCC)
7 8 9 10 11 12 13 14
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings -Wlogical-op")
    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")
15
endif(CMAKE_COMPILER_IS_GNUCC)
16

17
if(CMAKE_COMPILER_IS_CLANG)
18 19 20 21 22 23 24 25 26
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings -Wpointer-arith")
    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 -O3")
    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 ")
    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")
27 28
endif(CMAKE_COMPILER_IS_CLANG)

Paul Bakker's avatar
Paul Bakker committed
29
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}
30
    CACHE STRING "Choose the type of build: None Debug Release Coverage ASan ASanDbg MemSan MemSanDbg Check CheckFull"
Paul Bakker's avatar
Paul Bakker committed
31
    FORCE)
32

33
if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
34 35 36
    if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
        set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
    endif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
37
endif(CMAKE_BUILD_TYPE STREQUAL "Coverage")
38

39
option(USE_PKCS11_HELPER_LIBRARY "Build mbed TLS with the pkcs11-helper library." OFF)
40

41 42 43
option(ENABLE_ZLIB_SUPPORT "Build mbed TLS with zlib library." OFF)
option(ENABLE_PROGRAMS "Build mbed TLS programs." ON)
option(ENABLE_TESTING "Build mbed TLS tests." ON)
44 45

if(ENABLE_TESTING)
46
    enable_testing()
47
endif()
48

49 50
if(LIB_INSTALL_DIR)
else()
51
    set(LIB_INSTALL_DIR lib)
52 53
endif()

54 55
include_directories(include/)

56
if(ENABLE_ZLIB_SUPPORT)
57
    find_package(ZLIB)
58

59 60 61
    if(ZLIB_FOUND)
        include_directories(${ZLIB_INCLUDE_DIR})
    endif(ZLIB_FOUND)
62 63
endif(ENABLE_ZLIB_SUPPORT)

64
add_subdirectory(library)
65
add_subdirectory(include)
66

67
if(ENABLE_PROGRAMS)
68
    add_subdirectory(programs)
69
endif()
70 71

ADD_CUSTOM_TARGET(apidoc
72 73
    COMMAND doxygen doxygen/mbedtls.doxyfile
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
74

75
if(ENABLE_TESTING)
76 77
    add_subdirectory(tests)

78 79 80 81 82
    ADD_CUSTOM_TARGET(covtest
        COMMAND make test
        COMMAND programs/test/selftest
        COMMAND cd tests && ./compat.sh
        COMMAND cd tests && ./ssl-opt.sh
83 84
    )

85 86 87 88 89 90 91 92 93
    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
94 95
    )

96 97 98 99 100 101
    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
102
    )
103
endif()