link against X11 using find_package

This commit is contained in:
Martchus 2016-03-28 21:57:01 +02:00
parent bffe7b999c
commit 4cca128180
3 changed files with 14 additions and 7 deletions

View File

@ -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}

View File

@ -12,7 +12,7 @@
#ifdef PLATFORM_SPECIFIC_CAPSLOCK_DETECTION
# if defined(Q_OS_WIN32)
# include <windows.h>
# elif defined(Q_OS_UNIX)
# elif defined(X_AVAILABLE)
# include <X11/XKBlib.h>
# 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) {

View File

@ -99,6 +99,7 @@ CONFIG(debug, debug|release) {
contains(DEFINES, PLATFORM_SPECIFIC_CAPSLOCK_DETECTION) {
x11 {
LIBS += -lX11
DEFINES += X_AVAILABLE
}
}