blob: 1afe78035eec03542a84581d2e5c56ea1a7bb545 [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)
Paul Bakkerf1ab0ec2012-10-23 12:12:53 +00009 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -Wall -Wextra -W -Wdeclaration-after-statement")
10 set(CMAKE_C_FLAGS_DEBUG "-g3 -O0")
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010011 set(CMAKE_C_FLAGS_COVERAGE "-g3 -O0 --coverage")
Paul Bakkere1e962d2013-12-30 19:00:41 +010012 set(CMAKE_C_FLAGS_CHECK "${CMAKE_C_FLAGS} -Werror -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)
17 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -Wall -Wextra -W -Wdeclaration-after-statement")
18 set(CMAKE_C_FLAGS_DEBUG "-g3 -O0")
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010019 set(CMAKE_C_FLAGS_COVERAGE "-g3 -O0 --coverage")
Manuel Pégourié-Gonnard8505d502014-01-23 17:26:36 +010020 set(CMAKE_C_FLAGS_CHECK "${CMAKE_C_FLAGS} -Werror -Wpointer-arith -Wwrite-strings -Wdocumentation")
Paul Bakker92bc8752013-12-30 17:56:23 +010021endif(CMAKE_COMPILER_IS_CLANG)
22
Paul Bakkerad0db972013-12-30 14:09:27 +010023set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}
24 CACHE STRING "Choose the type of build: None Debug Release Coverage Check CheckFull"
25 FORCE)
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010026
Paul Bakker396c52f2009-07-11 19:54:40 +000027if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
Paul Bakker2015eac2011-07-27 16:52:28 +000028 if(CMAKE_COMPILER_IS_GNUCC)
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010029 set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
Paul Bakker2015eac2011-07-27 16:52:28 +000030 endif(CMAKE_COMPILER_IS_GNUCC)
Manuel Pégourié-Gonnard0933d1f2014-01-31 13:16:30 +010031 if(CMAKE_COMPILER_IS_CLANG)
32 set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
33 endif(CMAKE_COMPILER_IS_CLANG)
Paul Bakker396c52f2009-07-11 19:54:40 +000034endif(CMAKE_BUILD_TYPE STREQUAL "Coverage")
Paul Bakker367dae42009-06-28 21:50:27 +000035
Paul Bakkerb06819b2011-01-18 16:18:38 +000036option(USE_PKCS11_HELPER_LIBRARY "Build PolarSSL with the pkcs11-helper library." OFF)
37
Paul Bakker92eeea42012-07-03 15:10:33 +000038option(ENABLE_ZLIB_SUPPORT "Build PolarSSL with zlib library." OFF)
39
Paul Bakker091e2872011-07-13 11:45:58 +000040if(LIB_INSTALL_DIR)
41else()
Paul Bakkerb3b49012011-12-11 11:28:52 +000042set(LIB_INSTALL_DIR lib)
Paul Bakker091e2872011-07-13 11:45:58 +000043endif()
44
Paul Bakker367dae42009-06-28 21:50:27 +000045include_directories(include/)
46
Paul Bakker92eeea42012-07-03 15:10:33 +000047if(ENABLE_ZLIB_SUPPORT)
48 find_package(ZLIB)
49
50 if(ZLIB_FOUND)
51 include_directories(ZLIB_INCLUDE_DIR)
52 endif(ZLIB_FOUND)
53endif(ENABLE_ZLIB_SUPPORT)
54
Paul Bakker367dae42009-06-28 21:50:27 +000055add_subdirectory(library)
Paul Bakker547f73d2011-01-05 15:07:54 +000056add_subdirectory(include)
Paul Bakker2015eac2011-07-27 16:52:28 +000057
58if(CMAKE_COMPILER_IS_GNUCC)
59 add_subdirectory(tests)
60endif(CMAKE_COMPILER_IS_GNUCC)
Manuel Pégourié-Gonnardbd0de942014-01-18 18:14:16 +010061if(CMAKE_COMPILER_IS_CLANG)
62 add_subdirectory(tests)
63endif(CMAKE_COMPILER_IS_CLANG)
Paul Bakker2015eac2011-07-27 16:52:28 +000064
Paul Bakker1bbeb692009-10-04 15:08:01 +000065add_subdirectory(programs)
Paul Bakkerccba9bc2011-01-05 15:30:32 +000066
67ADD_CUSTOM_TARGET(apidoc
Paul Bakker37ca75d2011-01-06 12:28:03 +000068 COMMAND doxygen doxygen/polarssl.doxyfile
Paul Bakkerccba9bc2011-01-05 15:30:32 +000069 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Manuel Pégourié-Gonnard7669f282013-09-07 16:52:42 +020070
71ADD_CUSTOM_TARGET(memcheck
Manuel Pégourié-Gonnarddeb79492013-09-13 13:43:43 +020072 COMMAND ctest -O memcheck.log -D ExperimentalMemCheck
Manuel Pégourié-Gonnard7669f282013-09-07 16:52:42 +020073 COMMAND tail -n1 memcheck.log | grep 'Memory checking results:' > /dev/null
74 COMMAND rm -f memcheck.log
75 )