blob: 86439ada42a22163ddb1fcb9f8fb97d56caf9443 [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)
hasufellfcd36292014-03-06 15:45:00 +01007 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement")
8 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é-Gonnard469238a2014-01-31 13:29:47 +010011 set(CMAKE_C_FLAGS_ASAN "-fsanitize=address -fno-omit-frame-pointer -g3 -O1")
Manuel Pégourié-Gonnard1827a6e2014-03-27 14:56:14 +010012 set(CMAKE_C_FLAGS_CHECK "${CMAKE_C_FLAGS} -Werror -O1 -Wlogical-op -Wwrite-strings")
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)
hasufellfcd36292014-03-06 15:45:00 +010017 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement")
18 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é-Gonnard469238a2014-01-31 13:29:47 +010021 set(CMAKE_C_FLAGS_ASAN "-fsanitize=address -fno-omit-frame-pointer -g3 -O1")
Manuel Pégourié-Gonnard1827a6e2014-03-27 14:56:14 +010022 set(CMAKE_C_FLAGS_CHECK "${CMAKE_C_FLAGS} -Werror -O1 -Wpointer-arith -Wwrite-strings -Wdocumentation -Wunreachable-code")
Paul Bakker92bc8752013-12-30 17:56:23 +010023endif(CMAKE_COMPILER_IS_CLANG)
24
Paul Bakkerad0db972013-12-30 14:09:27 +010025set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}
Manuel Pégourié-Gonnard469238a2014-01-31 13:29:47 +010026 CACHE STRING "Choose the type of build: None Debug Release Coverage ASan Check CheckFull"
Paul Bakkerad0db972013-12-30 14:09:27 +010027 FORCE)
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010028
Paul Bakker396c52f2009-07-11 19:54:40 +000029if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
Paul Bakker2015eac2011-07-27 16:52:28 +000030 if(CMAKE_COMPILER_IS_GNUCC)
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010031 set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
Paul Bakker2015eac2011-07-27 16:52:28 +000032 endif(CMAKE_COMPILER_IS_GNUCC)
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010033 if(CMAKE_COMPILER_IS_CLANG)
34 set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
35 endif(CMAKE_COMPILER_IS_CLANG)
Paul Bakker396c52f2009-07-11 19:54:40 +000036endif(CMAKE_BUILD_TYPE STREQUAL "Coverage")
Paul Bakker367dae42009-06-28 21:50:27 +000037
Paul Bakkerb06819b2011-01-18 16:18:38 +000038option(USE_PKCS11_HELPER_LIBRARY "Build PolarSSL with the pkcs11-helper library." OFF)
39
Paul Bakker92eeea42012-07-03 15:10:33 +000040option(ENABLE_ZLIB_SUPPORT "Build PolarSSL with zlib library." OFF)
Paul Bakkerdf5024c2014-03-26 13:27:51 +010041option(ENABLE_PROGRAMS "Build PolarSSL programs." ON)
Paul Bakker27f1cae2014-04-30 16:31:54 +020042option(ENABLE_TESTING "Build PolarSSL tests." ON)
43
44if(ENABLE_TESTING)
45 enable_testing()
46endif()
Paul Bakker92eeea42012-07-03 15:10:33 +000047
Paul Bakker091e2872011-07-13 11:45:58 +000048if(LIB_INSTALL_DIR)
49else()
Paul Bakkerb3b49012011-12-11 11:28:52 +000050set(LIB_INSTALL_DIR lib)
Paul Bakker091e2872011-07-13 11:45:58 +000051endif()
52
Paul Bakker367dae42009-06-28 21:50:27 +000053include_directories(include/)
54
Paul Bakker92eeea42012-07-03 15:10:33 +000055if(ENABLE_ZLIB_SUPPORT)
56 find_package(ZLIB)
57
58 if(ZLIB_FOUND)
hasufell7c4a5532014-03-06 15:46:06 +010059 include_directories(${ZLIB_INCLUDE_DIR})
Paul Bakker92eeea42012-07-03 15:10:33 +000060 endif(ZLIB_FOUND)
61endif(ENABLE_ZLIB_SUPPORT)
62
Paul Bakker367dae42009-06-28 21:50:27 +000063add_subdirectory(library)
Paul Bakker547f73d2011-01-05 15:07:54 +000064add_subdirectory(include)
Paul Bakker2015eac2011-07-27 16:52:28 +000065
Paul Bakker27f1cae2014-04-30 16:31:54 +020066if(ENABLE_TESTING)
67 if(CMAKE_COMPILER_IS_GNUCC)
68 add_subdirectory(tests)
69 endif(CMAKE_COMPILER_IS_GNUCC)
70 if(CMAKE_COMPILER_IS_CLANG)
71 add_subdirectory(tests)
72 endif(CMAKE_COMPILER_IS_CLANG)
73endif()
Paul Bakker2015eac2011-07-27 16:52:28 +000074
Paul Bakkerdf5024c2014-03-26 13:27:51 +010075if(ENABLE_PROGRAMS)
76 add_subdirectory(programs)
77endif()
Paul Bakkerccba9bc2011-01-05 15:30:32 +000078
79ADD_CUSTOM_TARGET(apidoc
Paul Bakker37ca75d2011-01-06 12:28:03 +000080 COMMAND doxygen doxygen/polarssl.doxyfile
Paul Bakkerccba9bc2011-01-05 15:30:32 +000081 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Manuel Pégourié-Gonnard7669f282013-09-07 16:52:42 +020082
Paul Bakker27f1cae2014-04-30 16:31:54 +020083if(ENABLE_TESTING)
84 ADD_CUSTOM_TARGET(test-ref-config
Manuel Pégourié-Gonnard6529ff02014-01-31 13:41:07 +010085 COMMAND tests/scripts/test-ref-configs.pl
86 )
87
Paul Bakker27f1cae2014-04-30 16:31:54 +020088 ADD_CUSTOM_TARGET(covtest
Manuel Pégourié-Gonnard61137df2014-02-24 11:57:36 +010089 COMMAND make test
90 COMMAND programs/test/selftest
91 COMMAND cd tests && ./compat.sh
92 COMMAND cd tests && ./ssl-opt.sh
93 )
94
Paul Bakker27f1cae2014-04-30 16:31:54 +020095 ADD_CUSTOM_TARGET(lcov
Manuel Pégourié-Gonnard720375e2014-02-24 12:39:18 +010096 COMMAND rm -rf Coverage
Manuel Pégourié-Gonnard53c6e962014-06-13 12:22:07 +020097 COMMAND lcov --capture --initial --directory library/CMakeFiles/polarssl.dir -o files.info
98 COMMAND lcov --capture --directory library/CMakeFiles/polarssl.dir -o tests.info
Manuel Pégourié-Gonnarde41072e2014-06-16 16:24:24 +020099 COMMAND lcov --add-tracefile files.info --add-tracefile tests.info -o all.info
100 COMMAND lcov --remove all.info -o final.info '*.h'
Manuel Pégourié-Gonnard720375e2014-02-24 12:39:18 +0100101 COMMAND gendesc tests/Descriptions.txt -o descriptions
Manuel Pégourié-Gonnarde41072e2014-06-16 16:24:24 +0200102 COMMAND genhtml --title PolarSSL --description-file descriptions --keep-descriptions --legend --no-branch-coverage -o Coverage final.info
103 COMMAND rm -f files.info tests.info all.info final.info descriptions
Manuel Pégourié-Gonnard546d86c2014-01-31 16:19:43 +0100104 )
105
Paul Bakker27f1cae2014-04-30 16:31:54 +0200106 ADD_CUSTOM_TARGET(memcheck
Manuel Pégourié-Gonnarddeb79492013-09-13 13:43:43 +0200107 COMMAND ctest -O memcheck.log -D ExperimentalMemCheck
Manuel Pégourié-Gonnard7669f282013-09-07 16:52:42 +0200108 COMMAND tail -n1 memcheck.log | grep 'Memory checking results:' > /dev/null
109 COMMAND rm -f memcheck.log
110 )
Paul Bakker27f1cae2014-04-30 16:31:54 +0200111endif()