CMakeLists.txt 2.41 KB
Newer Older
Hugo Leisink's avatar
Hugo Leisink committed
1
cmake_minimum_required(VERSION 3.0)
Hugo Leisink's avatar
Hugo Leisink committed
2
project("mbed TLS" C)
Hugo Leisink's avatar
Hugo Leisink committed
3

Hugo Leisink's avatar
Hugo Leisink committed
4 5 6 7
option(USE_PKCS11_HELPER_LIBRARY "Build mbed TLS with the pkcs11-helper library." OFF)
option(ENABLE_ZLIB_SUPPORT "Build mbed TLS with zlib library." OFF)

string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}")
Hugo Leisink's avatar
Hugo Leisink committed
8
string(REGEX MATCH "GNU" CMAKE_COMPILER_IS_GNU "${CMAKE_C_COMPILER_ID}")
Hugo Leisink's avatar
Hugo Leisink committed
9

Hugo Leisink's avatar
Hugo Leisink committed
10 11 12
if(CMAKE_COMPILER_IS_GNU)
    execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
                    OUTPUT_VARIABLE GCC_VERSION)
Hugo Leisink's avatar
Hugo Leisink committed
13 14 15 16
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings")
    if (GCC_VERSION VERSION_GREATER 4.5 OR GCC_VERSION VERSION_EQUAL 4.5)
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wlogical-op")
    endif()
Hugo Leisink's avatar
Hugo Leisink committed
17 18 19
    if (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8)
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
    endif()
Hugo Leisink's avatar
Hugo Leisink committed
20 21 22 23 24 25 26
    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")
Hugo Leisink's avatar
Hugo Leisink committed
27
endif(CMAKE_COMPILER_IS_GNU)
Hugo Leisink's avatar
Hugo Leisink committed
28 29

if(CMAKE_COMPILER_IS_CLANG)
Hugo Leisink's avatar
Hugo Leisink committed
30
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow")
Hugo Leisink's avatar
Hugo Leisink committed
31 32 33
    set(CMAKE_C_FLAGS_RELEASE     "-O2")
    set(CMAKE_C_FLAGS_DEBUG       "-O0 -g3")
    set(CMAKE_C_FLAGS_COVERAGE    "-O0 -g3 --coverage")
Hugo Leisink's avatar
Hugo Leisink committed
34 35
    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 ")
Hugo Leisink's avatar
Hugo Leisink committed
36 37 38
    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")
Hugo Leisink's avatar
Hugo Leisink committed
39 40
endif(CMAKE_COMPILER_IS_CLANG)

Hugo Leisink's avatar
Hugo Leisink committed
41 42
if(LIB_INSTALL_DIR)
else()
Hugo Leisink's avatar
Hugo Leisink committed
43
    set(LIB_INSTALL_DIR lib)
Hugo Leisink's avatar
Hugo Leisink committed
44 45 46
endif()

include_directories(include/)
Hugo Leisink's avatar
Hugo Leisink committed
47
add_subdirectory(library)