From 5989f68a47567569a957b81ba64cbd8fef0bccc5 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Tue, 25 Jul 2017 12:31:49 +0200 Subject: Change compile flag and clearer to read Use -O0 with DEBUG instead of -0g Change-Id: I100e2188b34f3506d400379808ce875a4817be8d Signed-off-by: Romain Forlot --- cmake/cmake.d/04-build_options.cmake | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cmake/cmake.d/04-build_options.cmake b/cmake/cmake.d/04-build_options.cmake index d1b25f4..899505f 100644 --- a/cmake/cmake.d/04-build_options.cmake +++ b/cmake/cmake.d/04-build_options.cmake @@ -75,18 +75,19 @@ add_compile_options(-fPIC) # TODO: make more visible readable compile (macro ? split ?) # Compilation option depending on CMAKE_BUILD_TYPE ################################################## -add_compile_options($<$,$,$>:-g>) - -add_compile_options($<$:-ggdb>) -add_compile_options($<$:--coverage>) - -add_compile_options($<$:-Og>) +add_compile_options($<$:-g>) add_compile_options($<$:-O0>) add_compile_options($<$:-pg>) -add_compile_options($<$,$>:-O2>) +add_compile_options($<$:-Wp,-U_FORTIFY_SOURCE>) -add_compile_options($<$,$>:-Wp,-U_FORTIFY_SOURCE>) +add_compile_options($<$:-g>) +add_compile_options($<$:-O0>) +add_compile_options($<$:-ggdb>) +add_compile_options($<$:-Wp,-U_FORTIFY_SOURCE>) +add_compile_options($<$:-g>) +add_compile_options($<$:-O2>) +add_compile_options($<$:--coverage>) # Env variable overload default if(DEFINED ENV{INSTALL_PREFIX}) -- cgit 1.2.3-korg From ec101c751a6359483a00c0c3923d502845f45126 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Tue, 25 Jul 2017 12:40:02 +0200 Subject: 2 Kernel checks available (warning or mandatory) Use 2 differents checks, one specify a mandatory kernel version and the other will output a warning and position a preprocessing variable that can be used in the code to exclude portions of code that use kernel features not available under a certain version. Change-Id: Ifc6848df1a1a448094f5312ea23e6d4837e8ef14 Signed-off-by: Romain Forlot --- cmake/cmake.d/01-variables.cmake | 15 +++++++++++++++ cmake/cmake.d/04-build_options.cmake | 30 +++++++++++++----------------- cmake/config.cmake.sample | 14 +++++++++++--- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/cmake/cmake.d/01-variables.cmake b/cmake/cmake.d/01-variables.cmake index 1bba5ce..3891f53 100644 --- a/cmake/cmake.d/01-variables.cmake +++ b/cmake/cmake.d/01-variables.cmake @@ -71,6 +71,21 @@ else() set(OSRELEASE "NOT DEBIAN OS") endif() +if(DEFINED ENV{SDKTARGETSYSROOT}) + file(STRINGS $ENV{SDKTARGETSYSROOT}/usr/include/linux/version.h LINUX_VERSION_CODE_LINE REGEX "LINUX_VERSION_CODE") +elseif(DEFINED ENV{PKG_CONFIG_SYSROOT_DIR}) + file(STRINGS $ENV{PKG_CONFIG_SYSROOT_DIR}/usr/include/linux/version.h LINUX_VERSION_CODE_LINE REGEX "LINUX_VERSION_CODE") +else() + file(STRINGS /usr/include/linux/version.h LINUX_VERSION_CODE_LINE REGEX "LINUX_VERSION_CODE") +endif() + +string(REGEX MATCH "[0-9]+" LINUX_VERSION_CODE ${LINUX_VERSION_CODE_LINE}) +math(EXPR a "${LINUX_VERSION_CODE} >> 16") +math(EXPR b "(${LINUX_VERSION_CODE} >> 8) & 255") +math(EXPR c "(${LINUX_VERSION_CODE} & 255)") + +set(KERNEL_VERSION "${a}.${b}.${c}") + # Include project configuration # ------------------------------ project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES ${PROJECT_LANGUAGES}) diff --git a/cmake/cmake.d/04-build_options.cmake b/cmake/cmake.d/04-build_options.cmake index 899505f..bc14ee6 100644 --- a/cmake/cmake.d/04-build_options.cmake +++ b/cmake/cmake.d/04-build_options.cmake @@ -33,27 +33,23 @@ if (gcc_minimal_version) endif() endif(gcc_minimal_version) -# Check Kernel minimal version +# Check Kernel mandatory version, will fail the configuration if required version not matched. +if (kernel_mandatory_version) + message (STATUS "${Cyan}-- Check kernel_mandatory_version (found kernel version ${KERNEL_VERSION})${ColourReset}") + if (KERNEL_VERSION VERSION_LESS ${kernel_mandatory_version}) + message(FATAL_ERROR "${Red}**** FATAL: Require at least ${kernel_mandatory_version} please use a recent kernel or source your SDK environment then clean and reconfigure your CMake project.") + endif (KERNEL_VERSION VERSION_LESS ${kernel_mandatory_version}) +endif(kernel_mandatory_version) + +# Check Kernel minimal version just print a Warning about missing features +# and set a definition to be used as preprocessor condition in code to disable +# incompatibles features. if (kernel_minimal_version) - if(DEFINED ENV{SDKTARGETSYSROOT}) - file(STRINGS $ENV{SDKTARGETSYSROOT}/usr/include/linux/version.h LINUX_VERSION_CODE_LINE REGEX "LINUX_VERSION_CODE") - elseif(DEFINED ENV{PKG_CONFIG_SYSROOT_DIR}) - file(STRINGS $ENV{PKG_CONFIG_SYSROOT_DIR}/usr/include/linux/version.h LINUX_VERSION_CODE_LINE REGEX "LINUX_VERSION_CODE") - else() - file(STRINGS /usr/include/linux/version.h LINUX_VERSION_CODE_LINE REGEX "LINUX_VERSION_CODE") - endif() - - string(REGEX MATCH "[0-9]+" LINUX_VERSION_CODE ${LINUX_VERSION_CODE_LINE}) - math(EXPR a "${LINUX_VERSION_CODE} >> 16") - math(EXPR b "(${LINUX_VERSION_CODE} >> 8) & 255") - math(EXPR c "(${LINUX_VERSION_CODE} & 255)") - - set(KERNEL_VERSION "${a}.${b}.${c}") message (STATUS "${Cyan}-- Check kernel_minimal_version (found kernel version ${KERNEL_VERSION})${ColourReset}") - if (KERNEL_VERSION VERSION_LESS ${kernel_minimal_version}) - message(FATAL_ERROR "${Red}**** FATAL: Require at least ${kernel_minimal_version} please use a recent kernel or source your SDK environment then clean and reconfigure your CMake project.") + message(WARNING "${Yellow}**** Warning: Some feature(s) require at least ${kernel_minimal_version}. Please use a recent kernel or source your SDK environment then clean and reconfigure your CMake project.${ColourReset}") endif (KERNEL_VERSION VERSION_LESS ${kernel_minimal_version}) + add_definitions(-DKERNEL_MINIMAL_VERSION_OK) endif(kernel_minimal_version) INCLUDE(FindPkgConfig) diff --git a/cmake/config.cmake.sample b/cmake/config.cmake.sample index fb878a2..b1dda58 100644 --- a/cmake/config.cmake.sample +++ b/cmake/config.cmake.sample @@ -47,10 +47,18 @@ set(PROJECT_APP_TEMPLATES_DIR "conf.d/app-templates") # ---------------------------------- set(CMAKE_BUILD_TYPE "DEBUG") -# Kernel selection if needed. Impose a minimal version. -# NOTE FOR NOW IT CHECKS KERNEL Yocto SDK Kernel version -# else only HOST VERSION +# Kernel selection if needed. You can choose between a +# mandatory version to Impose a minimal version. +# else only HOST VERSION. Or check Kernel minimal version +# and just print a Warning about missing features and set +# a define variable to be used as preprocessor condition +# in code to disable incompatibles features. Preprocessor +# define is named KERNEL_MINIMAL_VERSION_OK. +# +# NOTE*** FOR NOW IT CHECKS KERNEL Yocto environment and +# Yocto SDK Kernel version. # ----------------------------------------------- +#set (kernel_mandatory_version 4.8) #set (kernel_minimal_version 4.8) # Compiler selection if needed. Impose a minimal version. -- cgit 1.2.3-korg From 8f3bc0b6f25a5560a308078342a8ed3cc6dba13f Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Tue, 25 Jul 2017 13:51:28 +0200 Subject: Comment Change-Id: I5a78f103c29c3535d332172ee0b0547de79cc193 Signed-off-by: Romain Forlot --- cmake/config.cmake.sample | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmake/config.cmake.sample b/cmake/config.cmake.sample index b1dda58..23f1e80 100644 --- a/cmake/config.cmake.sample +++ b/cmake/config.cmake.sample @@ -48,12 +48,12 @@ set(PROJECT_APP_TEMPLATES_DIR "conf.d/app-templates") set(CMAKE_BUILD_TYPE "DEBUG") # Kernel selection if needed. You can choose between a -# mandatory version to Impose a minimal version. -# else only HOST VERSION. Or check Kernel minimal version -# and just print a Warning about missing features and set -# a define variable to be used as preprocessor condition -# in code to disable incompatibles features. Preprocessor -# define is named KERNEL_MINIMAL_VERSION_OK. +# mandatory version to impose a minimal version. +# Or check Kernel minimal version and just print a Warning +# about missing features and define a preprocessor variable +# to be used as preprocessor condition in code to disable +# incompatibles features. Preprocessor define is named +# KERNEL_MINIMAL_VERSION_OK. # # NOTE*** FOR NOW IT CHECKS KERNEL Yocto environment and # Yocto SDK Kernel version. -- cgit 1.2.3-korg From dee58363ddb98f8e63239035f1a8f1ab151c5e96 Mon Sep 17 00:00:00 2001 From: Jan-Simon Möller Date: Wed, 26 Jul 2017 20:47:40 +0200 Subject: Fix logic bug in addition of -DKERNEL_MINIMAL_VERSION MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -DKERNEL_MINIMAL_VERSION_OK was always set. Move it into else case. Change-Id: Icc7e0982584bce6134611a7724e9d1ef36602360 Signed-off-by: Jan-Simon Möller --- cmake/cmake.d/04-build_options.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/cmake.d/04-build_options.cmake b/cmake/cmake.d/04-build_options.cmake index bc14ee6..18a1b17 100644 --- a/cmake/cmake.d/04-build_options.cmake +++ b/cmake/cmake.d/04-build_options.cmake @@ -48,8 +48,9 @@ if (kernel_minimal_version) message (STATUS "${Cyan}-- Check kernel_minimal_version (found kernel version ${KERNEL_VERSION})${ColourReset}") if (KERNEL_VERSION VERSION_LESS ${kernel_minimal_version}) message(WARNING "${Yellow}**** Warning: Some feature(s) require at least ${kernel_minimal_version}. Please use a recent kernel or source your SDK environment then clean and reconfigure your CMake project.${ColourReset}") + else (KERNEL_VERSION VERSION_LESS ${kernel_minimal_version}) + add_definitions(-DKERNEL_MINIMAL_VERSION_OK) endif (KERNEL_VERSION VERSION_LESS ${kernel_minimal_version}) - add_definitions(-DKERNEL_MINIMAL_VERSION_OK) endif(kernel_minimal_version) INCLUDE(FindPkgConfig) -- cgit 1.2.3-korg