Teach CMake about Qt 5 plugins.

Change-Id: Idd3225759f9f5ec620f79e29035eb176f965bef7
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Stephen Kelly 2013-08-15 16:45:23 +02:00 committed by The Qt Project
parent 9d3866ed32
commit 955052c0d9
5 changed files with 110 additions and 0 deletions

View File

@ -49,6 +49,12 @@ contains(CMAKE_BIN_DIR, "^\\.\\./.*") {
CMAKE_BIN_DIR_IS_ABSOLUTE = True
}
CMAKE_PLUGIN_DIR = $$cmakeRelativePath($$[QT_INSTALL_PLUGINS], $$[QT_INSTALL_PREFIX])
contains(CMAKE_PLUGIN_DIR, "^\\.\\./.*") {
CMAKE_PLUGIN_DIR = $$[QT_INSTALL_PLUGINS]/
CMAKE_PLUGIN_DIR_IS_ABSOLUTE = True
}
!isEmpty(DLLDESTDIR):!static:!staticlib {
CMAKE_DLL_DIR = $$cmakeRelativePath($$[QT_INSTALL_BINS], $$[QT_INSTALL_PREFIX])
contains(CMAKE_DLL_DIR, "^\\.\\./.*") {
@ -83,6 +89,48 @@ equals(QMAKE_HOST.os, Windows): CMAKE_BIN_SUFFIX = ".exe"
if(build_all|CONFIG(debug, debug|release)): CMAKE_DEBUG_TYPE = debug
if(build_all|CONFIG(release, debug|release)): CMAKE_RELEASE_TYPE = release
contains(CONFIG, plugin) {
equals(PLUGIN_TYPE, bearer): PLUGIN_MODULE_NAME = network
else:equals(PLUGIN_TYPE, sqldrivers): PLUGIN_MODULE_NAME = sql
else:equals(PLUGIN_TYPE, accessible): PLUGIN_MODULE_NAME = widgets
else:equals(PLUGIN_TYPE, imageformats): PLUGIN_MODULE_NAME = gui
else:equals(PLUGIN_TYPE, platforminputcontexts): PLUGIN_MODULE_NAME = gui
else:equals(PLUGIN_TYPE, platformthemes): PLUGIN_MODULE_NAME = gui
else:equals(PLUGIN_TYPE, generic): PLUGIN_MODULE_NAME = gui
else:equals(PLUGIN_TYPE, platforms): PLUGIN_MODULE_NAME = gui
else: return()
CMAKE_MODULE_NAME = $$cmakeModuleName($$PLUGIN_MODULE_NAME)
CMAKE_PLUGIN_NAME = $$PLUGIN_CLASS_NAME
win32 {
CMAKE_PLUGIN_LOCATION_RELEASE = $$PLUGIN_TYPE/$${TARGET}.dll
CMAKE_PLUGIN_LOCATION_DEBUG = $$PLUGIN_TYPE/$${TARGET}d.dll
} else {
mac {
CMAKE_PLUGIN_LOCATION_RELEASE = $$PLUGIN_TYPE/lib$${TARGET}.dylib
CMAKE_PLUGIN_LOCATION_DEBUG = $$PLUGIN_TYPE/lib$${TARGET}.dylib
} else {
CMAKE_PLUGIN_LOCATION_RELEASE = $$PLUGIN_TYPE/lib$${TARGET}.so
CMAKE_PLUGIN_LOCATION_DEBUG = $$PLUGIN_TYPE/lib$${TARGET}.so
}
}
cmake_target_file.input = $$PWD/data/cmake/Qt5PluginTarget.cmake.in
cmake_target_file.output = $$DESTDIR/../../$${CMAKE_LIB_DIR}cmake/Qt5$${CMAKE_MODULE_NAME}/Qt5$${CMAKE_MODULE_NAME}_$${PLUGIN_CLASS_NAME}.cmake
!build_pass:QMAKE_SUBSTITUTES += \
cmake_target_file
cmake_qt5_plugin_file.files = $$cmake_target_file.output
cmake_qt5_plugin_file.path = $$[QT_INSTALL_LIBS]/cmake/Qt5$${CMAKE_MODULE_NAME}
INSTALLS += cmake_qt5_plugin_file
return()
}
contains($$list(network sql widgets gui), $$MODULE): CMAKE_LOAD_PLUGINS = true
unix:contains(QT_CONFIG, reduce_relocations):CMAKE_ADD_FPIE_FLAGS = "true"
CMAKE_MKSPEC = $$[QMAKE_XSPEC]

View File

@ -280,6 +280,28 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
!!ENDIF // CMAKE_DEBUG_TYPE
!!IF !isEmpty(CMAKE_LOAD_PLUGINS)
macro(_populate_$${CMAKE_MODULE_NAME}_plugin_properties Plugin Configuration PLUGIN_LOCATION)
set_property(TARGET Qt5::${Plugin} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${Configuration})
!!IF isEmpty(CMAKE_PLUGIN_DIR_IS_ABSOLUTE)
set(imported_location \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_PLUGIN_DIR}${PLUGIN_LOCATION}\")
!!ELSE
set(imported_location \"$${CMAKE_PLUGIN_DIR}${PLUGIN_LOCATION}\")
!!ENDIF
_qt5_$${CMAKE_MODULE_NAME}_check_file_exists(${imported_location})
set_target_properties(Qt5::${Plugin} PROPERTIES
\"IMPORTED_LOCATION_${Configuration}\" ${imported_location}
)
endmacro()
file(GLOB pluginTargets \"${CMAKE_CURRENT_LIST_DIR}/Qt5$${CMAKE_MODULE_NAME}_*Plugin.cmake\")
foreach(pluginTarget ${pluginTargets})
include(${pluginTarget})
endforeach()
!!ENDIF
!!IF !isEmpty(CMAKE_MODULE_EXTRAS)
include(\"${CMAKE_CURRENT_LIST_DIR}/Qt5$${CMAKE_MODULE_NAME}ConfigExtras.cmake\")
!!ENDIF

View File

@ -0,0 +1,11 @@
add_library(Qt5::$$CMAKE_PLUGIN_NAME MODULE IMPORTED)
!!IF !isEmpty(CMAKE_RELEASE_TYPE)
_populate_$${CMAKE_MODULE_NAME}_plugin_properties($$CMAKE_PLUGIN_NAME RELEASE \"$${CMAKE_PLUGIN_LOCATION_RELEASE}\")
!!ENDIF
!!IF !isEmpty(CMAKE_DEBUG_TYPE)
_populate_$${CMAKE_MODULE_NAME}_plugin_properties($$CMAKE_PLUGIN_NAME DEBUG \"$${CMAKE_PLUGIN_LOCATION_DEBUG}\")
!!ENDIF
list(APPEND Qt5$${CMAKE_MODULE_NAME}_PLUGINS Qt5::$$CMAKE_PLUGIN_NAME)

View File

@ -47,6 +47,8 @@ INSTALLS += target
TARGET = $$qtLibraryTarget($$TARGET)
CONFIG += create_cmake
load(qt_targets)
load(qt_common)

View File

@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 2.8)
project(test_plugins)
find_package(Qt5Network 5.0.0 REQUIRED)
include_directories(
${Qt5Network_INCLUDE_DIRS}
)
add_definitions(${Qt5Netork_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Netork_EXECUTABLE_COMPILE_FLAGS}")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
if(NOT Qt5Network_PLUGINS)
message(SEND_ERROR "Qt5 network plugins not known!")
endif()
foreach(plugin ${Qt5Network_PLUGINS})
get_target_property(_loc ${plugin} LOCATION)
if (NOT EXISTS "${_loc}")
message(SEND_ERROR "Plugin ${plugin} not found at ${_loc}")
endif()
endforeach()