Question

I need to differentiate Ubuntu and Debian in a CMakelists.txt. Is someone know how to do that ? I tried to use CMAKE_SYSTEM and CMAKE_SYSTEM_NAME but it returns only informations about the Linux kernel...

Thanks

Was it helpful?

Solution

You could try something like this:

cmake_minimum_required(VERSION 2.8)

file(READ "/etc/issue" ETC_ISSUE)
string(REGEX MATCH "Debian|Ubuntu" DIST ${ETC_ISSUE})

if(DIST STREQUAL "Debian")
    message(STATUS ">>>> Found Debian <<<<")
elseif(DIST STREQUAL "Ubuntu")
    message(STATUS ">>>> Found Ubuntu <<<<")
else()
    message(STATUS ">>>> Found unknown distribution <<<<")
endif()

add_executable(main main.cpp)

This reads the /etc/issue file, which contains the name of the distribution you are using, into the ETC_ISSUE variable. Then you grep for Debian or Ubuntu and save the result in DIST. Now you can check DIST using the if command.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top