Skip to content

Commit

Permalink
Improve CMake rules
Browse files Browse the repository at this point in the history
* Disable building examples by default.
* Use CMAKE_CURRENT_SOURCE_DIR instead of CMAKE_SOURCE_DIR.
* Add an option to disable install rules.
  • Loading branch information
Shatur committed Jun 6, 2020
1 parent 0352904 commit 055d242
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.1)

project(qhotkey VERSION 1.2.2 LANGUAGES CXX)

option(QHOTKEY_EXAMPLES "Build examples" ON)
option(QHOTKEY_EXAMPLES "Build examples" OFF)
option(QHOTKEY_INSTALL "Enable install rule" ON)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

Expand Down Expand Up @@ -53,18 +54,20 @@ if(QHOTKEY_EXAMPLES)
add_subdirectory(HotkeyTest)
endif()

include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/QHotkey)

install(
TARGETS qhotkey EXPORT QHotkeyConfig
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES
${CMAKE_SOURCE_DIR}/QHotkey/qhotkey.h
${CMAKE_SOURCE_DIR}/QHotkey/QHotkey
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/)
install(EXPORT QHotkeyConfig DESTINATION ${INSTALL_CONFIGDIR})

export(TARGETS qhotkey FILE QHotkeyConfig.cmake)
if(QHOTKEY_INSTALL)
include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/QHotkey)

install(
TARGETS qhotkey EXPORT QHotkeyConfig
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/QHotkey/qhotkey.h
${CMAKE_CURRENT_SOURCE_DIR}/QHotkey/QHotkey
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/)
install(EXPORT QHotkeyConfig DESTINATION ${INSTALL_CONFIGDIR})

export(TARGETS qhotkey FILE QHotkeyConfig.cmake)
endif()

0 comments on commit 055d242

Please sign in to comment.