X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=cmake%2Fcmake.d%2F04-build_options.cmake;h=3db685c174756c6965573778db334e4641d34d18;hb=735b677e54a31a411fcb770f1f9696f0d606244d;hp=aacad64b95a02d6b344e18e621b90e3a878e49e1;hpb=0fc19b3bd78758bdcbc2c5e3a2188ce3173406c9;p=staging%2Fxdg-launcher.git diff --git a/cmake/cmake.d/04-build_options.cmake b/cmake/cmake.d/04-build_options.cmake index aacad64..3db685c 100644 --- a/cmake/cmake.d/04-build_options.cmake +++ b/cmake/cmake.d/04-build_options.cmake @@ -33,26 +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}") + else (KERNEL_VERSION VERSION_LESS ${kernel_minimal_version}) + add_definitions(-DKERNEL_MINIMAL_VERSION_OK) endif (KERNEL_VERSION VERSION_LESS ${kernel_minimal_version}) endif(kernel_minimal_version) @@ -64,23 +61,42 @@ INCLUDE(GNUInstallDirs) # Default compilation options ############################################################################ link_libraries(-Wl,--as-needed -Wl,--gc-sections) -add_compile_options(-Wall -Wextra -Wconversion) -add_compile_options(-Wno-unused-parameter) # frankly not using a parameter does it care? -add_compile_options(-Wno-sign-compare -Wno-sign-conversion) -add_compile_options(-Werror=maybe-uninitialized) -add_compile_options(-Werror=implicit-function-declaration) -add_compile_options(-ffunction-sections -fdata-sections) -add_compile_options(-fPIC) - -set(CMAKE_C_FLAGS_PROFILING "-g -O0 -pg -Wp,-U_FORTIFY_SOURCE" CACHE STRING "Flags for profiling") -set(CMAKE_C_FLAGS_DEBUG "-g -Og -ggdb -Wp,-U_FORTIFY_SOURCE" CACHE STRING "Flags for debugging") -set(CMAKE_C_FLAGS_RELEASE "-O2" CACHE STRING "Flags for releasing") -set(CMAKE_C_FLAGS_CCOV "-g -O2 --coverage" CACHE STRING "Flags for coverage test") - -set(CMAKE_CXX_FLAGS_PROFILING "-g -O0 -pg -Wp,-U_FORTIFY_SOURCE" CACHE STRING "Flags for profiling") -set(CMAKE_CXX_FLAGS_DEBUG "-g -Og -ggdb -Wp,-U_FORTIFY_SOURCE" CACHE STRING "Flags for debugging") -set(CMAKE_CXX_FLAGS_RELEASE "-O2" CACHE STRING "Flags for releasing") -set(CMAKE_CXX_FLAGS_CCOV "-g -O2 --coverage" CACHE STRING "Flags for coverage test") +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") +foreach(option ${COMPILE_OPTIONS}) + add_compile_options($<$:${option}>) +endforeach() + +# Compilation OPTIONS depending on language +######################################### + +foreach(option ${COMPILE_OPTIONS}) + add_compile_options(${option}) +endforeach() +foreach(option ${C_COMPILE_OPTIONS}) + add_compile_options($<$:${option}>) +endforeach() +foreach(option ${CXX_COMPILE_OPTIONS}) + add_compile_options($<$:${option}>) +endforeach() + +# Compilation option depending on CMAKE_BUILD_TYPE +################################################## +set(PROFILING_COMPILE_OPTIONS "-g" "-O0" "-pg" "-Wp,-U_FORTIFY_SOURCE" CACHE STRING "Compilation flags for PROFILING build type.") +set(DEBUG_COMPILE_OPTIONS "-g" "-ggdb" "-Wp,-U_FORTIFY_SOURCE" CACHE STRING "Compilation flags for DEBUG build type.") +set(CCOV_COMPILE_OPTIONS "-g" "-O2" "--coverage" CACHE STRING "Compilation flags for CCOV build type.") +set(RELEASE_COMPILE_OPTIONS "-g" "-O2" CACHE STRING "Compilation flags for RELEASE build type.") +foreach(option ${PROFILING_COMPILE_OPTIONS}) + add_compile_options($<$:${option}>) +endforeach() +foreach(option ${DEBUG_COMPILE_OPTIONS}) + add_compile_options($<$:${option}>) +endforeach() +foreach(option ${CCOV_COMPILE_OPTIONS}) + add_compile_options($<$:${option}>) +endforeach() +foreach(option ${RELEASE_COMPILE_OPTIONS}) + add_compile_options($<$:${option}>) +endforeach() # Env variable overload default if(DEFINED ENV{INSTALL_PREFIX}) @@ -96,7 +112,7 @@ foreach (PKG_CONFIG ${PKG_REQUIRED_LIST}) PKG_CHECK_MODULES(${XPREFIX} REQUIRED ${PKG_CONFIG}) INCLUDE_DIRECTORIES(${${XPREFIX}_INCLUDE_DIRS}) - list (APPEND link_libraries ${${XPREFIX}_LDFLAGS}) + list(APPEND link_libraries ${${XPREFIX}_LDFLAGS}) add_compile_options (${${XPREFIX}_CFLAGS}) endforeach(PKG_CONFIG)