blob: 00e0af59f1db16aa7f2d576ce2d6052940ebb552 [file] [log] [blame]
Paul Bakker367dae42009-06-28 21:50:27 +00001cmake_minimum_required(VERSION 2.6)
2project(POLARSSL C)
3
4enable_testing()
5
Paul Bakker92bc8752013-12-30 17:56:23 +01006string(REGEX MATCH "clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER}")
7
Paul Bakker2015eac2011-07-27 16:52:28 +00008if(CMAKE_COMPILER_IS_GNUCC)
hasufellfcd36292014-03-06 15:45:00 +01009 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement")
10 set(CMAKE_C_FLAGS_RELEASE "-O2")
Paul Bakkerf1ab0ec2012-10-23 12:12:53 +000011 set(CMAKE_C_FLAGS_DEBUG "-g3 -O0")
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010012 set(CMAKE_C_FLAGS_COVERAGE "-g3 -O0 --coverage")
Manuel Pégourié-Gonnard469238a2014-01-31 13:29:47 +010013 set(CMAKE_C_FLAGS_ASAN "-fsanitize=address -fno-omit-frame-pointer -g3 -O1")
Paul Bakkere1e962d2013-12-30 19:00:41 +010014 set(CMAKE_C_FLAGS_CHECK "${CMAKE_C_FLAGS} -Werror -Wlogical-op -Wwrite-strings")
Paul Bakker76f03112013-11-28 17:20:04 +010015 set(CMAKE_C_FLAGS_CHECKFULL "${CMAKE_C_FLAGS_CHECK} -Wcast-qual")
Paul Bakker2015eac2011-07-27 16:52:28 +000016endif(CMAKE_COMPILER_IS_GNUCC)
Paul Bakker76f03112013-11-28 17:20:04 +010017
Paul Bakker92bc8752013-12-30 17:56:23 +010018if(CMAKE_COMPILER_IS_CLANG)
hasufellfcd36292014-03-06 15:45:00 +010019 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement")
20 set(CMAKE_C_FLAGS_RELEASE "-O2")
Paul Bakker92bc8752013-12-30 17:56:23 +010021 set(CMAKE_C_FLAGS_DEBUG "-g3 -O0")
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010022 set(CMAKE_C_FLAGS_COVERAGE "-g3 -O0 --coverage")
Manuel Pégourié-Gonnard469238a2014-01-31 13:29:47 +010023 set(CMAKE_C_FLAGS_ASAN "-fsanitize=address -fno-omit-frame-pointer -g3 -O1")
Manuel Pégourié-Gonnarde8bac682014-02-24 10:49:27 +010024 set(CMAKE_C_FLAGS_CHECK "${CMAKE_C_FLAGS} -Werror -Wpointer-arith -Wwrite-strings -Wdocumentation -Wunreachable-code")
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é-Gonnard469238a2014-01-31 13:29:47 +010028 CACHE STRING "Choose the type of build: None Debug Release Coverage ASan 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 Bakker92eeea42012-07-03 15:10:33 +000044
Paul Bakker091e2872011-07-13 11:45:58 +000045if(LIB_INSTALL_DIR)
46else()
Paul Bakkerb3b49012011-12-11 11:28:52 +000047set(LIB_INSTALL_DIR lib)
Paul Bakker091e2872011-07-13 11:45:58 +000048endif()
49
Paul Bakker367dae42009-06-28 21:50:27 +000050include_directories(include/)
51
Paul Bakker92eeea42012-07-03 15:10:33 +000052if(ENABLE_ZLIB_SUPPORT)
53 find_package(ZLIB)
54
55 if(ZLIB_FOUND)
hasufell7c4a5532014-03-06 15:46:06 +010056 include_directories(${ZLIB_INCLUDE_DIR})
Paul Bakker92eeea42012-07-03 15:10:33 +000057 endif(ZLIB_FOUND)
58endif(ENABLE_ZLIB_SUPPORT)
59
Paul Bakker367dae42009-06-28 21:50:27 +000060add_subdirectory(library)
Paul Bakker547f73d2011-01-05 15:07:54 +000061add_subdirectory(include)
Paul Bakker2015eac2011-07-27 16:52:28 +000062
63if(CMAKE_COMPILER_IS_GNUCC)
64 add_subdirectory(tests)
65endif(CMAKE_COMPILER_IS_GNUCC)
Manuel Pégourié-Gonnardbd0de942014-01-18 18:14:16 +010066if(CMAKE_COMPILER_IS_CLANG)
67 add_subdirectory(tests)
68endif(CMAKE_COMPILER_IS_CLANG)
Paul Bakker2015eac2011-07-27 16:52:28 +000069
Paul Bakkerdf5024c2014-03-26 13:27:51 +010070if(ENABLE_PROGRAMS)
71 add_subdirectory(programs)
72endif()
Paul Bakkerccba9bc2011-01-05 15:30:32 +000073
74ADD_CUSTOM_TARGET(apidoc
Paul Bakker37ca75d2011-01-06 12:28:03 +000075 COMMAND doxygen doxygen/polarssl.doxyfile
Paul Bakkerccba9bc2011-01-05 15:30:32 +000076 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Manuel Pégourié-Gonnard7669f282013-09-07 16:52:42 +020077
Manuel Pégourié-Gonnard6529ff02014-01-31 13:41:07 +010078ADD_CUSTOM_TARGET(test-ref-config
79 COMMAND tests/scripts/test-ref-configs.pl
80 )
81
Manuel Pégourié-Gonnard720375e2014-02-24 12:39:18 +010082# add programs/test/selftest even though the selftest functions are
83# called from the testsuites since it runs them in verbose mode,
84# avoiding spurious "uncovered" printf lines
Manuel Pégourié-Gonnard61137df2014-02-24 11:57:36 +010085ADD_CUSTOM_TARGET(covtest
86 COMMAND make test
87 COMMAND programs/test/selftest
88 COMMAND cd tests && ./compat.sh
89 COMMAND cd tests && ./ssl-opt.sh
90 )
91
Manuel Pégourié-Gonnard546d86c2014-01-31 16:19:43 +010092ADD_CUSTOM_TARGET(lcov
Manuel Pégourié-Gonnard720375e2014-02-24 12:39:18 +010093 COMMAND rm -rf Coverage
94 COMMAND lcov --capture --directory library/CMakeFiles/polarssl.dir -o polarssl.info
95 COMMAND gendesc tests/Descriptions.txt -o descriptions
96 COMMAND genhtml --title PolarSSL --description-file descriptions --keep-descriptions --legend --no-branch-coverage -o Coverage polarssl.info
97 COMMAND rm -f polarssl.info descriptions
Manuel Pégourié-Gonnard546d86c2014-01-31 16:19:43 +010098 )
99
Manuel Pégourié-Gonnard7669f282013-09-07 16:52:42 +0200100ADD_CUSTOM_TARGET(memcheck
Manuel Pégourié-Gonnarddeb79492013-09-13 13:43:43 +0200101 COMMAND ctest -O memcheck.log -D ExperimentalMemCheck
Manuel Pégourié-Gonnard7669f282013-09-07 16:52:42 +0200102 COMMAND tail -n1 memcheck.log | grep 'Memory checking results:' > /dev/null
103 COMMAND rm -f memcheck.log
104 )