From 4cca12818007ceb346416737de450ad84961f474 Mon Sep 17 00:00:00 2001 From: Martchus Date: Mon, 28 Mar 2016 21:57:01 +0200 Subject: [PATCH] link against X11 using find_package --- CMakeLists.txt | 16 +++++++++++----- enterpassworddialog/enterpassworddialog.cpp | 4 ++-- qtutilities.pro | 1 + 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a5fc2c..f1daa48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,7 +107,6 @@ endif(MINGW) add_definitions( -DGUI_QTWIDGETS -DMODEL_UNDO_SUPPORT - -DPLATFORM_SPECIFIC_CAPSLOCK_DETECTION -D_GLIBCXX_USE_CXX11_ABI=0 ) @@ -124,10 +123,17 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) # executable and linking add_library(${META_PROJECT_NAME} SHARED ${HEADER_FILES} ${SRC_FILES} ${WIDGETS_UI_FILES} ${RES_FILES} ${WINDOWS_ICON_PATH}) -if(${CMAKE_SYSTEM_NAME} MATCHES Linux) - set(EXTRA_LIBS X11) +if(WIN32) + # WinAPI provides functions required for capslock detection + add_definitions(-DPLATFORM_SPECIFIC_CAPSLOCK_DETECTION) +else() + # X11 can provide functions required for capslock detection under non-Windows environments + find_package(X11) + if(X11_FOUND) + add_definitions(-DPLATFORM_SPECIFIC_CAPSLOCK_DETECTION -DX_AVAILABLE) + endif() endif() -target_link_libraries(${META_PROJECT_NAME} c++utilities Qt5::Core Qt5::Widgets ${EXTRA_LIBS}) +target_link_libraries(${META_PROJECT_NAME} c++utilities Qt5::Core Qt5::Widgets ${X11_LIBRARIES}) set_target_properties(${META_PROJECT_NAME} PROPERTIES VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH} SOVERSION ${META_VERSION_MAJOR} @@ -136,7 +142,7 @@ set_target_properties(${META_PROJECT_NAME} PROPERTIES if(MINGW) # enable static library when building with mingw-w64 add_library(${META_PROJECT_NAME}_static STATIC ${HEADER_FILES} ${SRC_FILES} ${RES_FILES} ${WINDOWS_ICON_PATH}) - target_link_libraries(${META_PROJECT_NAME}_static c++utilities Qt5::Core Qt5::Widgets ${EXTRA_LIBS}) + target_link_libraries(${META_PROJECT_NAME}_static c++utilities Qt5::Core Qt5::Widgets ${X11_LIBRARIES}) set_target_properties(${META_PROJECT_NAME}_static PROPERTIES VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH} SOVERSION ${META_VERSION_MAJOR} diff --git a/enterpassworddialog/enterpassworddialog.cpp b/enterpassworddialog/enterpassworddialog.cpp index f97f181..608985c 100644 --- a/enterpassworddialog/enterpassworddialog.cpp +++ b/enterpassworddialog/enterpassworddialog.cpp @@ -12,7 +12,7 @@ #ifdef PLATFORM_SPECIFIC_CAPSLOCK_DETECTION # if defined(Q_OS_WIN32) # include -# elif defined(Q_OS_UNIX) +# elif defined(X_AVAILABLE) # include # undef KeyPress # undef KeyRelease @@ -313,7 +313,7 @@ bool EnterPasswordDialog::isCapslockPressed() // platform dependent method of determining if CAPS LOCK is pressed # if defined(Q_OS_WIN32) return GetKeyState(VK_CAPITAL) == 1; -# elif defined(Q_OS_UNIX) +# elif defined(X_AVAILABLE) Display *d = XOpenDisplay((char*)0); bool caps_state = false; if (d) { diff --git a/qtutilities.pro b/qtutilities.pro index c4174f2..ea41bce 100644 --- a/qtutilities.pro +++ b/qtutilities.pro @@ -99,6 +99,7 @@ CONFIG(debug, debug|release) { contains(DEFINES, PLATFORM_SPECIFIC_CAPSLOCK_DETECTION) { x11 { LIBS += -lX11 + DEFINES += X_AVAILABLE } }