diff --git a/libimageviewer/CMakeLists.txt b/libimageviewer/CMakeLists.txt index aee43c77..a341ccb8 100644 --- a/libimageviewer/CMakeLists.txt +++ b/libimageviewer/CMakeLists.txt @@ -1,14 +1,51 @@ -#定义需要的cmake版本 +# Define the required cmake version cmake_minimum_required(VERSION 3.10) -# 设置工程名字 +# Set project name project(libimageviewer VERSION 0.1.0) -# 检查dtkwidget版本 -execute_process(COMMAND dpkg -s libdtkwidget-dev - COMMAND grep Version - TIMEOUT 5 - OUTPUT_VARIABLE DWIDGET_VERSION_STR) +# Check distribution +find_program(LSB_RELEASE lsb_release) + +if(EXISTS "/etc/os-release") + message(STATUS "The file /etc/os-release exists.") +else() + message(FATAL_ERROR "The file /etc/os-release does not exist.") +endif() + +execute_process( + COMMAND lsb_release -i + OUTPUT_VARIABLE LSB_RELEASE_ID + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +# Check dtkwidget version +if (LSB_RELEASE_ID MATCHES "Deepin" OR + LSB_RELEASE_ID MATCHES "UOS" OR + LSB_RELEASE_ID MATCHES "Debian" OR + LSB_RELEASE_ID MATCHES "Ubuntu") + execute_process(COMMAND dpkg -s libdtkwidget-dev + COMMAND grep Version + TIMEOUT 5 + OUTPUT_VARIABLE DWIDGET_VERSION_STR) +elseif (LSB_RELEASE_ID MATCHES "openSUSE" OR + LSB_RELEASE_ID MATCHES "SUSE" OR + LSB_RELEASE_ID MATCHES "Fedora" OR + LSB_RELEASE_ID MATCHES "Redhat" OR + LSB_RELEASE_ID MATCHES "Centos" OR + LSB_RELEASE_ID MATCHES "openEuler") + execute_process(COMMAND rpm -qi dtkwidget-devel + COMMAND grep Version + TIMEOUT 5 + OUTPUT_VARIABLE DWIDGET_VERSION_STR) +elseif (LSB_RELEASE_ID MATCHES "Arch") + execute_process(COMMAND pacman -Qi dtkwidget + COMMAND grep Version + TIMEOUT 5 + OUTPUT_VARIABLE DWIDGET_VERSION_STR) +else() + message(FATAL_ERROR "Unsupport your distribution. Please add your distribution. Exiting.") +endif() string(REPLACE "Version: " "" DWIDGET_VERSION_STR ${DWIDGET_VERSION_STR}) message(STATUS "BUILD DTKWidget VERSION ${DWIDGET_VERSION_STR}")