205 lines
5.5 KiB
CMake
205 lines
5.5 KiB
CMake
# SPDX-FileCopyrightText: (C) 2024 - 2026 Deskflow Developers
|
|
# SPDX-FileCopyrightText: (C) 2024 Symless Ltd
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
macro(configure_libs)
|
|
|
|
set(libs)
|
|
if(UNIX)
|
|
configure_unix_libs()
|
|
elseif(WIN32)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD /O2 /Ob2")
|
|
list(APPEND libs Wtsapi32 Userenv Wininet comsuppw Shlwapi version)
|
|
add_definitions(
|
|
/DWIN32
|
|
/D_WINDOWS
|
|
/D_CRT_SECURE_NO_WARNINGS
|
|
/D_XKEYCHECK_H
|
|
)
|
|
endif()
|
|
|
|
# Check if <format> header is available
|
|
check_cxx_source_compiles("
|
|
#include <format>
|
|
int main() {
|
|
char buffer[100];
|
|
std::format_to_n(buffer, 100, \"test {}\", 42);
|
|
return 0;
|
|
}
|
|
" HAVE_FORMAT)
|
|
|
|
if(HAVE_FORMAT)
|
|
add_definitions(-DHAVE_FORMAT)
|
|
endif()
|
|
endmacro()
|
|
|
|
#
|
|
# Unix (Mac, Linux, BSD, etc)
|
|
#
|
|
macro(configure_unix_libs)
|
|
|
|
if(NOT APPLE)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
|
endif()
|
|
|
|
# For config.h, detect the libraries, functions, etc.
|
|
include(CheckIncludeFiles)
|
|
include(CheckLibraryExists)
|
|
include(CheckFunctionExists)
|
|
include(CheckTypeSize)
|
|
include(CheckIncludeFileCXX)
|
|
include(CheckSymbolExists)
|
|
include(CheckCSourceCompiles)
|
|
include(CheckCXXSourceCompiles)
|
|
|
|
check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
|
|
if (NOT HAVE_SYS_SOCKET_H)
|
|
message(FATAL_ERROR "Missing header: sys/socket.h")
|
|
endif()
|
|
|
|
check_include_files(unistd.h HAVE_UNISTD_H)
|
|
if (NOT HAVE_UNISTD_H)
|
|
message(FATAL_ERROR "Missing unistd.h")
|
|
endif()
|
|
|
|
check_function_exists(sigwait HAVE_POSIX_SIGWAIT)
|
|
if (NOT HAVE_POSIX_SIGWAIT)
|
|
message(FATAL_ERROR "Missing posix sigwait")
|
|
endif()
|
|
|
|
# pthread is used on both Linux and Mac
|
|
check_library_exists("pthread" pthread_create "" HAVE_PTHREAD)
|
|
if(HAVE_PTHREAD)
|
|
list(APPEND libs pthread)
|
|
else()
|
|
message(FATAL_ERROR "Missing library: pthread")
|
|
endif()
|
|
|
|
if(APPLE)
|
|
find_library(lib_ScreenSaver ScreenSaver)
|
|
find_library(lib_IOKit IOKit)
|
|
find_library(lib_ApplicationServices ApplicationServices)
|
|
find_library(lib_Foundation Foundation)
|
|
find_library(lib_Carbon Carbon)
|
|
find_library(lib_UserNotifications UserNotifications)
|
|
list(APPEND libs
|
|
${lib_ScreenSaver} ${lib_IOKit} ${lib_ApplicationServices}
|
|
${lib_Foundation} ${lib_Carbon} ${lib_UserNotifications}
|
|
)
|
|
else()
|
|
|
|
if (BUILD_X11_SUPPORT)
|
|
configure_xorg_libs()
|
|
endif()
|
|
|
|
include(FindPkgConfig)
|
|
find_package(PkgConfig)
|
|
if(PKG_CONFIG_FOUND)
|
|
pkg_check_modules(LIBXKBCOMMON REQUIRED xkbcommon)
|
|
message(STATUS "xkbcommon version: ${LIBXKBCOMMON_VERSION}")
|
|
include_directories(${LIBXKBCOMMON_INCLUDE_DIRS})
|
|
|
|
pkg_check_modules(LIBXKBREGISTRY REQUIRED xkbregistry)
|
|
message(STATUS "xkbregistry version: ${LIBXKBREGISTRY_VERSION}")
|
|
include_directories(${LIBXKBREGISTRY_INCLUDE_DIRS})
|
|
else()
|
|
message(WARNING "pkg-config not found, skipping wayland libraries")
|
|
endif()
|
|
endif()
|
|
endmacro()
|
|
|
|
#
|
|
# X.org/X11 for Linux, BSD, etc
|
|
#
|
|
macro(configure_xorg_libs)
|
|
|
|
# Set include dir for BSD-derived systems
|
|
set(CMAKE_REQUIRED_INCLUDES "/usr/local/include")
|
|
|
|
set(XKBlib "X11/Xlib.h;X11/XKBlib.h")
|
|
set(CMAKE_EXTRA_INCLUDE_FILES "${XKBlib};X11/extensions/Xrandr.h")
|
|
check_type_size("XRRNotifyEvent" X11_EXTENSIONS_XRANDR_H)
|
|
set(HAVE_X11_EXTENSIONS_XRANDR_H "${X11_EXTENSIONS_XRANDR_H}")
|
|
set(CMAKE_EXTRA_INCLUDE_FILES)
|
|
|
|
check_include_files("${XKBlib};X11/extensions/dpms.h"
|
|
HAVE_X11_EXTENSIONS_DPMS_H)
|
|
check_include_files("X11/extensions/Xinerama.h"
|
|
HAVE_X11_EXTENSIONS_XINERAMA_H)
|
|
check_include_files("X11/extensions/XKB.h" HAVE_XKB_EXTENSION)
|
|
check_include_files("X11/extensions/XTest.h" HAVE_X11_EXTENSIONS_XTEST_H)
|
|
check_include_files("${XKBlib}" HAVE_X11_XKBLIB_H)
|
|
check_include_files("X11/extensions/XInput2.h" HAVE_XI2)
|
|
|
|
if(NOT HAVE_X11_XKBLIB_H)
|
|
message(FATAL_ERROR "Missing header: " ${XKBlib})
|
|
endif()
|
|
|
|
# Set library path and -L flag for BSD-derived systems.
|
|
# On our FreeBSD CI, `link_directories` is also needed for some reason.
|
|
set(CMAKE_LIBRARY_PATH "/usr/local/lib")
|
|
set(CMAKE_REQUIRED_FLAGS "-L${CMAKE_LIBRARY_PATH}")
|
|
link_directories(${CMAKE_LIBRARY_PATH})
|
|
|
|
check_library_exists("SM;ICE" IceConnectionNumber "" HAVE_ICE)
|
|
check_library_exists("Xext;X11" DPMSQueryExtension "" HAVE_Xext)
|
|
check_library_exists("Xtst;Xext;X11" XTestQueryExtension "" HAVE_Xtst)
|
|
check_library_exists("Xinerama" XineramaQueryExtension "" HAVE_Xinerama)
|
|
check_library_exists("Xi" XISelectEvents "" HAVE_Xi)
|
|
check_library_exists("Xrandr" XRRQueryExtension "" HAVE_Xrandr)
|
|
|
|
if(HAVE_ICE)
|
|
|
|
# Assume we have SM if we have ICE.
|
|
set(HAVE_SM 1)
|
|
list(APPEND libs SM ICE)
|
|
|
|
endif()
|
|
|
|
if(!X11_xkbfile_FOUND)
|
|
message(FATAL_ERROR "Missing library: xkbfile")
|
|
endif()
|
|
|
|
if(HAVE_Xtst)
|
|
|
|
# Xtxt depends on X11.
|
|
set(HAVE_X11)
|
|
list(
|
|
APPEND
|
|
libs
|
|
Xtst
|
|
X11
|
|
xkbfile)
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Missing library: Xtst")
|
|
|
|
endif()
|
|
|
|
if(HAVE_Xext)
|
|
list(APPEND libs Xext)
|
|
endif()
|
|
|
|
if(HAVE_Xinerama)
|
|
list(APPEND libs Xinerama)
|
|
else(HAVE_Xinerama)
|
|
if(HAVE_X11_EXTENSIONS_XINERAMA_H)
|
|
set(HAVE_X11_EXTENSIONS_XINERAMA_H 0)
|
|
message(WARNING "Old Xinerama implementation detected, disabled")
|
|
endif()
|
|
endif()
|
|
|
|
if(HAVE_Xrandr)
|
|
list(APPEND libs Xrandr)
|
|
endif()
|
|
|
|
# this was outside of the linux scope, not sure why, moving it back inside.
|
|
if(HAVE_Xi)
|
|
list(APPEND libs Xi)
|
|
endif()
|
|
|
|
add_definitions(-DWINAPI_XWINDOWS=1)
|
|
|
|
endmacro()
|