I assume that you want to evaluate the display server at compile time, when you invoke CMake, and not for each compilation. The way CMake works and is hot should be used. One drawback is that you need to re-run CMake for each changed display server.
There is currently no default method for detecting a working display server. Similarly, there is no default code snippet to evaluate the display server using CMake. Just choose one of the screen detection methods that manually works for you or your environment, respectively.
Call this code from CMake and save the result in a variable and use it for your C ++ code.
For example, loginctl show-session $(loginctl | grep $(whoami) | awk '{print $1}') -p Type works for me. Received CMake Check
execute_process( "loginctl show-session $(loginctl | grep $(whoami) | awk '{print $1}') -p Type" OUTPUT_VARIABLE result_display_server) if ("${resulting_display_server}" EQUALS "Type=x11") set(display_server_x11 TRUE) else() set(display_server_x11 FALSE) endif()
You probably need to play around with the condition and check for Type=wayland or similar, so that it works correctly in your environment.
You can use display_server_x11 and write it to the config.h file to use it in C ++ code.
source share