summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuigi Toscano <luigi.toscano@tiscali.it>2016-10-29 13:59:27 (GMT)
committerLuigi Toscano <luigi.toscano@tiscali.it>2016-10-29 15:47:15 (GMT)
commit5cf97d4dd4c0a7d923da350d9babc36860c5e062 (patch)
tree9aa1f605488188d74f810ce214a167681767adb1
parent9cf1978b47cf593618fb64c60c8b8e044ee45a35 (diff)
Dynamically generate the config file for CMake
This is the more modern way. INCLUDE_DIR and LIBRARY are not exported, but the information required are exported through targets and they will be used by the application through target_link_libraries.
-rw-r--r--CMakeLists.txt21
-rw-r--r--QMobipocketConfig.cmake20
-rw-r--r--QMobipocketConfig.cmake.in9
-rw-r--r--lib/CMakeLists.txt2
4 files changed, 28 insertions, 24 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ef68f35..1823efb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,12 +8,14 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_D
include(FeatureSummary)
include(GenerateExportHeader)
include(ECMOptionalAddSubdirectory)
+include(ECMPackageConfigHelpers)
include(ECMSetupVersion)
include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings NO_POLICY_SCOPE)
-find_package(Qt5 5.4 CONFIG REQUIRED Core Gui)
+set(REQUIRED_QT_VERSION 5.4.0)
+find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core Gui)
ecm_setup_version("2.0.0"
VARIABLE_PREFIX QMOBIPOCKET
@@ -34,10 +36,23 @@ if(STRIGI_STREAMS_LIBRARY)
ecm_optional_add_subdirectory(strigi)
endif()
+set(CMAKECONFIG_INSTALL_DIR "${LIB_INSTALL_DIR}/cmake/QMobipocket")
+
+ecm_configure_package_config_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/QMobipocketConfig.cmake.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/QMobipocketConfig.cmake"
+ INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
+)
+
+install(EXPORT QMobipocketTargets
+ DESTINATION ${CMAKECONFIG_INSTALL_DIR}
+ FILE QMobipocketTargets.cmake
+)
+
install(FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/QMobipocketConfig.cmake
+ ${CMAKE_CURRENT_BINARY_DIR}/QMobipocketConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/QMobipocketConfigVersion.cmake
- DESTINATION ${LIB_INSTALL_DIR}/cmake/QMobipocket
+ DESTINATION ${CMAKECONFIG_INSTALL_DIR}
)
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
diff --git a/QMobipocketConfig.cmake b/QMobipocketConfig.cmake
deleted file mode 100644
index d615afc..0000000
--- a/QMobipocketConfig.cmake
+++ /dev/null
@@ -1,20 +0,0 @@
-get_filename_component( _currentDir ${CMAKE_CURRENT_LIST_FILE} PATH)
-get_filename_component( _currentDir ${_currentDir} PATH)
-get_filename_component( _currentDir ${_currentDir} PATH)
-get_filename_component( _currentDir ${_currentDir} PATH)
-
-# find the full paths to the library and the includes:
-find_path(QMOBIPOCKET_INCLUDE_DIR qmobipocket/mobipocket.h
- HINTS ${_currentDir}/include
- NO_DEFAULT_PATH)
-
-find_library(QMOBIPOCKET_LIBRARY qmobipocket
- HINTS ${_currentDir}/lib
- NO_DEFAULT_PATH)
-
-set(QMOBIPOCKET_LIBRARIES ${QMOBIPOCKET_LIBRARY})
-
-if(QMOBIPOCKET_INCLUDE_DIR AND QMOBIPOCKET_LIBRARY)
- set(QMOBIPOCKET_FOUND TRUE)
-endif()
-
diff --git a/QMobipocketConfig.cmake.in b/QMobipocketConfig.cmake.in
new file mode 100644
index 0000000..a99f293
--- /dev/null
+++ b/QMobipocketConfig.cmake.in
@@ -0,0 +1,9 @@
+@PACKAGE_INIT@
+
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
+
+find_dependency(Qt5Core "@REQUIRED_QT_VERSION@")
+find_dependency(Qt5Gui "@REQUIRED_QT_VERSION@")
+find_dependency(KF5I18n)
+
+include("${CMAKE_CURRENT_LIST_DIR}/QMobipocketTargets.cmake")
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index f931667..bfa258b 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -20,5 +20,5 @@ install(FILES
DESTINATION ${INCLUDE_INSTALL_DIR}/qmobipocket/ COMPONENT Devel
)
-install(TARGETS qmobipocket ${INSTALL_TARGETS_DEFAULT_ARGS})
+install(TARGETS qmobipocket EXPORT QMobipocketTargets ${INSTALL_TARGETS_DEFAULT_ARGS})
set_target_properties(qmobipocket PROPERTIES VERSION ${QMOBIPOCKET_VERSION} SOVERSION ${QMOBIPOCKET_SOVERSION})