84649fc3efdabf18dea90dc5ac84100dd362dc29
[apps/agl-service-data-persistence.git] / ll-database-binding / conf.d / app-templates / cmake / cmake.d / 01-build_options.cmake
1 ###########################################################################
2 # Copyright 2015, 2016, 2017 IoT.bzh
3 #
4 # author: Fulup Ar Foll <fulup@iot.bzh>
5 # contrib: Romain Forlot <romain.forlot@iot.bzh>
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 ###########################################################################
19
20
21 #--------------------------------------------------------------------------
22 #  WARNING:
23 #     Do not change this cmake template
24 #     Customise your preferences in "./conf.d/cmake/config.cmake"
25 #--------------------------------------------------------------------------
26
27 # (BUG!!!) as PKG_CONFIG_PATH does not work [should be en env variable]
28 set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON CACHE BOOLEAN "Flag for using prefix path")
29
30 INCLUDE(FindPkgConfig)
31 INCLUDE(CheckIncludeFiles)
32 INCLUDE(CheckLibraryExists)
33 INCLUDE(GNUInstallDirs)
34
35 set(CMAKE_BUILD_TYPE Debug CACHE STRING "the type of build")
36 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
37 set(CMP0048 1)
38
39 # Default compilation options
40 ############################################################################
41 link_libraries(-Wl,--as-needed -Wl,--gc-sections)
42 set(COMPILE_OPTIONS -Wall -Wextra -Wconversion -Wno-unused-parameter -Wno-sign-compare -Wno-sign-conversion -Werror=maybe-uninitialized -Werror=implicit-function-declaration -ffunction-sections -fdata-sections -fPIC CACHE STRING "Compilation flags")
43 foreach(option ${COMPILE_OPTIONS})
44         add_compile_options($<$<CONFIG:PROFILING>:${option}>)
45 endforeach()
46
47 # Compilation OPTIONS depending on language
48 #########################################
49 foreach(option ${COMPILE_OPTIONS})
50         add_compile_options(${option})
51 endforeach()
52 foreach(option ${C_COMPILE_OPTIONS})
53         add_compile_options($<$<COMPILE_LANGUAGE:C>:${option}>)
54 endforeach()
55 foreach(option ${CXX_COMPILE_OPTIONS})
56         add_compile_options($<$<COMPILE_LANGUAGE:CXX>:${option}>)
57 endforeach()
58
59 # Compilation option depending on CMAKE_BUILD_TYPE
60 ##################################################
61 set(PROFILING_COMPILE_OPTIONS -g -O0 -pg -Wp,-U_FORTIFY_SOURCE CACHE STRING "Compilation flags for PROFILING build type.")
62 set(DEBUG_COMPILE_OPTIONS -g -ggdb -Wp,-U_FORTIFY_SOURCE CACHE STRING "Compilation flags for DEBUG build type.")
63 set(CCOV_COMPILE_OPTIONS -g -O2 --coverage CACHE STRING "Compilation flags for CCOV build type.")
64 set(RELEASE_COMPILE_OPTIONS -g -O2 CACHE STRING "Compilation flags for RELEASE build type.")
65 foreach(option ${PROFILING_COMPILE_OPTIONS})
66         add_compile_options($<$<CONFIG:PROFILING>:${option}>)
67 endforeach()
68 foreach(option ${DEBUG_COMPILE_OPTIONS})
69         add_compile_options($<$<CONFIG:PROFILING>:${option}>)
70 endforeach()
71 foreach(option ${CCOV_COMPILE_OPTIONS})
72         add_compile_options($<$<CONFIG:PROFILING>:${option}>)
73 endforeach()
74 foreach(option ${RELEASE_COMPILE_OPTIONS})
75         add_compile_options($<$<CONFIG:PROFILING>:${option}>)
76 endforeach()
77
78 # Env variable overload default
79 # Disabled by default now. Tell me if you need really it
80 # but you should not have needs for that since you can
81 # set CMAKE_INSTALL_PREFIX in your config.cmake.
82 #if(DEFINED ENV{INSTALL_PREFIX})
83 #       set(INSTALL_PREFIX $ENV{INSTALL_PREFIX} CACHE PATH "The path where to install")
84 #else()
85 #       set(INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/Install" CACHE PATH "The path where to install")
86 #endif()
87 #set(CMAKE_INSTALL_PREFIX ${INSTALL_PREFIX} CACHE PATH "Installation Prefix")
88
89 # Loop on required package and add options
90 foreach (PKG_CONFIG ${PKG_REQUIRED_LIST})
91         string(REGEX REPLACE "[<>]?=.*$" "" XPREFIX ${PKG_CONFIG})
92         PKG_CHECK_MODULES(${XPREFIX} REQUIRED ${PKG_CONFIG})
93
94         INCLUDE_DIRECTORIES(${${XPREFIX}_INCLUDE_DIRS})
95         list(APPEND link_libraries ${${XPREFIX}_LDFLAGS})
96         add_compile_options (${${XPREFIX}_CFLAGS})
97 endforeach(PKG_CONFIG)
98
99 # Optional LibEfence Malloc debug library
100 IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
101 CHECK_LIBRARY_EXISTS(efence malloc "" HAVE_LIBEFENCE)
102 IF(HAVE_LIBEFENCE)
103         MESSAGE(STATUS "Linking with ElectricFence for debugging purposes...")
104         SET(libefence_LIBRARIES "-lefence")
105         list (APPEND link_libraries ${libefence_LIBRARIES})
106 ENDIF(HAVE_LIBEFENCE)
107 ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG)
108
109 # set default include directories
110 INCLUDE_DIRECTORIES(${EXTRA_INCLUDE_DIRS})
111
112 # Default Linkflag
113 set (PKG_TEMPLATE_PREFIX ${CMAKE_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR} CACHE PATH "Default Package Templates Directory")
114 if(NOT BINDINGS_LINK_FLAG)
115         set(BINDINGS_LINK_FLAG "-Wl,--version-script=${PKG_TEMPLATE_PREFIX}/cmake/export.map")
116 endif()