]> git.lyx.org Git - lyx.git/blobdiff - CMakeLists.txt
Handle activateWindow in LFUN_BUFFER_SWITCH like in saveBufferIfNeeded() and doShowDi...
[lyx.git] / CMakeLists.txt
index 3f491581b821fb0f6e4655008794e4a0527b7238..33daf5b699a493a2184a2fe5c812ba17b1a2dd38 100644 (file)
@@ -10,8 +10,9 @@ set(LYX_PROJECT LyX)
 
 enable_testing()
 
-get_filename_component(lyx_dir_readme ${CMAKE_SOURCE_DIR}/README ABSOLUTE)
+get_filename_component(lyx_dir_readme ${CMAKE_SOURCE_DIR}/README REALPATH) # Resolve symlinks
 get_filename_component(TOP_SRC_DIR ${lyx_dir_readme} PATH)
+message(STATUS "TOP_SRC_DIR = ${TOP_SRC_DIR}")
 
 set(LYX_CMAKE_DIR "development/cmake")
 set(TOP_CMAKE_PATH "${TOP_SRC_DIR}/${LYX_CMAKE_DIR}")
@@ -40,6 +41,9 @@ if(COMMAND cmake_policy)
        cmake_policy(SET CMP0005 OLD)
        # Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION
        cmake_policy(SET CMP0006 NEW)
+       if(POLICY CMP0020)
+               cmake_policy(SET CMP0020 OLD)
+       endif()
        if(POLICY CMP0028)
                cmake_policy(SET CMP0028 OLD)
        endif()
@@ -68,8 +72,15 @@ if(LYX_XMINGW)
 endif()
 
 if(NOT help AND NOT HELP)
-       # 'project' triggers the searching for a compiler
-       project(${LYX_PROJECT})
+  # 'project' triggers the searching for a compiler
+  project(${LYX_PROJECT})
+  if (CMAKE_COMPILER_IS_GNUCXX)
+    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.0")
+      message(STATUS "Gnu CXX compiler version = ${CMAKE_CXX_COMPILER_VERSION}")
+      message(STATUS "is too old, should be >= 4.0")
+      message(FATAL_ERROR "Exiting")
+    endif()
+  endif()
 endif()
 
 if(UNIX)
@@ -127,6 +138,9 @@ LYX_OPTION(BUNDLE           "Build bundle  (experimental) " OFF ALL)
 LYX_OPTION(ENABLE_URLTESTS  "Enable for URL tests" OFF ALL)
 LYX_OPTION(ENABLE_EXPORT_TESTS "Enable for export tests" OFF ALL)
 LYX_OPTION(ASAN             "Use address sanitizer" OFF ALL)
+LYX_COMBO(USE_QT            "Use Qt version as frontend" QT4 QT5)
+LYX_OPTION(3RDPARTY_BUILD   "Build 3rdparty libs" OFF ALL)
+LYX_COMBO(ENABLE_CXX11          "Build with options for c++11-mode" AUTO ON OFF)
 
 # GCC specific
 LYX_OPTION(PROFILE              "Build profile version" OFF GCC)
@@ -135,9 +149,7 @@ LYX_OPTION(PROGRAM_SUFFIX       "Append version suffix to binaries" ON GCC)
 LYX_OPTION(DEBUG_GLIBC          "Enable libstdc++ debug mode" OFF GCC)
 LYX_OPTION(DEBUG_GLIBC_PEDANTIC "Enable libstdc++ pedantic debug mode" OFF GCC)
 LYX_OPTION(STDLIB_DEBUG         "Use debug stdlib" OFF GCC)
-LYX_OPTION(CONCEPT_CHECKS       "Enable concept-checks" OFF GCC)
 LYX_OPTION(PROFILE              "Build with options for gprof" OFF GCC)
-LYX_OPTION(ENABLE_CXX11         "Build with options for c++11-mode" OFF GCC)
 
 # MSVC specific
 LYX_OPTION(CONSOLE               "Show console on Windows, enforce with =FORCE" ON MSVC)
@@ -149,11 +161,6 @@ LYX_OPTION(DEPENDENCIES_DOWNLOAD "Download dependencies for MSVC 10" OFF MSVC)
 # APPLE specific
 LYX_OPTION(DMG                   "Build as Mac bundle, needed for .dmg  (experimental) " OFF MAC)
 LYX_OPTION(COCOA                 "Use Cocoa on Mac" OFF MAC)
-if(LYX_XMINGW)
-  LYX_COMBO(USE_QT               "Use Qt version as frontend for MINGW" QT4)
-else()
-  LYX_COMBO(USE_QT               "Use Qt version as frontend" QT4 QT5)
-endif()
 
 
 if(help OR HELP)
@@ -203,10 +210,18 @@ endif()
 
 if(LYX_DEPENDENCIES_DOWNLOAD)
        message(STATUS)
-       set(LYX_DEPENDENCIES_DIR ${TOP_BINARY_DIR}/msvc2010-deps)
-       message(STATUS "Using downloaded dependencies in ${LYX_DEPENDENCIES_DIR}")
-       set(deps_files lyx20-deps-msvc2010-x86.zip)
-       set(deps_server http://downloads.sourceforge.net/project/lyx/Win_installers/Dependencies)
+    if(MSVC12)
+        set(LYX_DEPENDENCIES_DIR ${TOP_BINARY_DIR}/msvc2013-deps)
+        set(deps_files lyx-windows-deps-msvc2013.zip)
+        set(deps_server http://ftp.lyx.de/LyX-Windows-Deps)
+        set(GNUWIN32_DIR ${LYX_DEPENDENCIES_DIR}/lyx-windows-deps-msvc2013)
+    else()
+        set(LYX_DEPENDENCIES_DIR ${TOP_BINARY_DIR}/msvc2010-deps)
+           set(deps_files lyx20-deps-msvc2010-x86.zip)
+           set(deps_server http://downloads.sourceforge.net/project/lyx/Win_installers/Dependencies)
+        set(GNUWIN32_DIR ${LYX_DEPENDENCIES_DIR}/deps20)
+    endif()
+    message(STATUS "Using downloaded dependencies in ${LYX_DEPENDENCIES_DIR}")
        foreach(it ${deps_files})
                set(already_downloaded already_downloaded-NOTFOUND CACHE PATH "downloaded" FORCE)
                find_file(already_downloaded ${it} "${LYX_DEPENDENCIES_DIR}/download")
@@ -223,11 +238,6 @@ if(LYX_DEPENDENCIES_DOWNLOAD)
                                      WORKING_DIRECTORY ${LYX_DEPENDENCIES_DIR})
                endif()
        endforeach()
-       set(GNUWIN32_DIR ${LYX_DEPENDENCIES_DIR}/deps20)
-    if(MSVC12)
-        # handle error in msvc12 when linking against msvc10 libs
-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /vd2")
-    endif()
 endif()
 
 
@@ -242,14 +252,41 @@ else()
 endif()
 
 
+if(LYX_ENABLE_CXX11 MATCHES "AUTO")
+  # Set to some meaningful default
+  find_package(CXX11Compiler)
+  if(NOT CXX11COMPILER_FOUND)
+    set(LYX_ENABLE_CXX11 OFF CACHE TYPE STRING FORCE)
+  else()
+    if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
+      execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
+      if(NOT GCC_VERSION VERSION_LESS 4.3)
+        set(LYX_ENABLE_CXX11 ON CACHE TYPE STRING FORCE)
+      else()
+        set(LYX_ENABLE_CXX11 OFF CACHE TYPE STRING FORCE)
+      endif()
+    else()
+      # Not a gnu compiler
+      if(CMAKE_CXX_COMPILER_ID MATCHES "^[cC]lang$")
+        set(LYX_ENABLE_CXX11 ON CACHE TYPE STRING FORCE)
+      else()
+        set(LYX_ENABLE_CXX11 OFF CACHE TYPE STRING FORCE)
+      endif()
+    endif()
+  endif()
+endif()
 set(LYX_GCC11_MODE)
 if(UNIX OR MINGW)
-       execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
+       execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
        message(STATUS "Using GCC version ${GCC_VERSION}")
        if(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()
+               if (LYX_ENABLE_CXX11)
+                       set(LYX_USE_STD_REGEX 1)
+               endif()
        endif()
        if (LYX_ENABLE_CXX11)
                find_package(CXX11Compiler)
@@ -274,6 +311,10 @@ include(LyXPaths)
 file(STRINGS "${TOP_SRC_DIR}/configure.ac" _config_lines)
 
 if(WIN32)
+       set(CMAKE_PREFIX_PATH Specify-path-to-Qt CACHE PATH "Used Qt version")
+       if(MSVC)
+               set(LYX_3RDPARTY_BUILD ON CACHE BOOL "Build 3rdparty libraries" FORCE)
+       endif()
        set(USE_WINDOWS_PACKAGING ON)
 elseif(APPLE)
        set(USE_MACOSX_PACKAGING ON)
@@ -426,9 +467,9 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
                        set(CMAKE_INSTALL_PREFIX "/usr/local/${LYX_PROJECT}" CACHE PATH "LyX default install prefix" FORCE)
                endif()
        endif()
-       if(WIN32)
-               set(CMAKE_INSTALL_PREFIX LYX_INSTALLED CACHE PATH "LyX default install prefix" FORCE)
-       endif()
+endif()
+if(WIN32)
+       set(CMAKE_INSTALL_PREFIX LYX_INSTALLED CACHE PATH "LyX default install prefix" FORCE)
 endif()
 if(IS_ABSOLUTE)
        set(CMAKE_INSTALL_PREFIX_ABSOLUTE ${CMAKE_INSTALL_PREFIX})
@@ -454,7 +495,11 @@ set(LYX_ABS_TOP_SRCDIR "${TOP_SRC_DIR}")
 if(LYX_BUNDLE AND APPLE)
        set(LYX_MAN_DIR "${LYX_DATA_SUBDIR}" CACHE STRING "Install location for man pages.")
 else()
-       set(LYX_MAN_DIR "/usr/local/man/man1" CACHE STRING "Install location for man pages.")
+       if(WIN32)
+               set(LYX_MAN_DIR "${CMAKE_BINARY_DIR}/usr/local/man/man1" CACHE STRING "Install location for man pages.")
+       else()
+               set(LYX_MAN_DIR "/usr/local/man/man1" CACHE STRING "Install location for man pages.")
+       endif()
 endif()
 mark_as_advanced(LYX_MAN_DIR)
 
@@ -522,9 +567,6 @@ if(NOT MSVC)
        if(LYX_STDLIB_DEBUG)
                set(LYX_CXX_FLAGS "${LYX_CXX_FLAGS} -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC")
        endif()
-       if(LYX_CONCEPT_CHECKS)
-               set(LYX_CXX_FLAGS "${LYX_CXX_FLAGS} -D_GLIBCPP_CONCEPT_CHECKS")
-       endif()
        set(CMAKE_CXX_FLAGS       "${LYX_CXX_FLAGS} -fno-strict-aliasing " CACHE TYPE STRING FORCE)
        set(CMAKE_CXX_FLAGS_DEBUG "${LYX_CXX_FLAGS} -fno-strict-aliasing -O0 -g3 -D_DEBUG" CACHE TYPE STRING FORCE)
        if(MINGW)
@@ -543,10 +585,12 @@ if(LYX_CXX_FLAGS_EXTRA)
 endif()
 
 if(LYX_XMINGW)
-    set(QT_MINGW_DIR ${LYX_QT4} CACHE PATH "Qt for Mingw" FORCE)
-    list(APPEND CMAKE_FIND_ROOT_PATH ${QT_MINGW_DIR} ${GNUWIN32_DIR})
+       list(APPEND CMAKE_FIND_ROOT_PATH ${GNUWIN32_DIR})
 endif()
+
+set(QPA_XCB)
 if(LYX_USE_QT MATCHES "QT5")
+       # set QPA_XCB if QT uses X11
        find_package(Qt5Core REQUIRED)
        if (Qt5Core_FOUND)
                find_package(Qt5Widgets REQUIRED)
@@ -554,6 +598,9 @@ if(LYX_USE_QT MATCHES "QT5")
                        find_package(Qt5MacExtras REQUIRED)
                endif()
                find_package(Qt5X11Extras QUIET)
+               if(Qt5X11Extras_FOUND)
+                 set(QPA_XCB 1)
+               endif()
                find_package(Qt5WinExtras QUIET)
                set(QTVERSION ${Qt5Core_VERSION})
                macro (qt_use_modules)
@@ -566,8 +613,15 @@ if(LYX_USE_QT MATCHES "QT5")
                        qt5_wrap_ui(${ARGN})
                endmacro()
                message(STATUS "Found Qt-Version ${QTVERSION}")
+               if(WIN32)
+                       set(LYX_QTMAIN_LIBRARY ${Qt5Core_QTMAIN_LIBRARIES})
+               endif()
        endif()
 elseif(LYX_USE_QT MATCHES "QT4")
+       if(LYX_XMINGW)
+               set(QT_MINGW_DIR ${LYX_QT4} CACHE PATH "Qt for Mingw" FORCE)
+               list(APPEND CMAKE_FIND_ROOT_PATH ${QT_MINGW_DIR} ${GNUWIN32_DIR})
+       endif()
        find_package(Qt4 "4.5.0" REQUIRED)
        macro (qt_use_modules)
        endmacro()
@@ -577,6 +631,9 @@ elseif(LYX_USE_QT MATCHES "QT4")
        macro (qt_wrap_uifiles)
                qt4_wrap_ui(${ARGN})
        endmacro()
+       if(WIN32)
+               set(LYX_QTMAIN_LIBRARY ${QT_QTMAIN_LIBRARIES})
+       endif()
 else()
   message(FATAL_ERROR "Unhandled value for LYX_USE_QT (${LYX_USE_QT})")
 endif()
@@ -591,9 +648,20 @@ include_directories(${TOP_BINARY_DIR} ${TOP_SRC_DIR}/src)
 set(Spelling_FOUND OFF)
 set(Include_used_spellchecker)   # String will be inserted into config.h
 
+if(LYX_3RDPARTY_BUILD)
+    add_subdirectory(3rdparty/hunspell)
+    add_definitions(-DHUNSPELL_STATIC)
+    set(HUNSPELL_FOUND ON)
+    message(STATUS "  * Hunspell:")
+    message(STATUS "     - include: ${HUNSPELL_INCLUDE_DIR}")
+    message(STATUS "     - library: ${HUNSPELL_LIBRARY}")
+endif()
+
 foreach(_spell "ASPELL" "Enchant" "Hunspell")
   string(TOUPPER ${_spell} _upspell)
-  find_package(${_spell})
+  if (NOT ${_upspell}_FOUND)
+    find_package(${_spell})
+  endif()
   if (${_upspell}_FOUND)
     include_directories(${${_upspell}_INCLUDE_DIR})
     set(Spelling_FOUND ON)
@@ -608,8 +676,28 @@ foreach(_spell "ASPELL" "Enchant" "Hunspell")
   endif()
 endforeach()
 
+if(GNUWIN32_DIR)
+       list(APPEND CMAKE_PROGRAM_PATH "${GNUWIN32_DIR}/Python" )
+endif()
+
+find_package(PythonInterp 2.7 QUIET)
+if(PYTHONINTERP_FOUND)
+       if(PYTHON_VERSION_STRING VERSION_GREATER 2.8)
+       unset(PYTHONINTERP_FOUND)
+       endif()
+endif()
+
+if(NOT PYTHONINTERP_FOUND)
+  unset(PYTHON_EXECUTABLE CACHE)
+  unset(PYTHON_VERSION_MAJOR)
+  unset(PYTHON_VERSION_MINOR)
+  unset(PYTHON_VERSION_STRING)
+  find_package(PythonInterp 3.3 REQUIRED)
+endif()
+
+set(LYX_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE FILEPATH "Python to be used by LyX")
+
 if(LYX_NLS)
-       FIND_PROGRAM(LYX_PYTHON_EXECUTABLE python2 python HINTS ${GNUWIN32_DIR}/python)
        find_package(LyXGettext)
        if(LYX_PYTHON_EXECUTABLE AND GETTEXT_FOUND)
                add_subdirectory(po "${TOP_BINARY_DIR}/po")
@@ -624,9 +712,16 @@ if(LYX_NLS)
        endif()
 endif()
 
-
-find_package(ICONV REQUIRED)
-find_package(ZLIB REQUIRED)
+if(UNIX)
+    find_package(ICONV REQUIRED)
+    find_package(ZLIB REQUIRED)
+else()
+    if(LYX_3RDPARTY_BUILD)
+       add_subdirectory(3rdparty/libiconv)
+       set(HAVE_ICONV_CONST 1)
+       add_subdirectory(3rdparty/zlib)
+    endif()
+endif()
 
 if(LYX_EXTERNAL_BOOST)
        message(STATUS "Searching for boost")
@@ -639,6 +734,13 @@ if(LYX_EXTERNAL_BOOST)
                message(STATUS "Boost found")
                message(STATUS "Boost-libs = ${Boost_LIBRARIES}")
                set(Lyx_Boost_Libraries ${Boost_LIBRARIES})
+               if (LYX_STDLIB_DEBUG)
+                       # 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(WARNING "Compiling LyX with stdlib-debug and system boost libraries may lead to crashes. Consider using '-DLYX_STDLIB_DEBUG=OFF' or using '-DLYX_EXTERNAL_BOOST=OFF'")
+               endif()
        else()
                message(FATAL_ERROR "Boost not found" ${Boost_ERROR_REASON})
        endif()
@@ -650,17 +752,18 @@ else()
        endif()
        add_definitions(-DBOOST_USER_CONFIG="<config.h>")
        add_definitions(-DBOOST_SIGNALS_NO_DEPRECATION_WARNING=1)
-       include_directories(${TOP_SRC_DIR}/boost)
-       add_subdirectory(boost "${TOP_BINARY_DIR}/boost")
+       include_directories(${TOP_SRC_DIR}/3rdparty/boost)
+       add_subdirectory(3rdparty/boost "${TOP_BINARY_DIR}/3rdparty/boost")
 endif()
 
 
 
 
 if(WIN32)
-       if(NOT LYX_CONSOLE)
+       if(LYX_CONSOLE)
+               set(LYX_QTMAIN_LIBRARY)
+       else()
                set(WIN32_CONSOLE WIN32)
-               set(LYX_QTMAIN_LIBRARY ${QT_QTMAIN_LIBRARY})
        endif()
        if(MSVC)
                add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DNOMINMAX)
@@ -827,6 +930,10 @@ 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)
@@ -881,10 +988,10 @@ if(LYX_NLS)
        message(STATUS "Building Native Language Support (LYX_NLS is set), used libraries:")
        message(STATUS)
        message(STATUS "  * iconv")
-       message(STATUS "     - header : ${ICONV_HEADER}")
+       message(STATUS "     - include: ${ICONV_INCLUDE_DIR}")
        message(STATUS "     - library: ${ICONV_LIBRARY}")
        message(STATUS "  * zlib")
-       message(STATUS "     - header : ${ZLIB_HEADER}")
+       message(STATUS "     - include: ${ZLIB_INCLUDE_DIR}")
        message(STATUS "     - library: ${ZLIB_LIBRARY}")
        message(STATUS)
 endif()