Skip to content

Commit 5557a02

Browse files
authored
Merge pull request #23 from mujx/cmake-support
Add CMake support
2 parents 700367d + 9a44a03 commit 5557a02

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

CMakeLists.txt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
3+
project(qhotkey VERSION 1.2.2 LANGUAGES CXX)
4+
5+
option(QHOTKEY_EXAMPLES "Build examples" ON)
6+
7+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
8+
9+
find_package(Qt5 COMPONENTS Core Widgets REQUIRED)
10+
11+
qt5_wrap_cpp(MOC_HEADERS
12+
QHotkey/qhotkey.h
13+
QHotkey/qhotkey_p.h)
14+
15+
set(LIBS
16+
Qt5::Core
17+
Qt5::Widgets)
18+
19+
set(SRC_FILES
20+
QHotkey/qhotkey.cpp)
21+
22+
if(APPLE)
23+
find_library(CARBON_LIBRARY Carbon)
24+
mark_as_advanced(CARBON_LIBRARY)
25+
26+
set(SRC_FILES ${SRC_FILES} QHotkey/qhotkey_mac.cpp)
27+
set(LIBS ${LIBS} ${CARBON_LIBRARY})
28+
elseif(WIN32)
29+
set(SRC_FILES ${SRC_FILES} QHotkey/qhotkey_win.cpp)
30+
else()
31+
find_package(X11 REQUIRED)
32+
find_package(Qt5X11Extras REQUIRED)
33+
34+
include_directories(${X11_INCLUDE_DIR})
35+
set(LIBS ${LIBS} ${X11_LIBRARIES} Qt5::X11Extras)
36+
set(SRC_FILES ${SRC_FILES} QHotkey/qhotkey_x11.cpp)
37+
endif()
38+
39+
add_library(qhotkey ${SRC_FILES} ${MOC_HEADERS})
40+
add_library(QHotkey::QHotkey ALIAS qhotkey)
41+
target_link_libraries(qhotkey ${LIBS})
42+
43+
target_include_directories(qhotkey
44+
PUBLIC
45+
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/QHotkey>
46+
$<INSTALL_INTERFACE:include>)
47+
48+
set_target_properties(qhotkey PROPERTIES
49+
SOVERSION ${PROJECT_VERSION_MAJOR}
50+
VERSION ${PROJECT_VERSION})
51+
52+
if(QHOTKEY_EXAMPLES)
53+
add_subdirectory(HotkeyTest)
54+
endif()
55+
56+
include(GNUInstallDirs)
57+
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/QHotkey)
58+
59+
install(
60+
TARGETS qhotkey EXPORT QHotkeyConfig
61+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
62+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
63+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
64+
install(FILES
65+
${CMAKE_SOURCE_DIR}/QHotkey/qhotkey.h
66+
${CMAKE_SOURCE_DIR}/QHotkey/QHotkey
67+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/)
68+
install(EXPORT QHotkeyConfig DESTINATION ${INSTALL_CONFIGDIR})
69+
70+
export(TARGETS qhotkey FILE QHotkeyConfig.cmake)

HotkeyTest/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
2+
3+
qt5_wrap_ui(test_UI_HEADERS hottestwidget.ui)
4+
qt5_wrap_cpp(test_MOC_HEADERS hottestwidget.h)
5+
6+
add_executable(HotkeyTest
7+
main.cpp
8+
hottestwidget.cpp
9+
${test_UI_HEADERS}
10+
${test_MOC_HEADERS})
11+
target_link_libraries(HotkeyTest Qt5::Widgets qhotkey)
12+
target_include_directories(HotkeyTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy