summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-08-23 16:44:00 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-10-15 18:22:47 +0200
commitceaac96060b51a87f40dcad5ae652ad393815a88 (patch)
tree3ba5e0b2cd4aca1e35658560c8b307e0936ceeb2
parent7b841b8b3ecbf66d8a32f1499e8892fa795a650a (diff)
Enhances OS detection with Yocto and SDK
Change-Id: I27f70c3ef9f16d918353e00c0535351bd738df82 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--cmake/cmake.d/02-variables.cmake40
1 files changed, 22 insertions, 18 deletions
diff --git a/cmake/cmake.d/02-variables.cmake b/cmake/cmake.d/02-variables.cmake
index 285648f..54a362d 100644
--- a/cmake/cmake.d/02-variables.cmake
+++ b/cmake/cmake.d/02-variables.cmake
@@ -48,10 +48,29 @@ endif()
# Native packaging name
set(NPKG_PROJECT_NAME agl-${PROJECT_NAME})
+if(DEFINED ENV{SDKTARGETSYSROOT})
+file(STRINGS $ENV{SDKTARGETSYSROOT}/usr/include/linux/version.h LINUX_VERSION_CODE_LINE REGEX "LINUX_VERSION_CODE")
+set(BUILD_ENV_SYSROOT $ENV{SDKTARGETSYSROOT})
+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")
+set(BUILD_ENV_SYSROOT $ENV{PKG_CONFIG_SYSROOT_DIR})
+else()
+file(STRINGS /usr/include/linux/version.h LINUX_VERSION_CODE_LINE REGEX "LINUX_VERSION_CODE")
+set(BUILD_ENV_SYSROOT "")
+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}")
+
# Get the os type
# Used to package .deb
-if(EXISTS "/etc/os-release")
- execute_process(COMMAND bash "-c" "grep -E '^ID(_LIKE)?=' /etc/os-release | tail -n 1"
+set(OS_RELEASE_PATH "${BUILD_ENV_SYSROOT}/etc/os-release")
+if(EXISTS ${OS_RELEASE_PATH})
+ execute_process(COMMAND bash "-c" "grep -E '^ID(_LIKE)?=' ${OS_RELEASE_PATH} | tail -n 1"
OUTPUT_VARIABLE TMP_OSRELEASE
)
@@ -62,25 +81,10 @@ if(EXISTS "/etc/os-release")
endif()
else()
- set(OSRELEASE "NOT COMPATIBLE ! Missing /etc/os-release file.")
+ set(OSRELEASE "NOT COMPATIBLE ! Missing ${OS_RELEASE_PATH} file.")
endif()
message(STATUS "Distribution used ${OSRELEASE}")
-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})