From 889d10cda3cba0ba599e918f72b272f69aa08ff7 Mon Sep 17 00:00:00 2001 From: Kornel Benko Date: Thu, 14 Jun 2018 13:55:52 +0200 Subject: [PATCH] Cmake build: Adapt to compile with qt5.11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 d6b21e20e254c96d963c6ab4988ad635f8f4e44b) (cherry picked from commit 72a2f922393f8029b658fffe3c5a2e3e2c81ac1d) (cherry picked from commit 6343452a7397a5ac4b84af30d61c4d7fca5afbc1) (cherry picked from commit cb08d4a879bf63222a4462308b614d3209607737) (cherry picked from commit 1bf4d7b0fc2bc4c700e7cecc1e6e3c7faf4f03a5) --- CMakeLists.txt | 29 ++++++++++++------- INSTALL.cmake | 2 +- .../cmake/modules/FindCXX11Compiler.cmake | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c3c05d4104..ed0f4a4798 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ # Copyright (c) 2006-2011 Peter Kümmel, # Copyright (c) 2008-2011 Kornel Benko, -cmake_minimum_required(VERSION 2.6.4) +cmake_minimum_required(VERSION 3.1.0) set(LYX_PROJECT LyX) @@ -47,6 +47,10 @@ if(COMMAND cmake_policy) # COMPILE_DEFINITIONS are not used yet. Enable new behavior. cmake_policy(SET CMP0043 NEW) endif() + cmake_policy(SET CMP0020 NEW) + if(POLICY CMP0075) + cmake_policy(SET CMP0075 OLD) + endif() endif() set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) @@ -260,7 +264,7 @@ if(NOT CXX11COMPILER_FOUND) endif() set(LYX_GCC11_MODE) 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 # and use the resulting CXX11_STD_REGEX found in FindCXX11Compiler.cmake message(STATUS "Using clang") @@ -625,7 +629,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}") @@ -641,14 +645,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}\"") @@ -660,8 +664,11 @@ if(LYX_USE_QT MATCHES "QT5") # Subject: cmake compilation error #message(FATAL_ERROR "Wrong Qt-Version") endif() - macro (qt_use_modules) - qt5_use_modules(${ARGN}) + macro (qt_use_modules lyxtarget) + foreach (_tg ${ARGN}) + find_package(Qt5${_tg} CONFIG REQUIRED) + target_link_libraries(${lyxtarget} Qt5::${_tg}) + endforeach() endmacro() macro (qt_add_resources) qt5_add_resources(${ARGN}) @@ -698,7 +705,7 @@ endif() find_package(Magic) if(Magic_FOUND) - set(HAVE_MAGIC_H 1) + set(HAVE_MAGIC_H 1) endif() include_directories(${TOP_BINARY_DIR} ${TOP_SRC_DIR}/src) diff --git a/INSTALL.cmake b/INSTALL.cmake index 4c8d4789f3..540b68e698 100644 --- a/INSTALL.cmake +++ b/INSTALL.cmake @@ -2,7 +2,7 @@ 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). diff --git a/development/cmake/modules/FindCXX11Compiler.cmake b/development/cmake/modules/FindCXX11Compiler.cmake index 5c7b69866e..739d267bf0 100644 --- a/development/cmake/modules/FindCXX11Compiler.cmake +++ b/development/cmake/modules/FindCXX11Compiler.cmake @@ -34,7 +34,7 @@ INCLUDE(CheckCXXSourceCompiles) 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") else() if (CYGWIN)