Cmake build: Simplify use of qt5 modules

According to this page:
	http://doc.qt.io/qt-5/cmake-manual.html
the way to replace use of qt5_use_modules() for module "_mod" and target "_target"
is to use
	1.) cmake_minimum_required(VERSION 3.1.0)
	2.) find_package(Qt5${_mod} CONFIG REQUIRED)
	3.) target_link_libraries(${_target} Qt5::${_mod})
The last one sets all reguired libraries, compile flags and needed includes for the ${_target}
This commit is contained in:
Kornel Benko 2018-06-09 23:59:47 +02:00
parent d6b21e20e2
commit 72a2f92239

View File

@ -4,7 +4,7 @@
# Copyright (c) 2006-2011 Peter Kümmel, <syntheticpp@gmx.net>
# Copyright (c) 2008-2011 Kornel Benko, <Kornel.Benko@berlin.de>
cmake_minimum_required(VERSION 2.6.4)
cmake_minimum_required(VERSION 3.1.0)
set(LYX_PROJECT LyX)
@ -48,6 +48,7 @@ if(COMMAND cmake_policy)
cmake_policy(SET CMP0043 NEW)
endif()
cmake_policy(SET CMP0020 NEW)
cmake_policy(SET CMP0075 OLD)
endif()
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
@ -622,7 +623,7 @@ endif()
set(min_qt5_version "5.6")
if(LYX_USE_QT MATCHES "AUTO")
# try qt5 first
find_package(Qt5Core QUIET)
find_package(Qt5Core CONFIG QUIET)
if(Qt5Core_FOUND)
set(LYX_USE_QT "QT5" CACHE STRING "Valid qt version" FORCE)
message(STATUS "Qt5Core_VERSION = ${Qt5Core_VERSION}")
@ -638,14 +639,14 @@ if(LYX_USE_QT MATCHES "AUTO")
endif()
if(LYX_USE_QT MATCHES "QT5")
# set QPA_XCB if QT uses X11
find_package(Qt5Core REQUIRED)
find_package(Qt5Core CONFIG REQUIRED)
if (Qt5Core_FOUND)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Widgets CONFIG REQUIRED)
if(APPLE)
find_package(Qt5MacExtras REQUIRED)
find_package(Qt5MacExtras CONFIG REQUIRED)
endif()
find_package(Qt5X11Extras QUIET)
find_package(Qt5WinExtras QUIET)
find_package(Qt5X11Extras CONFIG QUIET)
find_package(Qt5WinExtras CONFIG QUIET)
set(QTVERSION ${Qt5Core_VERSION})
if (QTVERSION VERSION_LESS ${min_qt5_version})
message(STATUS "QTVERSION = \"${QTVERSION}\"")
@ -658,17 +659,9 @@ if(LYX_USE_QT MATCHES "QT5")
#message(FATAL_ERROR "Wrong Qt-Version")
endif()
macro (qt_use_modules lyxtarget)
if (Qt5_POSITION_INDEPENDENT_CODE
AND (CMAKE_VERSION VERSION_LESS 2.8.12
AND (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
OR CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)))
set_property(TARGET ${lyxtarget} PROPERTY POSITION_INDEPENDENT_CODE ${Qt5_POSITION_INDEPENDENT_CODE})
endif()
foreach (_tg ${ARGN})
find_package(Qt5${_tg} REQUIRED)
include_directories(${Qt5${_tg}_INCLUDE_DIRS})
set_property(TARGET ${lyxtarget} APPEND PROPERTY COMPILE_DEFINITIONS ${Qt5${_tg}_COMPILE_DEFINITIONS})
target_link_libraries(${lyxtarget} ${Qt5${_tg}_LIBRARIES})
find_package(Qt5${_tg} CONFIG REQUIRED)
target_link_libraries(${lyxtarget} Qt5::${_tg})
endforeach()
endmacro()
macro (qt_add_resources)