1 ###########################################################################
2 # Copyright 2015, 2016, 2017 IoT.bzh
4 # author: Fulup Ar Foll <fulup@iot.bzh>
5 # contrib: Romain Forlot <romain.forlot@iot.bzh>
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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 ###########################################################################
21 #--------------------------------------------------------------------------
23 # Do not change this cmake template
24 # Customise your preferences in "./conf.d/cmake/config.cmake"
25 #--------------------------------------------------------------------------
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")
30 INCLUDE(FindPkgConfig)
31 INCLUDE(CheckIncludeFiles)
32 INCLUDE(CheckLibraryExists)
33 INCLUDE(GNUInstallDirs)
35 set(CMAKE_BUILD_TYPE Debug CACHE STRING "the type of build")
36 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
39 # Default compilation options
40 ############################################################################
41 link_libraries(-Wl,--as-needed -Wl,--gc-sections)
42 set(COMPILE_OPTIONS -Wall
48 -Werror=implicit-function-declaration
51 -fPIC CACHE STRING "Compilation flags")
53 set(COMPILE_OPTIONS_GNU -Werror=maybe-uninitialized CACHE STRING "GNU Compile specific options")
54 set(COMPILE_OPTIONS_CLANG -Werror=uninitialized CACHE STRING "CLang compile specific options")
56 # Compilation OPTIONS depending on language
57 #########################################
58 foreach(option ${COMPILE_OPTIONS})
59 add_compile_options(${option})
62 if (${CMAKE_C_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
63 foreach(option ${COMPILE_OPTIONS_GNU})
64 add_compile_options(${option})
66 elseif(${CMAKE_C_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
67 foreach(option ${COMPILE_OPTIONS_CLANG})
68 add_compile_options(${option})
72 foreach(option ${C_COMPILE_OPTIONS})
73 add_compile_options($<$<COMPILE_LANGUAGE:C>:${option}>)
75 foreach(option ${CXX_COMPILE_OPTIONS})
76 add_compile_options($<$<COMPILE_LANGUAGE:CXX>:${option}>)
79 # Compilation option depending on CMAKE_BUILD_TYPE
80 ##################################################
81 set(PROFILING_COMPILE_OPTIONS -g -O0 -pg -Wp,-U_FORTIFY_SOURCE CACHE STRING "Compilation flags for PROFILING build type.")
82 set(DEBUG_COMPILE_OPTIONS -g -ggdb -Og -D_FORTIFY_SOURCE=2 CACHE STRING "Compilation flags for DEBUG build type.")
83 set(COVERAGE_COMPILE_OPTIONS -g --coverage CACHE STRING "Compilation flags for COVERAGE build type.")
84 set(RELEASE_COMPILE_OPTIONS -O2 -D_FORTIFY_SOURCE=2 CACHE STRING "Compilation flags for RELEASE build type.")
85 foreach(option ${PROFILING_COMPILE_OPTIONS})
86 add_compile_options($<$<CONFIG:PROFILING>:${option}>)
88 foreach(option ${DEBUG_COMPILE_OPTIONS})
89 add_compile_options($<$<CONFIG:DEBUG>:${option}>)
91 foreach(option ${COVERAGE_COMPILE_OPTIONS})
92 add_compile_options($<$<CONFIG:COVERAGE>:${option}>)
94 foreach(option ${RELEASE_COMPILE_OPTIONS})
95 add_compile_options($<$<CONFIG:RELEASE>:${option}>)
98 # Loop on required package and add options
99 foreach (PKG_CONFIG ${PKG_REQUIRED_LIST})
100 string(REGEX REPLACE "[<>]?=.*$" "" XPREFIX ${PKG_CONFIG})
101 PKG_CHECK_MODULES(${XPREFIX} REQUIRED ${PKG_CONFIG})
103 INCLUDE_DIRECTORIES(${${XPREFIX}_INCLUDE_DIRS})
104 list(APPEND link_libraries ${${XPREFIX}_LDFLAGS})
105 add_compile_options (${${XPREFIX}_CFLAGS})
106 endforeach(PKG_CONFIG)
108 # Optional LibEfence Malloc debug library
109 IF(CMAKE_BUILD_TYPE MATCHES DEBUG AND USE_EFENCE)
110 CHECK_LIBRARY_EXISTS(efence malloc "" HAVE_LIBEFENCE)
112 MESSAGE(STATUS "Linking with ElectricFence for debugging purposes...")
113 SET(libefence_LIBRARIES "-lefence")
114 list (APPEND link_libraries ${libefence_LIBRARIES})
115 ENDIF(HAVE_LIBEFENCE)
116 ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG AND USE_EFENCE)
118 # set default include directories
119 INCLUDE_DIRECTORIES(${EXTRA_INCLUDE_DIRS})
122 set(PKG_TEMPLATE_PREFIX "\"${CMAKE_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}\"" CACHE PATH "Default Package Templates Directory")
123 set(BARE_PKG_TEMPLATE_PREFIX "${CMAKE_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}" CACHE PATH "Default Package Templates Directory")
125 if(NOT BINDINGS_LINK_FLAG)
126 set(BINDINGS_LINK_FLAG "-Wl,--version-script=${PKG_TEMPLATE_PREFIX}/cmake/export.map")