# 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(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)
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)
include(LyXMacros)
include(LyXDestinations)
+# Value of USE_POSIX_PACKAGING is needed in determineversionandbuildtype()
+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)
+else()
+ set(USE_POSIX_PACKAGING ON)
+endif()
+
+determineversionandbuildtype("${TOP_SRC_DIR}/configure.ac" _package_list _version_list _envlist LYX_DATE LYX_BUILD_TYPE)
+list(GET _package_list 0 PACKAGE_BASE)
+list(GET _package_list 1 PACKAGE_VERSION)
+list(GET _package_list 2 PACKAGE_BUGREPORT)
+list(GET _envlist 0 LYX_DIR_VER)
+list(GET _envlist 1 LYX_USERDIR_VER)
+list(GET _version_list 0 LYX_VERSION)
+list(GET _version_list 1 LYX_MAJOR_VERSION)
+list(GET _version_list 2 LYX_MINOR_VERSION)
+list(GET _version_list 3 LYX_RELEASE_LEVEL)
+list(GET _version_list 4 LYX_RELEASE_PATCH)
+
# Usage LYX_OPTION
# 1. parameter: option name without prefix 'LYX_'
# 2. parameter: description
# 4-n parameter: possible other string values
LYX_OPTION_INIT()
+LYX_COMBO(ENABLE_BUILD_TYPE "Allows to tweak the compiled code" AUTO release prerelease development gprof)
+
+if(LYX_ENABLE_BUILD_TYPE MATCHES "AUTO")
+ message(STATUS "Selecting build type defaults from configure.ac")
+else()
+ set(LYX_BUILD_TYPE "${LYX_ENABLE_BUILD_TYPE}")
+ message(STATUS "Selecting build type defaults from LYX_ENABLE_BUILD_TYPE")
+endif()
+
+# Select some defaults depending on LYX_BUILD_TYPE
+# they can always be overwritten by the respective command line settings
+# These settings are only effective on fresh(==empty) CMakeCache.txt
+if(LYX_BUILD_TYPE STREQUAL "development")
+ set(DefaultLyxDebug ON)
+ set(DefaultLyxRelease OFF)
+ set(DefaultLyxStdlibDebug ON)
+ set(DefaultLyxEnableAssertions ON)
+ set(DefaultLyxProfile OFF)
+ set(DefaultExternalLibs OFF)
+elseif(LYX_BUILD_TYPE STREQUAL "prerelease")
+ set(DefaultLyxDebug OFF)
+ set(DefaultLyxRelease OFF)
+ set(DefaultLyxStdlibDebug OFF)
+ set(DefaultLyxEnableAssertions OFF)
+ set(DefaultLyxProfile OFF)
+ set(DefaultExternalLibs ON)
+elseif(LYX_BUILD_TYPE STREQUAL "release")
+ set(DefaultLyxDebug OFF)
+ set(DefaultLyxRelease ON)
+ set(DefaultLyxStdlibDebug OFF)
+ set(DefaultLyxEnableAssertions OFF)
+ set(DefaultLyxProfile OFF)
+ set(DefaultExternalLibs ON)
+elseif(LYX_BUILD_TYPE STREQUAL "gprof")
+ set(DefaultLyxDebug ON)
+ set(DefaultLyxRelease OFF)
+ set(DefaultLyxStdlibDebug OFF)
+ set(DefaultLyxEnableAssertions OFF)
+ set(DefaultLyxProfile ON)
+ set(DefaultExternalLibs OFF)
+else()
+ message(FATAL_ERROR "Invalid build type (${LYX_BUILD_TYPE}) encountered")
+endif()
# Options for all compilers/systems
LYX_OPTION(CPACK "Use the CPack management (Implies LYX_INSTALL option)" OFF ALL)
LYX_OPTION(ASPELL "Require aspell" OFF ALL)
LYX_OPTION(ENCHANT "Require Enchant" OFF ALL)
LYX_OPTION(HUNSPELL "Require Hunspell" OFF ALL)
-LYX_OPTION(RELEASE "Build release version, build debug when disabled" OFF ALL)
-LYX_OPTION(DEBUG "Enforce debug build" OFF ALL)
+LYX_OPTION(RELEASE "Build release version, build debug when disabled" ${DefaultLyxRelease} ALL)
+LYX_OPTION(DEBUG "Enforce debug build" ${DefaultLyxDebug} ALL)
LYX_OPTION(NO_OPTIMIZE "Don't use any optimization/debug flags" OFF ALL)
+LYX_OPTION(ENABLE_ASSERTIONS "Run sanity checks in the program" ${DefaultLyxEnableAssertions} ALL)
LYX_OPTION(PACKAGE_SUFFIX "Use version suffix for packaging" ON ALL)
LYX_STRING(SUFFIX_VALUE "Use this string as suffix" "")
LYX_OPTION(PCH "Use precompiled headers" OFF ALL)
LYX_COMBO(USE_IPO "Interprocedural optimization" OFF AUTO ON)
#LYX_OPTION(3RDPARTY_BUILD "Build 3rdparty libs" OFF ALL)
LYX_OPTION(DISABLE_CALLSTACK_PRINTING "do not print a callstack when crashing" OFF ALL)
-LYX_OPTION(EXTERNAL_Z "OFF := Build 3rdparty lib zlib" ON ALL)
-LYX_OPTION(EXTERNAL_DTL "OFF := Build 3rdparty commands dt2dv and dv2dt" ON ALL)
-LYX_OPTION(EXTERNAL_ICONV "OFF := Build 3rdparty lib iconvlib" ON ALL)
-LYX_OPTION(EXTERNAL_HUNSPELL "OFF := Build 3rdparty lib hunspelllib" ON ALL)
+LYX_OPTION(EXTERNAL_Z "OFF := Build 3rdparty lib zlib" ${DefaultExternalLibs} ALL)
+LYX_OPTION(EXTERNAL_DTL "OFF := Build 3rdparty commands dt2dv and dv2dt" ${DefaultExternalLibs} ALL)
+LYX_OPTION(EXTERNAL_ICONV "OFF := Build 3rdparty lib iconvlib" ${DefaultExternalLibs} ALL)
+LYX_OPTION(EXTERNAL_HUNSPELL "OFF := Build 3rdparty lib hunspelllib" ${DefaultExternalLibs} ALL)
LYX_COMBO(EXTERNAL_MYTHES "OFF := Build 3rdparty lib mytheslib" AUTO OFF ON)
# GCC specific
-LYX_OPTION(PROFILE "Build with options for gprof" OFF GCC)
-LYX_OPTION(EXTERNAL_BOOST "Use external boost" OFF GCC)
+LYX_OPTION(PROFILE "Build with options for gprof" ${DefaultLyxProfile} GCC)
+LYX_OPTION(EXTERNAL_BOOST "Use external boost" ${DefaultExternalLibs} GCC)
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(STDLIB_DEBUG "Use debug stdlib" ${DefaultLyxStdlibDebug} GCC)
# MSVC specific
LYX_OPTION(CONSOLE "Show console on Windows" ON 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)
message(STATUS)
LYX_OPTION_LIST_ALL(help)
message(STATUS)
+ unset(help CACHE)
+ unset(HELP CACHE)
RETURN()
endif()
+if ("${LYX_SUFFIX_VALUE}" MATCHES "")
+ set(LYX_INSTALL_SUFFIX "${LYX_MAJOR_VERSION}.${LYX_MINOR_VERSION}")
+else()
+ set(LYX_INSTALL_SUFFIX "${LYX_SUFFIX_VALUE}")
+endif()
+
# Check option dependencies
if (LYX_ENABLE_VALGRIND_TESTS)
find_program(VALGRIND_EXECUTABLE "valgrind")
endif()
endif()
-
-# Try to get some informations from configure.ac
-
-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)
-else()
- set(USE_POSIX_PACKAGING ON)
-endif()
-
if(LYX_3RDPARTY_BUILD)
# LYX_3RDPARTY_BUILD is not cached anymore, but for compatibility reasons
# this enables the build of all 3rd_party libs
set(LYX_EXTERNAL_MYTHES OFF CACHE STRING "Build 3rdparty mytheslib" FORCE)
endif()
-macro(setstripped _varname)
- if(${ARGC} GREATER 1)
- string(STRIP "${ARGV1}" _v)
- if (_v MATCHES "^\\[\(.+\)\\]$")
- set(_v ${CMAKE_MATCH_1})
- endif()
- if(USE_POSIX_PACKAGING)
- string(TOLOWER ${_v} ${_varname})
- else()
- set(${_varname} ${_v})
- endif()
- else()
- set(${_varname})
- endif()
-endmacro(setstripped)
-
-foreach(_c_l ${_config_lines} )
- if(_c_l MATCHES "^AC_INIT\\(\([^,]+\),\([^,]+\), *\\[\([^,]+\)\\] *,\(.*\)")
- # Not using CMAKE_MATCH_ directly is needed, because
- # its value is now changed inside macro setstripped
- set(_PB ${CMAKE_MATCH_1})
- set(_PV ${CMAKE_MATCH_2})
- set(_PBU ${CMAKE_MATCH_3})
- setstripped(PACKAGE_BASE ${_PB})
- setstripped(PACKAGE_VERSION ${_PV})
- setstripped(PACKAGE_BUGREPORT ${_PBU})
- if(PACKAGE_VERSION MATCHES "^\([0-9]+\)\\.\([0-9]+\)\(\\.\([0-9]+\)\(\\.\([0-9]+\)\)?\)?.*$")
- set(LYX_MAJOR_VERSION ${CMAKE_MATCH_1})
- set(LYX_MINOR_VERSION ${CMAKE_MATCH_2})
- set(LYX_RELEASE_LEVEL ${CMAKE_MATCH_4})
- set(LYX_RELEASE_PATCH ${CMAKE_MATCH_6})
- set(LYX_DIR_VER "LYX_DIR_${CMAKE_MATCH_1}${CMAKE_MATCH_2}x")
- set(LYX_USERDIR_VER "LYX_USERDIR_${CMAKE_MATCH_1}${CMAKE_MATCH_2}x")
- if (NOT LYX_RELEASE_LEVEL)
- set(LYX_RELEASE_LEVEL 0)
- endif()
- if (NOT LYX_RELEASE_PATCH)
- set(LYX_RELEASE_PATCH 0)
- endif()
- set(LYX_VERSION "${LYX_MAJOR_VERSION}.${LYX_MINOR_VERSION}")
- if ("${LYX_SUFFIX_VALUE}" MATCHES "")
- set(LYX_INSTALL_SUFFIX "${LYX_MAJOR_VERSION}.${LYX_MINOR_VERSION}")
- else()
- set(LYX_INSTALL_SUFFIX "${LYX_SUFFIX_VALUE}")
- endif()
- endif()
- endif()
- if(_c_l MATCHES "^AC_SUBST\\( *LYX_DATE *, *\\[\\\"(.*)\\\"\\].*")
- set(LYX_DATE "${CMAKE_MATCH_1}")
- endif()
-endforeach(_c_l)
-unset(_config_lines)
-
FIND_PROGRAM(LYX_GITVERSION git)
#message(STATUS "gitversion = ${LYX_GITVERSION}")
set(LYX_REVISION_VERSION ${LYX_RELEASE_LEVEL})
set(library_type STATIC)
endif()
+if(LYX_ENABLE_ASSERTIONS)
+ set(LYX_CXX_FLAGS " -DENABLE_ASSERTIONS=1")
+else()
+ set(LYX_CXX_FLAGS "")
+endif()
+
if(MSVC)
if (CXX11_FLAG MATCHES "\\+\\+([0-9]+)")
set(CMAKE_CXX_STANDARD ${CMAKE_MATCH_1})
message(STATUS "CMAKE_CXX_STANDARD set to ${CMAKE_CXX_STANDARD}")
endif()
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}${LYX_CXX_FLAGS}")
else()
if(NOT LYX_QUIET)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()
- set(LYX_CXX_FLAGS "-Wall -Wunused-parameter ${LYX_GCC11_MODE}")
- if(LYX_CXX_FLAGS 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 -Wunused-parameter ${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()
endif()
endif()
+if(LYX_ASAN)
+ set(CMAKE_CXX_FLAGS "-fsanitize=address -fno-omit-frame-pointer -g ${CMAKE_CXX_FLAGS}")
+ message(STATUS)
+ message(STATUS "Address sanitizer enabled. Usage:")
+ message(STATUS " wget https://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py")
+ message(STATUS " chmod +x ./asan_symbolize.py")
+ message(STATUS " ./bin/${_lyx} 2>&1 | ./asan_symbolize.py | c++filt ")
+ message(STATUS)
+endif()
+
set(LYX_CXX_FLAGS_EXTRA "" CACHE STRING "Desired semicolon separated list of extra cxx compile flags, like '-Werror'")
mark_as_advanced(LYX_CXX_FLAGS_EXTRA)
if(LYX_CXX_FLAGS_EXTRA)
if (LYX_EXTERNAL_MYTHES MATCHES "AUTO")
# try system library first
- find_package(MyThesLIB)
+ find_package(MYTHESLIB)
if (MYTHESLIB_FOUND)
set(LYX_EXTERNAL_MYTHES ON CACHE STRING "OFF:= Build 3rdparty mytheslib" FORCE)
else()
endif()
endif()
if (LYX_EXTERNAL_MYTHES MATCHES "ON")
- find_package(MyThesLIB REQUIRED)
+ find_package(MYTHESLIB REQUIRED)
else()
add_subdirectory(3rdparty/mythes)
endif()
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
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)
# add here warnings which should be disabled /wdXXXX
set(MSVC_W_DISABLE "/wd4288 /wd4355 /wd4800 /wd4996 /wd4311 /wd4312 /wd4505 /wd4267 /wd4512 /wd4245 /wd4127 /wd4180 /wd4231")
- set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Wp64 ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
- set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Wp64 ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
- set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /Wp64 ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
+ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /W4 ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
+ set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /W4 ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
else()
set(CMAKE_CXX_WARNING_LEVEL 3 CACHE STRING "Warning level" FORCE)
add_custom_target (lyx_run_tests COMMAND ${cmd})
set_target_properties(lyx_run_tests PROPERTIES FOLDER "tests")
-if(LYX_ASAN)
- set(LYX_CXX_FLAGS "-fsanitize=address -fno-omit-frame-pointer -g")
- message(STATUS)
- message(STATUS "Address sanitizer enabled. Usage:")
- message(STATUS " wget https://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py")
- message(STATUS " chmod +x ./asan_symbolize.py")
- message(STATUS " ./bin/lyx2.2 2>&1 | ./asan_symbolize.py | c++filt ")
- message(STATUS)
-endif()
-
if(LYX_INSTALL)
if(${LYX_PYTHON_EXECUTABLE} MATCHES "-NOTFOUND")
message(STATUS "Python required to create doc!")
# 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()