Cmake build: Adapt to compile with qt5.11

Since qt5_use_modules() is removed from QT5 (as spotted
by Jürgen Spitzmüller), we had to create own version
of this macro.

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}

Disable possible warn about not known policy

Extend Clang compiler detection to cover Apple CLang

(cherry picked from commit d6b21e20e2)
(cherry picked from commit 72a2f92239)
(cherry picked from commit 6343452a73)
(cherry picked from commit cb08d4a879)
(cherry picked from commit 1bf4d7b0fc)
This commit is contained in:
Kornel Benko 2018-06-14 13:55:52 +02:00
parent 0eccf87797
commit 889d10cda3
3 changed files with 20 additions and 13 deletions

View File

@ -4,7 +4,7 @@
# Copyright (c) 2006-2011 Peter Kümmel, <syntheticpp@gmx.net> # Copyright (c) 2006-2011 Peter Kümmel, <syntheticpp@gmx.net>
# Copyright (c) 2008-2011 Kornel Benko, <Kornel.Benko@berlin.de> # 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) set(LYX_PROJECT LyX)
@ -47,6 +47,10 @@ if(COMMAND cmake_policy)
# COMPILE_DEFINITIONS are not used yet. Enable new behavior. # COMPILE_DEFINITIONS are not used yet. Enable new behavior.
cmake_policy(SET CMP0043 NEW) cmake_policy(SET CMP0043 NEW)
endif() endif()
cmake_policy(SET CMP0020 NEW)
if(POLICY CMP0075)
cmake_policy(SET CMP0075 OLD)
endif()
endif() endif()
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
@ -260,7 +264,7 @@ if(NOT CXX11COMPILER_FOUND)
endif() endif()
set(LYX_GCC11_MODE) set(LYX_GCC11_MODE)
if(UNIX OR MINGW) if(UNIX OR MINGW)
if (CMAKE_CXX_COMPILER_ID MATCHES "^[cC]lang$") if (CMAKE_CXX_COMPILER_ID MATCHES "^([cC]lang|AppleClang)$")
# ignore the GCC_VERSION for clang # ignore the GCC_VERSION for clang
# and use the resulting CXX11_STD_REGEX found in FindCXX11Compiler.cmake # and use the resulting CXX11_STD_REGEX found in FindCXX11Compiler.cmake
message(STATUS "Using clang") message(STATUS "Using clang")
@ -625,7 +629,7 @@ endif()
set(min_qt5_version "5.6") set(min_qt5_version "5.6")
if(LYX_USE_QT MATCHES "AUTO") if(LYX_USE_QT MATCHES "AUTO")
# try qt5 first # try qt5 first
find_package(Qt5Core QUIET) find_package(Qt5Core CONFIG QUIET)
if(Qt5Core_FOUND) if(Qt5Core_FOUND)
set(LYX_USE_QT "QT5" CACHE STRING "Valid qt version" FORCE) set(LYX_USE_QT "QT5" CACHE STRING "Valid qt version" FORCE)
message(STATUS "Qt5Core_VERSION = ${Qt5Core_VERSION}") message(STATUS "Qt5Core_VERSION = ${Qt5Core_VERSION}")
@ -641,14 +645,14 @@ if(LYX_USE_QT MATCHES "AUTO")
endif() endif()
if(LYX_USE_QT MATCHES "QT5") if(LYX_USE_QT MATCHES "QT5")
# set QPA_XCB if QT uses X11 # set QPA_XCB if QT uses X11
find_package(Qt5Core REQUIRED) find_package(Qt5Core CONFIG REQUIRED)
if (Qt5Core_FOUND) if (Qt5Core_FOUND)
find_package(Qt5Widgets REQUIRED) find_package(Qt5Widgets CONFIG REQUIRED)
if(APPLE) if(APPLE)
find_package(Qt5MacExtras REQUIRED) find_package(Qt5MacExtras CONFIG REQUIRED)
endif() endif()
find_package(Qt5X11Extras QUIET) find_package(Qt5X11Extras CONFIG QUIET)
find_package(Qt5WinExtras QUIET) find_package(Qt5WinExtras CONFIG QUIET)
set(QTVERSION ${Qt5Core_VERSION}) set(QTVERSION ${Qt5Core_VERSION})
if (QTVERSION VERSION_LESS ${min_qt5_version}) if (QTVERSION VERSION_LESS ${min_qt5_version})
message(STATUS "QTVERSION = \"${QTVERSION}\"") message(STATUS "QTVERSION = \"${QTVERSION}\"")
@ -660,8 +664,11 @@ if(LYX_USE_QT MATCHES "QT5")
# Subject: cmake compilation error # Subject: cmake compilation error
#message(FATAL_ERROR "Wrong Qt-Version") #message(FATAL_ERROR "Wrong Qt-Version")
endif() endif()
macro (qt_use_modules) macro (qt_use_modules lyxtarget)
qt5_use_modules(${ARGN}) foreach (_tg ${ARGN})
find_package(Qt5${_tg} CONFIG REQUIRED)
target_link_libraries(${lyxtarget} Qt5::${_tg})
endforeach()
endmacro() endmacro()
macro (qt_add_resources) macro (qt_add_resources)
qt5_add_resources(${ARGN}) qt5_add_resources(${ARGN})
@ -698,7 +705,7 @@ endif()
find_package(Magic) find_package(Magic)
if(Magic_FOUND) if(Magic_FOUND)
set(HAVE_MAGIC_H 1) set(HAVE_MAGIC_H 1)
endif() endif()
include_directories(${TOP_BINARY_DIR} ${TOP_SRC_DIR}/src) include_directories(${TOP_BINARY_DIR} ${TOP_SRC_DIR}/src)

View File

@ -2,7 +2,7 @@
Building LyX with CMake Building LyX with CMake
========================= =========================
Install CMake from www.cmake.org or your distribution (version >= 2.6.4). Install CMake from www.cmake.org or your distribution (version >= 3.1.0).

View File

@ -34,7 +34,7 @@
INCLUDE(CheckCXXSourceCompiles) INCLUDE(CheckCXXSourceCompiles)
INCLUDE(FindPackageHandleStandardArgs) INCLUDE(FindPackageHandleStandardArgs)
if (CMAKE_CXX_COMPILER_ID MATCHES "^[cC]lang$") if (CMAKE_CXX_COMPILER_ID MATCHES "^([cC]lang|AppleClang)$")
set(CXX11_FLAG_CANDIDATES "--std=c++11 -Wno-deprecated-register") set(CXX11_FLAG_CANDIDATES "--std=c++11 -Wno-deprecated-register")
else() else()
if (CYGWIN) if (CYGWIN)