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.