blob: 1596226c067b9561ee48c7de5e08c471fdfd7cc3 [file] [log] [blame]
Paul Bakker367dae42009-06-28 21:50:27 +00001cmake_minimum_required(VERSION 2.6)
2project(POLARSSL C)
3
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")
hasufellfcd36292014-03-06 15:45:00 +01008 set(CMAKE_C_FLAGS_RELEASE "-O2")
Paul Bakkerf1ab0ec2012-10-23 12:12:53 +00009 set(CMAKE_C_FLAGS_DEBUG "-g3 -O0")
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010010 set(CMAKE_C_FLAGS_COVERAGE "-g3 -O0 --coverage")
Manuel Pégourié-Gonnard39141fe2014-08-14 11:23:46 +020011 set(CMAKE_C_FLAGS_ASAN "-fsanitize=address -fno-omit-frame-pointer -g3 -O1 -Werror")
12 set(CMAKE_C_FLAGS_CHECK "-O1 -Werror")
Paul Bakker76f03112013-11-28 17:20:04 +010013 set(CMAKE_C_FLAGS_CHECKFULL "${CMAKE_C_FLAGS_CHECK} -Wcast-qual")
Paul Bakker2015eac2011-07-27 16:52:28 +000014endif(CMAKE_COMPILER_IS_GNUCC)
Paul Bakker76f03112013-11-28 17:20:04 +010015
Paul Bakker92bc8752013-12-30 17:56:23 +010016if(CMAKE_COMPILER_IS_CLANG)
Manuel Pégourié-Gonnard54f6e562014-11-10 12:15:39 +010017 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings -Wpointer-arith -Wdocumentation -Wunreachable-code")
hasufellfcd36292014-03-06 15:45:00 +010018 set(CMAKE_C_FLAGS_RELEASE "-O2")
Paul Bakker92bc8752013-12-30 17:56:23 +010019 set(CMAKE_C_FLAGS_DEBUG "-g3 -O0")
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010020 set(CMAKE_C_FLAGS_COVERAGE "-g3 -O0 --coverage")
Manuel Pégourié-Gonnardd6197a32014-11-10 13:02:22 +010021 set(CMAKE_C_FLAGS_ASAN "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover -fno-omit-frame-pointer -g3 -O1 -Werror")
Manuel Pégourié-Gonnarde9271e62014-11-11 22:21:27 +010022 # note: can add -fsanitize-memory-track-origins=2 for debugging with memsan
23 set(CMAKE_C_FLAGS_MEMSAN "-fsanitize=memory -fno-omit-frame-pointer -fno-optimize-sibling-calls -g3 -O1 -Werror")
Manuel Pégourié-Gonnard39141fe2014-08-14 11:23:46 +020024 set(CMAKE_C_FLAGS_CHECK "-O1 -Werror")
Paul Bakker92bc8752013-12-30 17:56:23 +010025endif(CMAKE_COMPILER_IS_CLANG)
26
Paul Bakkerad0db972013-12-30 14:09:27 +010027set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}
Manuel Pégourié-Gonnarde9271e62014-11-11 22:21:27 +010028 CACHE STRING "Choose the type of build: None Debug Release Coverage ASan MemSan Check CheckFull"
Paul Bakkerad0db972013-12-30 14:09:27 +010029 FORCE)
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010030
Paul Bakker396c52f2009-07-11 19:54:40 +000031if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
Paul Bakker2015eac2011-07-27 16:52:28 +000032 if(CMAKE_COMPILER_IS_GNUCC)
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010033 set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
Paul Bakker2015eac2011-07-27 16:52:28 +000034 endif(CMAKE_COMPILER_IS_GNUCC)
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010035 if(CMAKE_COMPILER_IS_CLANG)
36 set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
37 endif(CMAKE_COMPILER_IS_CLANG)
Paul Bakker396c52f2009-07-11 19:54:40 +000038endif(CMAKE_BUILD_TYPE STREQUAL "Coverage")
Paul Bakker367dae42009-06-28 21:50:27 +000039
Paul Bakkerb06819b2011-01-18 16:18:38 +000040option(USE_PKCS11_HELPER_LIBRARY "Build PolarSSL with the pkcs11-helper library." OFF)
41
Paul Bakker92eeea42012-07-03 15:10:33 +000042option(ENABLE_ZLIB_SUPPORT "Build PolarSSL with zlib library." OFF)
Paul Bakkerdf5024c2014-03-26 13:27:51 +010043option(ENABLE_PROGRAMS "Build PolarSSL programs." ON)
Paul Bakker27f1cae2014-04-30 16:31:54 +020044option(ENABLE_TESTING "Build PolarSSL tests." ON)
45
46if(ENABLE_TESTING)
47 enable_testing()
48endif()
Paul Bakker92eeea42012-07-03 15:10:33 +000049
Paul Bakker091e2872011-07-13 11:45:58 +000050if(LIB_INSTALL_DIR)
51else()
Paul Bakkerb3b49012011-12-11 11:28:52 +000052set(LIB_INSTALL_DIR lib)
Paul Bakker091e2872011-07-13 11:45:58 +000053endif()
54
Paul Bakker367dae42009-06-28 21:50:27 +000055include_directories(include/)
56
Paul Bakker92eeea42012-07-03 15:10:33 +000057if(ENABLE_ZLIB_SUPPORT)
58 find_package(ZLIB)
59
60 if(ZLIB_FOUND)
hasufell7c4a5532014-03-06 15:46:06 +010061 include_directories(${ZLIB_INCLUDE_DIR})
Paul Bakker92eeea42012-07-03 15:10:33 +000062 endif(ZLIB_FOUND)
63endif(ENABLE_ZLIB_SUPPORT)
64
Paul Bakker367dae42009-06-28 21:50:27 +000065add_subdirectory(library)
Paul Bakker547f73d2011-01-05 15:07:54 +000066add_subdirectory(include)
Paul Bakker2015eac2011-07-27 16:52:28 +000067
Paul Bakker27f1cae2014-04-30 16:31:54 +020068if(ENABLE_TESTING)
69 if(CMAKE_COMPILER_IS_GNUCC)
70 add_subdirectory(tests)
71 endif(CMAKE_COMPILER_IS_GNUCC)
72 if(CMAKE_COMPILER_IS_CLANG)
73 add_subdirectory(tests)
74 endif(CMAKE_COMPILER_IS_CLANG)
75endif()
Paul Bakker2015eac2011-07-27 16:52:28 +000076
Paul Bakkerdf5024c2014-03-26 13:27:51 +010077if(ENABLE_PROGRAMS)
78 add_subdirectory(programs)
79endif()
Paul Bakkerccba9bc2011-01-05 15:30:32 +000080
81ADD_CUSTOM_TARGET(apidoc
Paul Bakker37ca75d2011-01-06 12:28:03 +000082 COMMAND doxygen doxygen/polarssl.doxyfile
Paul Bakkerccba9bc2011-01-05 15:30:32 +000083 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Manuel Pégourié-Gonnard7669f282013-09-07 16:52:42 +020084
Paul Bakker27f1cae2014-04-30 16:31:54 +020085if(ENABLE_TESTING)
86 ADD_CUSTOM_TARGET(test-ref-config
Manuel Pégourié-Gonnard6529ff02014-01-31 13:41:07 +010087 COMMAND tests/scripts/test-ref-configs.pl
88 )
89
Paul Bakker27f1cae2014-04-30 16:31:54 +020090 ADD_CUSTOM_TARGET(covtest
Manuel Pégourié-Gonnard61137df2014-02-24 11:57:36 +010091 COMMAND make test
92 COMMAND programs/test/selftest
93 COMMAND cd tests && ./compat.sh
94 COMMAND cd tests && ./ssl-opt.sh
95 )
96
Paul Bakker27f1cae2014-04-30 16:31:54 +020097 ADD_CUSTOM_TARGET(lcov
Manuel Pégourié-Gonnard720375e2014-02-24 12:39:18 +010098 COMMAND rm -rf Coverage
Manuel Pégourié-Gonnard53c6e962014-06-13 12:22:07 +020099 COMMAND lcov --capture --initial --directory library/CMakeFiles/polarssl.dir -o files.info
100 COMMAND lcov --capture --directory library/CMakeFiles/polarssl.dir -o tests.info
Manuel Pégourié-Gonnarde41072e2014-06-16 16:24:24 +0200101 COMMAND lcov --add-tracefile files.info --add-tracefile tests.info -o all.info
102 COMMAND lcov --remove all.info -o final.info '*.h'
Manuel Pégourié-Gonnard720375e2014-02-24 12:39:18 +0100103 COMMAND gendesc tests/Descriptions.txt -o descriptions
Manuel Pégourié-Gonnarde41072e2014-06-16 16:24:24 +0200104 COMMAND genhtml --title PolarSSL --description-file descriptions --keep-descriptions --legend --no-branch-coverage -o Coverage final.info
105 COMMAND rm -f files.info tests.info all.info final.info descriptions
Manuel Pégourié-Gonnard546d86c2014-01-31 16:19:43 +0100106 )
107
Paul Bakker27f1cae2014-04-30 16:31:54 +0200108 ADD_CUSTOM_TARGET(memcheck
Manuel Pégourié-Gonnarddeb79492013-09-13 13:43:43 +0200109 COMMAND ctest -O memcheck.log -D ExperimentalMemCheck
Manuel Pégourié-Gonnard7669f282013-09-07 16:52:42 +0200110 COMMAND tail -n1 memcheck.log | grep 'Memory checking results:' > /dev/null
111 COMMAND rm -f memcheck.log
112 )
Paul Bakker27f1cae2014-04-30 16:31:54 +0200113endif()