]> git.lyx.org Git - lyx.git/blobdiff - CMakeLists.txt
Fix bug #11500
[lyx.git] / CMakeLists.txt
index bb7ecfe4e16c2a473d7abf7c9b54725183244f1f..65d3a6e06ef9a998b2a129232a8dfd71851e2f73 100644 (file)
@@ -2,17 +2,11 @@
 # Licence details can be found in the file COPYING.
 #
 # Copyright (c) 2006-2011 Peter Kümmel, <syntheticpp@gmx.net>
-# Copyright (c) 2008-2011 Kornel Benko, <Kornel.Benko@berlin.de>
+# Copyright (c) 2008-2020 Kornel Benko, <Kornel.Benko@berlin.de>
 
 cmake_minimum_required(VERSION 3.1.0)
 
-set(CMAKE_CXX_STANDARD 20)
-set(GNUWIN32_DIR D:/LyX/lyx-unstable/lyx-windows-deps-msvc2017)
-set(LYX_USE_QT "QT5")
-set(LYX_REQUIRE_SPELLCHECK true)
-
 set(LYX_PROJECT LyX)
-
 # Instruct cmake to not use gnu extensions,
 # this prevents the mix of '-std=c++*' and '-std=gnu++*' flags
 set(CMAKE_CXX_EXTENSIONS OFF)
@@ -56,6 +50,9 @@ if(COMMAND cmake_policy)
        if(POLICY CMP0075)
                cmake_policy(SET CMP0075 NEW)
        endif()
+       if(POLICY CMP0077)
+               cmake_policy(SET CMP0077 NEW)
+       endif()
 endif()
 
 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
@@ -80,9 +77,9 @@ if(NOT help AND NOT HELP)
   # 'project' triggers the searching for a compiler
   project(${LYX_PROJECT})
   if (CMAKE_COMPILER_IS_GNUCXX)
-    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.0")
+    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9")
       message(STATUS "Gnu CXX compiler version = ${CMAKE_CXX_COMPILER_VERSION}")
-      message(STATUS "is too old, should be >= 4.0")
+      message(STATUS "is too old, should be >= 4.9")
       message(FATAL_ERROR "Exiting")
     endif()
   endif()
@@ -107,9 +104,6 @@ endif()
 include(LyXMacros)
 include(LyXDestinations)
 
-# Try to get some informations from configure.ac
-include(LyXPaths)
-
 # Value of USE_POSIX_PACKAGING is needed in determineversionandbuildtype()
 if(WIN32)
        set(CMAKE_PREFIX_PATH Specify-path-to-Qt CACHE PATH "Used Qt version")
@@ -253,6 +247,9 @@ LYX_OPTION(DEPENDENCIES_DOWNLOAD "Download dependencies for MSVC 10" OFF MSVC)
 LYX_OPTION(DMG                   "Build as Mac bundle, needed for .dmg  (experimental) " OFF MAC)
 LYX_OPTION(COCOA                 "Use Cocoa on Mac" OFF MAC)
 
+# Try to get some informations from configure.ac
+include(LyXPaths)
+
 
 if(help OR HELP)
        message(STATUS)
@@ -260,6 +257,8 @@ if(help OR HELP)
        message(STATUS)
        LYX_OPTION_LIST_ALL(help)
        message(STATUS)
+       unset(help CACHE)
+       unset(HELP CACHE)
        RETURN()
 endif()
 
@@ -381,13 +380,7 @@ unset(LYX_GCC11_MODE)
 if(UNIX OR MINGW)
        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")
-         if(CXX11_STD_REGEX)
-           set(LYX_USE_STD_REGEX 1)
-         else()
-           set(LYX_USE_STD_REGEX 0)
-         endif()
        else()
          execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpfullversion OUTPUT_VARIABLE GCC_VERSION ERROR_VARIABLE _error RESULT_VARIABLE _err OUTPUT_STRIP_TRAILING_WHITESPACE)
          #message(STATUS "dumpfullversion: error = ${_error}, result = ${_err}")
@@ -397,14 +390,8 @@ if(UNIX OR MINGW)
            #message(STATUS "dumpversion: error = ${_error}, result = ${_err}")
          endif()
          message(STATUS "Using GCC version ${GCC_VERSION}")
-         if(GCC_VERSION VERSION_LESS 4.6)
-               message(FATAL_ERROR "gcc >= 4.6 is required.")
-         elseif(GCC_VERSION VERSION_LESS 4.9)
-               # <regex> in gcc is unusable in versions less than 4.9.0
-               # see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631
-               set(LYX_USE_STD_REGEX 0)
-         else()
-               set(LYX_USE_STD_REGEX 1)
+         if(GCC_VERSION VERSION_LESS 4.9)
+               message(FATAL_ERROR "gcc >= 4.9 is required.")
          endif()
        endif()
        set(LYX_GCC11_MODE "${CXX11_FLAG}")
@@ -412,9 +399,6 @@ else()
        if(MSVC_VERSION LESS 1900)
                # Drop support for msvc versions prior to 1900 (Visual Studio 2015)
                message(FATAL_ERROR "Visual Studio >= 2015 is required.")
-               set(LYX_USE_STD_REGEX 0)
-       else()
-               set(LYX_USE_STD_REGEX 1)
        endif()
 endif()
 
@@ -692,15 +676,22 @@ else()
        if(NOT LYX_QUIET)
                set(CMAKE_VERBOSE_MAKEFILE ON)
        endif()
-       set(LYX_CXX_FLAGS "-Wall -Wunused-parameter ${LYX_GCC11_MODE}${LYX_CXX_FLAGS}")
-       if(LYX_GCC11_MODE MATCHES "\\+\\+(14|11|98)")
+       if(LYX_GCC11_MODE MATCHES "\\+\\+([0-9][0-9])")
          # Thanks to Brad King <brad.king@kitware.com>
          # for the pointer to https://cmake.org/cmake/help/v3.6/variable/CMAKE_CXX_STANDARD.html
          # This allows us to use QT5.7 with recent g++ (version >= 4.9) compilers
          # and still use our own c++ extension tests
-         set(CMAKE_CXX_STANDARD ${CMAKE_MATCH_1})
-         message(STATUS "CMAKE_CXX_STANDARD set to ${CMAKE_CXX_STANDARD}")
+         set(std_num ${CMAKE_MATCH_1})
+         set(CMAKE_CXX_STANDARD ${std_num})
+       else()
+         message(STATUS "Setting CMAKE_CXX_STANDARD 11 as fallback")
+         set(CMAKE_CXX_STANDARD 11)
+         set(LYX_GCC11_MODE "--std=c++11")
        endif()
+       # The following setting with LYX_GCC11_MODE is needed because cmake does not honor
+       # CMAKE_CXX_STANDARD while performing tests like
+       # check_cxx_source_compiles("..." HAVE_DEF_MAKE_UNIQUE)
+       set(LYX_CXX_FLAGS "-Wall -Wextra -Wno-deprecated-copy ${LYX_GCC11_MODE}${LYX_CXX_FLAGS}")
        if(LYX_STDLIB_DEBUG)
          set(LYX_CXX_FLAGS "${LYX_CXX_FLAGS} -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC")
         else()
@@ -714,9 +705,9 @@ else()
        set(CMAKE_CXX_FLAGS       "${LYX_CXX_FLAGS} -fno-strict-aliasing " CACHE STRING "Set CXX flags" FORCE)
        set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -D_DEBUG" CACHE STRING "Set debug flags" FORCE)
        if(MINGW)
-               set(CMAKE_CXX_FLAGS_RELEASE "-O2 -march=native -pipe -DNDEBUG" CACHE STRING "Set release flags for Mingw" FORCE)
+               set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "Set release flags for Mingw" FORCE)
        else()
-               set(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -pipe -DNDEBUG" CACHE STRING "Set release flags" FORCE)
+               set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "Set release flags" FORCE)
        endif()
 endif()
 
@@ -876,6 +867,7 @@ endforeach()
 
 if(GNUWIN32_DIR)
        list(APPEND CMAKE_PROGRAM_PATH "${GNUWIN32_DIR}/Python" )
+       list(APPEND CMAKE_PROGRAM_PATH "${GNUWIN32_DIR}/Perl/bin" )
 endif()
 
 # Search for python default version first
@@ -923,6 +915,8 @@ if(LYX_NLS)
 endif()
 
 if(LYX_EXTERNAL_ICONV)
+  # Possible remnants of previous run without external iconv
+  file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/libiconv" "${CMAKE_BINARY_DIR}/3rdparty/libiconv")
   find_package(ICONV REQUIRED)
 else()
   add_subdirectory(3rdparty/libiconv)
@@ -939,40 +933,14 @@ if(NOT LYX_EXTERNAL_DTL)
   add_subdirectory(3rdparty/dtl)
 endif()
 
-if(LYX_USE_STD_REGEX)
-  # Set only include path.
-  # Use internal boost, which is known to exist
-  # we don't need any libraries
-  set(Lyx_Boost_Libraries)
-  add_definitions(-DBOOST_USER_CONFIG=<config.h>)
-  include_directories(${TOP_SRC_DIR}/3rdparty/boost)
-else()
-  # Using boost-regex
-  if(LYX_EXTERNAL_BOOST)
-    message(STATUS "Searching for external boost")
-    find_package(Boost COMPONENTS regex)
-    if(Boost_FOUND)
-      message(STATUS "Boost found")
-      message(STATUS "Boost-libs = ${Boost_LIBRARIES}")
-      set(Lyx_Boost_Libraries ${Boost_LIBRARIES})
-      if (LYX_STDLIB_DEBUG OR LYX_DEBUG_GLIBC OR LYX_DEBUG_GLIBC_PEDANTIC)
-       # Comment from  Jean-Marc Lasgouttes:
-       # In general, system boost libraries are incompatible with
-       # the use of stdlib-debug in libstdc++. See ticket #9736 for
-       # details.
-       message(FATAL_ERROR "Compiling LyX with stdlib-debug and system boost libraries may lead to crashes. Consider using '-DLYX_STDLIB_DEBUG=OFF -DLYX_DEBUG_GLIBC=OFF -DLYX_DEBUG_GLIBC_PEDANTIC=OFF' or using '-DLYX_EXTERNAL_BOOST=OFF'")
-      endif()
-    else()
-      message(FATAL_ERROR "Boost not found" ${Boost_ERROR_REASON})
-    endif()
-  else()
-    # Using included boost
-    set(Lyx_Boost_Libraries boost_regex)
-    add_definitions(-DBOOST_USER_CONFIG=<config.h>)
-    include_directories(${TOP_SRC_DIR}/3rdparty/boost)
-    add_subdirectory(3rdparty/boost "${TOP_BINARY_DIR}/3rdparty/boost")
-  endif()
-endif()
+# Set only include path.
+# Use internal boost, which is known to exist
+# we don't need any libraries
+set(Lyx_Boost_Libraries)
+add_definitions(-DBOOST_USER_CONFIG=<config.h>)
+include_directories(${TOP_SRC_DIR}/3rdparty/boost)
+
+include_directories(${TOP_SRC_DIR}/3rdparty/nod)
 
 if(WIN32)
        if(LYX_CONSOLE)
@@ -989,7 +957,7 @@ if(WIN32)
                # -DPSAPI_VERSION=1 is not needed for mingw, since the mingw psapi.h
                # does not use it and always declares the vista compatible API.
                # If this ever changes then -DPSAPI_VERSION might be needed here as well.
-               add_definitions(-DWINVER=0x0600)
+               add_definitions(-DWINVER=0x0500)
        endif()
 endif()
 
@@ -1101,6 +1069,13 @@ if(MSVC)
                set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /Zc:wchar_t-")
        endif()
 
+       if (MSVC_VERSION GREATER_EQUAL 1914)
+               # Ensure the __cplusplus macro is set to a sensible value.
+               set(CMAKE_CXX_FLAGS_DEBUG      "${CMAKE_CXX_FLAGS_DEBUG} /Zc:__cplusplus")
+               set(CMAKE_CXX_FLAGS_RELEASE    "${CMAKE_CXX_FLAGS_RELEASE} /Zc:__cplusplus")
+               set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /Zc:__cplusplus")
+       endif()
+
        message(STATUS "----- Warning level      : ${CMAKE_CXX_WARNING_LEVEL}  ${WARNING_LEVEL_MESSAGE}")
        message(STATUS "----- Warnings as errors : ${MSVC_W_ERROR}")
        message(STATUS "----- Warnings disabled  : ${MSVC_W_DISABLE}")
@@ -1173,10 +1148,6 @@ if(QTVERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*")
        MATH(EXPR QT4_VERSION "(${CMAKE_MATCH_1}<<16)|(${CMAKE_MATCH_2}<<8)|${CMAKE_MATCH_3}")
 endif()
 
-if (NOT HAVE_REGEX)
-       set(LYX_USE_STD_REGEX 0)
-endif()
-
 
 set (cmd ${CMAKE_CTEST_COMMAND})
 if (MSVC)
@@ -1201,6 +1172,10 @@ include(../Install)
 
 # By running the URL tests first, time can be saved when running the ctests in
 # parallel since the URL tests take a long time to run (e.g. 10 minutes).
+
+# Needed, because of perl scripts in checkurls autotests and batchtests
+find_package(Perl REQUIRED)
+
 if(LYX_ENABLE_URLTESTS)
        add_subdirectory(development/checkurls "${TOP_BINARY_DIR}/checkurls")
 endif()
@@ -1266,4 +1241,10 @@ endif()
 # can be run last
 add_subdirectory(development/cmake/post_install)
 
+string(TIMESTAMP current_date "%Y-%m-%d %H:%M")
+execute_process(COMMAND ${LYX_GITVERSION} describe --tags
+       WORKING_DIRECTORY "${TOP_SRC_DIR}"
+       OUTPUT_VARIABLE current_version
+       OUTPUT_STRIP_TRAILING_WHITESPACE)
+file(APPEND "${TOP_BINARY_DIR}/Testing/IgnoredCount" "${current_date} ${current_version} Ignored tests = ${LYX_ignored_count}\n")
 message(STATUS)