blob: 70ad10a6b48f817cb98383e9fd827775c1af1d3b [file] [log] [blame]
Paul Bakker367dae42009-06-28 21:50:27 +00001cmake_minimum_required(VERSION 2.6)
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +00002project(MBEDTLS C)
Paul Bakker367dae42009-06-28 21:50:27 +00003
Barry K. Nathancf975f52014-04-23 17:40:25 -07004string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}")
Paul Bakker92bc8752013-12-30 17:56:23 +01005
Paul Bakker2015eac2011-07-27 16:52:28 +00006if(CMAKE_COMPILER_IS_GNUCC)
Manuel Pégourié-Gonnard54f6e562014-11-10 12:15:39 +01007 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings -Wlogical-op")
Manuel Pégourié-Gonnard705b70f2014-11-13 13:35:50 +01008 set(CMAKE_C_FLAGS_RELEASE "-O2")
9 set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
10 set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
11 set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -O3")
12 set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls ")
Manuel Pégourié-Gonnard187ffb92015-03-13 11:20:20 +000013 set(CMAKE_C_FLAGS_CHECK "-Werror -Os")
Manuel Pégourié-Gonnard705b70f2014-11-13 13:35:50 +010014 set(CMAKE_C_FLAGS_CHECKFULL "${CMAKE_C_FLAGS_CHECK} -Wcast-qual")
Paul Bakker2015eac2011-07-27 16:52:28 +000015endif(CMAKE_COMPILER_IS_GNUCC)
Paul Bakker76f03112013-11-28 17:20:04 +010016
Paul Bakker92bc8752013-12-30 17:56:23 +010017if(CMAKE_COMPILER_IS_CLANG)
Manuel Pégourié-Gonnard98aa1912014-11-14 16:34:36 +010018 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings -Wpointer-arith")
Manuel Pégourié-Gonnard705b70f2014-11-13 13:35:50 +010019 set(CMAKE_C_FLAGS_RELEASE "-O2")
20 set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
21 set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
22 set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover -O3")
23 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 ")
24 set(CMAKE_C_FLAGS_MEMSAN "-Werror -fsanitize=memory -O3")
25 set(CMAKE_C_FLAGS_MEMSANDBG "-Werror -fsanitize=memory -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2")
Manuel Pégourié-Gonnard187ffb92015-03-13 11:20:20 +000026 set(CMAKE_C_FLAGS_CHECK "-Werror -Os")
Paul Bakker92bc8752013-12-30 17:56:23 +010027endif(CMAKE_COMPILER_IS_CLANG)
28
Paul Bakkerad0db972013-12-30 14:09:27 +010029set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}
Manuel Pégourié-Gonnard705b70f2014-11-13 13:35:50 +010030 CACHE STRING "Choose the type of build: None Debug Release Coverage ASan ASanDbg MemSan MemSanDbg Check CheckFull"
Paul Bakkerad0db972013-12-30 14:09:27 +010031 FORCE)
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010032
Paul Bakker396c52f2009-07-11 19:54:40 +000033if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
Paul Bakker2015eac2011-07-27 16:52:28 +000034 if(CMAKE_COMPILER_IS_GNUCC)
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010035 set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
Paul Bakker2015eac2011-07-27 16:52:28 +000036 endif(CMAKE_COMPILER_IS_GNUCC)
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010037 if(CMAKE_COMPILER_IS_CLANG)
38 set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
39 endif(CMAKE_COMPILER_IS_CLANG)
Paul Bakker396c52f2009-07-11 19:54:40 +000040endif(CMAKE_BUILD_TYPE STREQUAL "Coverage")
Paul Bakker367dae42009-06-28 21:50:27 +000041
Manuel Pégourié-Gonnardcfa9a452015-01-23 13:33:31 +000042option(USE_PKCS11_HELPER_LIBRARY "Build mbed TLS with the pkcs11-helper library." OFF)
Paul Bakkerb06819b2011-01-18 16:18:38 +000043
Manuel Pégourié-Gonnardcfa9a452015-01-23 13:33:31 +000044option(ENABLE_ZLIB_SUPPORT "Build mbed TLS with zlib library." OFF)
45option(ENABLE_PROGRAMS "Build mbed TLS programs." ON)
46option(ENABLE_TESTING "Build mbed TLS tests." ON)
Paul Bakker27f1cae2014-04-30 16:31:54 +020047
48if(ENABLE_TESTING)
49 enable_testing()
50endif()
Paul Bakker92eeea42012-07-03 15:10:33 +000051
Paul Bakker091e2872011-07-13 11:45:58 +000052if(LIB_INSTALL_DIR)
53else()
Paul Bakkerb3b49012011-12-11 11:28:52 +000054set(LIB_INSTALL_DIR lib)
Paul Bakker091e2872011-07-13 11:45:58 +000055endif()
56
Paul Bakker367dae42009-06-28 21:50:27 +000057include_directories(include/)
58
Paul Bakker92eeea42012-07-03 15:10:33 +000059if(ENABLE_ZLIB_SUPPORT)
60 find_package(ZLIB)
61
62 if(ZLIB_FOUND)
hasufell7c4a5532014-03-06 15:46:06 +010063 include_directories(${ZLIB_INCLUDE_DIR})
Paul Bakker92eeea42012-07-03 15:10:33 +000064 endif(ZLIB_FOUND)
65endif(ENABLE_ZLIB_SUPPORT)
66
Paul Bakker367dae42009-06-28 21:50:27 +000067add_subdirectory(library)
Paul Bakker547f73d2011-01-05 15:07:54 +000068add_subdirectory(include)
Paul Bakker2015eac2011-07-27 16:52:28 +000069
Paul Bakker27f1cae2014-04-30 16:31:54 +020070if(ENABLE_TESTING)
71 if(CMAKE_COMPILER_IS_GNUCC)
72 add_subdirectory(tests)
73 endif(CMAKE_COMPILER_IS_GNUCC)
74 if(CMAKE_COMPILER_IS_CLANG)
75 add_subdirectory(tests)
76 endif(CMAKE_COMPILER_IS_CLANG)
77endif()
Paul Bakker2015eac2011-07-27 16:52:28 +000078
Paul Bakkerdf5024c2014-03-26 13:27:51 +010079if(ENABLE_PROGRAMS)
80 add_subdirectory(programs)
81endif()
Paul Bakkerccba9bc2011-01-05 15:30:32 +000082
83ADD_CUSTOM_TARGET(apidoc
Manuel Pégourié-Gonnardf234ff82015-01-22 17:01:27 +000084 COMMAND doxygen doxygen/mbedtls.doxyfile
Paul Bakkerccba9bc2011-01-05 15:30:32 +000085 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Manuel Pégourié-Gonnard7669f282013-09-07 16:52:42 +020086
Paul Bakker27f1cae2014-04-30 16:31:54 +020087if(ENABLE_TESTING)
88 ADD_CUSTOM_TARGET(test-ref-config
Manuel Pégourié-Gonnard6529ff02014-01-31 13:41:07 +010089 COMMAND tests/scripts/test-ref-configs.pl
90 )
91
Paul Bakker27f1cae2014-04-30 16:31:54 +020092 ADD_CUSTOM_TARGET(covtest
Manuel Pégourié-Gonnard61137df2014-02-24 11:57:36 +010093 COMMAND make test
94 COMMAND programs/test/selftest
95 COMMAND cd tests && ./compat.sh
96 COMMAND cd tests && ./ssl-opt.sh
97 )
98
Paul Bakker27f1cae2014-04-30 16:31:54 +020099 ADD_CUSTOM_TARGET(lcov
Manuel Pégourié-Gonnard720375e2014-02-24 12:39:18 +0100100 COMMAND rm -rf Coverage
Manuel Pégourié-Gonnard9014b6f2015-01-27 15:44:46 +0000101 COMMAND lcov --capture --initial --directory library/CMakeFiles/mbedtls.dir -o files.info
102 COMMAND lcov --capture --directory library/CMakeFiles/mbedtls.dir -o tests.info
Manuel Pégourié-Gonnarde41072e2014-06-16 16:24:24 +0200103 COMMAND lcov --add-tracefile files.info --add-tracefile tests.info -o all.info
104 COMMAND lcov --remove all.info -o final.info '*.h'
Manuel Pégourié-Gonnard720375e2014-02-24 12:39:18 +0100105 COMMAND gendesc tests/Descriptions.txt -o descriptions
Manuel Pégourié-Gonnardafe8f532015-01-23 17:40:33 +0000106 COMMAND genhtml --title "mbed TLS" --description-file descriptions --keep-descriptions --legend --no-branch-coverage -o Coverage final.info
Manuel Pégourié-Gonnarde41072e2014-06-16 16:24:24 +0200107 COMMAND rm -f files.info tests.info all.info final.info descriptions
Manuel Pégourié-Gonnard546d86c2014-01-31 16:19:43 +0100108 )
109
Paul Bakker27f1cae2014-04-30 16:31:54 +0200110 ADD_CUSTOM_TARGET(memcheck
Manuel Pégourié-Gonnardd68b6512015-01-07 14:55:38 +0100111 COMMAND sed -i.bak s+/usr/bin/valgrind+`which valgrind`+ DartConfiguration.tcl
Manuel Pégourié-Gonnarddeb79492013-09-13 13:43:43 +0200112 COMMAND ctest -O memcheck.log -D ExperimentalMemCheck
Manuel Pégourié-Gonnard7669f282013-09-07 16:52:42 +0200113 COMMAND tail -n1 memcheck.log | grep 'Memory checking results:' > /dev/null
114 COMMAND rm -f memcheck.log
Manuel Pégourié-Gonnard3da751e2014-12-15 10:41:53 +0100115 COMMAND mv DartConfiguration.tcl.bak DartConfiguration.tcl
Manuel Pégourié-Gonnard7669f282013-09-07 16:52:42 +0200116 )
Paul Bakker27f1cae2014-04-30 16:31:54 +0200117endif()