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 "./etc/config.cmake"
25 #--------------------------------------------------------------------------
27 include(${PROJECT_APP_TEMPLATES_DIR}/cmake/macros.cmake)
28 include(${PROJECT_APP_TEMPLATES_DIR}/cmake/variables.cmake)
29 include(${PROJECT_APP_TEMPLATES_DIR}/cmake/extra_targets.cmake)
31 # Check GCC minimal version
32 if (gcc_minimal_version)
33 message (STATUS "${Blue}-- Check gcc_minimal_version (found gcc version ${CMAKE_C_COMPILER_VERSION}) (found g++ version ${CMAKE_CXX_COMPILER_VERSION})${ColourReset}")
34 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${gcc_minimal_version} OR CMAKE_C_COMPILER_VERSION VERSION_LESS ${gcc_minimal_version})
35 message(FATAL_ERROR "${Red}**** FATAL: Require at least gcc-${gcc_minimal_version} please set CMAKE_C[XX]_COMPILER")
37 endif(gcc_minimal_version)
39 # Check Kernel minimal version
40 if (kernel_minimal_version)
41 message (STATUS "${Blue}-- Check kernel_minimal_version (found kernel version ${CMAKE_SYSTEM_VERSION})${ColourReset}")
42 if (CMAKE_SYSTEM_VERSION VERSION_LESS ${kernel_minimal_version})
43 message(FATAL_ERROR "${Red}**** FATAL: Require at least ${kernel_minimal_version} please use a recent kernel.")
45 endif(kernel_minimal_version)
47 INCLUDE(FindPkgConfig)
48 INCLUDE(CheckIncludeFiles)
49 INCLUDE(CheckLibraryExists)
50 INCLUDE(GNUInstallDirs)
52 # Default compilation options
53 ############################################################################
54 link_libraries(-Wl,--as-needed -Wl,--gc-sections)
55 add_compile_options(-Wall -Wextra -Wconversion)
56 add_compile_options(-Wno-unused-parameter) # frankly not using a parameter does it care?
57 add_compile_options(-Wno-sign-compare -Wno-sign-conversion)
58 add_compile_options(-Werror=maybe-uninitialized)
59 add_compile_options(-Werror=implicit-function-declaration)
60 add_compile_options(-ffunction-sections -fdata-sections)
61 add_compile_options(-fPIC)
62 add_compile_options(-g)
64 set(CMAKE_C_FLAGS_PROFILING "-g -O2 -pg -Wp,-U_FORTIFY_SOURCE" CACHE STRING "Flags for profiling")
65 set(CMAKE_C_FLAGS_DEBUG "-g -O2 -ggdb -Wp,-U_FORTIFY_SOURCE" CACHE STRING "Flags for debugging")
66 set(CMAKE_C_FLAGS_RELEASE "-O2" CACHE STRING "Flags for releasing")
67 set(CMAKE_C_FLAGS_CCOV "-g -O2 --coverage" CACHE STRING "Flags for coverage test")
69 set(CMAKE_CXX_FLAGS_PROFILING "-g -O0 -pg -Wp,-U_FORTIFY_SOURCE")
70 set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -ggdb -Wp,-U_FORTIFY_SOURCE")
71 set(CMAKE_CXX_FLAGS_RELEASE "-g -O2")
72 set(CMAKE_CXX_FLAGS_CCOV "-g -O2 --coverage")
74 # Env variable overload default
75 if(DEFINED ENV{INSTALL_PREFIX})
76 set (INSTALL_PREFIX $ENV{INSTALL_PREFIX})
78 set(INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/Install" CACHE PATH "The path where to install")
80 set(CMAKE_INSTALL_PREFIX ${INSTALL_PREFIX} CACHE STRING "Installation Prefix")
82 # (BUG!!!) as PKG_CONFIG_PATH does not work [should be en env variable]
83 set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON CACHE BOOLEAN "Flag for using prefix path")
85 # Loop on required package and add options
86 foreach (PKG_CONFIG ${PKG_REQUIRED_LIST})
87 string(REGEX REPLACE "[<>]?=.*$" "" XPREFIX ${PKG_CONFIG})
88 PKG_CHECK_MODULES(${XPREFIX} REQUIRED ${PKG_CONFIG})
90 INCLUDE_DIRECTORIES(${${XPREFIX}_INCLUDE_DIRS})
91 list (APPEND link_libraries ${${XPREFIX}_LDFLAGS})
92 add_compile_options (${${XPREFIX}_CFLAGS})
93 endforeach(PKG_CONFIG)
95 # Optional LibEfence Malloc debug library
96 IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
97 CHECK_LIBRARY_EXISTS(efence malloc "" HAVE_LIBEFENCE)
99 MESSAGE(STATUS "Linking with ElectricFence for debugging purposes...")
100 SET(libefence_LIBRARIES "-lefence")
101 list (APPEND link_libraries ${libefence_LIBRARIES})
102 ENDIF(HAVE_LIBEFENCE)
103 ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG)
105 # set default include directories
106 INCLUDE_DIRECTORIES(${EXTRA_INCLUDE_DIRS})
109 if(NOT BINDINGS_LINK_FLAG)
110 set(BINDINGS_LINK_FLAG "-Wl,--version-script=${PKG_TEMPLATE_PREFIX}/cmake/export.map")