Prevent theoretical buffer overlow to make Coverity more happy (Coverity #181104)
[oonf.git] / CMakeLists.txt
1 project (OONF C)
2 cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
3
4 ########################################################
5 #### Set a default build type if none was specified ####
6 ########################################################
7
8 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
9   message(STATUS "Setting build type to 'Debug' as none was specified.")
10   set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
11   # Set the possible values of build type for cmake-gui
12   set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
13     "MinSizeRel" "RelWithDebInfo")
14 endif()
15
16 ###########################
17 #### API configuration ####
18 ###########################
19
20 # set cached variables
21 include (./cmake/lib_config.cmake)
22
23 # include compiler flags
24 include (./cmake/cc_flags.cmake)
25
26 # include global variables
27 include (./CMakeListsGlobal.cmake)
28
29 ########################################
30 #### get repository tag and version ####
31 ########################################
32
33 include (cmake/get_version.cmake)
34 IF(EXISTS "${PROJECT_BINARY_DIR}/version.cmake")
35   include (${PROJECT_BINARY_DIR}/version.cmake)
36 ENDIF()
37
38 ########################
39 #### Doxygen target ####
40 ########################
41
42 find_package(Doxygen)
43 if(DOXYGEN_FOUND)
44     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/files/framework.doxyfile.in
45         ${CMAKE_CURRENT_BINARY_DIR}/framework.doxyfile @ONLY)
46     add_custom_target(doc
47         ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/framework.doxyfile
48         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
49         COMMENT "Generating API documentation with Doxygen" VERBATIM
50     )
51 endif(DOXYGEN_FOUND)
52
53 #############################
54 #### add tarball targets ####
55 #############################
56
57 ADD_CUSTOM_TARGET(targz  COMMAND ${CMAKE_COMMAND}
58                                  -D SOURCE:STRING=${CMAKE_SOURCE_DIR}
59                                  -D BINARY:STRING=${PROJECT_BINARY_DIR}
60                                  -D VERSION:STRING=${VERSION}
61                                  -D FORMAT:STRING=tar.gz
62                                  -D TARBALL:STRING=${TARBALL}
63                                  -D TARPREFIX:STRING=${TARPREFIX}
64                                  -P ${CMAKE_SOURCE_DIR}/cmake/generate_archive.cmake)
65                                 
66 ADD_CUSTOM_TARGET(tarbz2 COMMAND ${CMAKE_COMMAND}
67                                  -D SOURCE:STRING=${CMAKE_SOURCE_DIR}
68                                  -D BINARY:STRING=${PROJECT_BINARY_DIR}
69                                  -D VERSION:STRING=${VERSION}
70                                  -D FORMAT:STRING=tar.bz2
71                                  -D TARBALL:STRING=${TARBALL}
72                                  -D TARPREFIX:STRING=${TARPREFIX}
73                                  -P ${CMAKE_SOURCE_DIR}/cmake/generate_archive.cmake)
74 ADD_CUSTOM_TARGET(zip    COMMAND ${CMAKE_COMMAND}
75                                  -D SOURCE:STRING=${CMAKE_SOURCE_DIR}
76                                  -D BINARY:STRING=${PROJECT_BINARY_DIR}
77                                  -D VERSION:STRING=${VERSION}
78                                  -D FORMAT:STRING=zip
79                                  -D TARBALL:STRING=${TARBALL}
80                                  -D TARPREFIX:STRING=${TARPREFIX}
81                                  -P ${CMAKE_SOURCE_DIR}/cmake/generate_archive.cmake)
82
83 #########################
84 #### Compile targets ####
85 #########################
86
87 # add define for length of base path
88 string(LENGTH "${CMAKE_SOURCE_DIR}/" BASELENGTH)
89 add_definitions(-DBASEPATH_LENGTH=${BASELENGTH})
90
91 # include build helper
92 include (cmake/declare_library.cmake)
93
94 if (NOT OONF_NO_TESTING)
95     ENABLE_TESTING()
96 endif (NOT OONF_NO_TESTING)
97
98 # define static and dynamic target
99 add_custom_target(static)
100 add_custom_target(dynamic)
101 add_custom_target(build_tests)
102
103 # start compiling core and plugins
104 add_subdirectory(src)
105 add_subdirectory(apps)