cmake: more option cleanup, use LYX_OPTION macro for consistent messages and variable naming

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34790 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Peter Kümmel 2010-07-06 19:47:16 +00:00
parent 7fd69c63a7
commit 2b99cacec9
12 changed files with 89 additions and 108 deletions

View File

@ -6,7 +6,7 @@
# Copyright (c) 2008-2010 Kornel Benko, <Kornel.Benko@berlin.de>
cmake_minimum_required(VERSION 2.4)
cmake_minimum_required(VERSION 2.6.4)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 OLD)
@ -17,20 +17,38 @@ project(lyx)
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/
# is checked
# where to look first for cmake modules,
# before ${CMAKE_ROOT}/Modules is checked
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules")
include(LyXMacros)
message(STATUS)
message(STATUS "Switch LYX_* variables by -DLYX_*=1 or 0:")
LYX_OPTION(INSTALL "Build install projects/rules" ON)
LYX_OPTION(DISABLE_PCH "Disable precompiled headers" ON)
LYX_OPTION(DEBUG_GLIBC "Enable libstdc++ debug mode" OFF)
LYX_OPTION(DEBUG_GLIBC_PEDANTIC "Enable libstdc++pedantic debug mode" OFF)
LYX_OPTION(USE_EXTERNAL_BOOST "Use external boost" OFF)
LYX_OPTION(NLS "Use nls" OFF)
LYX_OPTION(ASPELL "Use aspell" OFF)
LYX_OPTION(NO_CONSOLE "Suppress Console on Windows" OFF)
LYX_OPTION(USE_VERSION_SUFFIX "Use version suffix for packaging" OFF)
LYX_OPTION(VLD "Use VLD on with MSVC" OFF)
LYX_OPTION(MERGE_FILES "Merge source files into one copilation unit" OFF)
LYX_OPTION(DEBUG "Build debug version" OFF)
LYX_OPTION(RELEASE "Build release" ON)
LYX_OPTION(PROFILE "Enable profile build for GCC" OFF)
LYX_OPTION(STDLIB_DEBUG "Use debug stdstdlib" OFF)
LYX_OPTION(CONCEPT_CHECKS "Enable concept-checks" OFF)
LYX_OPTION(QUIET "Don't generate verbose makefiles" OFF)
LYX_OPTION(SHARED_LIBRARIES "Build shared libraries" OFF)
LYX_OPTION(USE_EXTERNAL_LIBINTL "Use external libintl" ON)
message(STATUS)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
option(LYX_DEBUG_GLIBC "Enable libstdc++ debug mode" OFF)
option(LYX_DEBUG_GLIBC_PEDANTIC "Enable libstdc++pedantic debug mode" OFF)
option(LYX_INSTALL "Build install projects/rules" ON)
option(LYX_USE_VERSION_SUFFIX "Using executables with versioned suffix" OFF)
option(LYX_ASPELL "Use aspell library" OFF)
option(LYX_NLS "Enable build with nls support" OFF)
option(LYX_USE_EXTERNAL_BOOST "Use external boost" OFF)
option(LYX_DISABLE_PCH "Disable precompiled headers" ON)
if(UNIX OR MINGW)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
@ -98,11 +116,9 @@ foreach(_c_l ${_config_lines} )
endforeach(_c_l)
if(LYX_USE_VERSION_SUFFIX)
message(STATUS "-- Using versioned PACKAGE. Disable with -DLYX_USE_VERSION_SUFFIX=OFF")
set(PACKAGE ${PACKAGE_BASE}${LYX_INSTALL_SUFFIX})
set(PROGRAM_SUFFIX "${LYX_INSTALL_SUFFIX}")
else()
message(STATUS "-- PACKAGE not versioned, to enable use -DLYX_USE_VERSION_SUFFIX=ON")
else()
set(PACKAGE ${PACKAGE_BASE})
set(PROGRAM_SUFFIX "")
endif()
@ -144,64 +160,47 @@ set(LYX_CPP_FILES *.cpp)
set(LYX_HPP_FILES *.h)
set(LYX_MOC_FILES moc_*.cpp)
include(LyXMacros)
include(ProjectSourceGroup)
if(merge OR merge_rebuild)
set(merge 1 CACHE TYPE STRING FORCE)
set(MERGE_FILES 1 CACHE TYPE STRING FORCE)
message(STATUS "")
message(STATUS "All *.cpp files of a project are merged into two files, disable with -Dmerge=0")
message(STATUS "")
if(LYX_MERGE_FILES)
add_definitions(-DLYX_MERGED_BUILD)
else()
set(merge 0 CACHE TYPE STRING FORCE)
set(MERGE_FILES 0 CACHE TYPE STRING FORCE)
message(STATUS "Enable merging files with -Dmerge=1")
endif()
set(CMAKE_BUILD_TYPE Release)
if(profile)
if(LYX_PROFILE)
set(CMAKE_BUILD_TYPE Profile CACHE TYPE STRING FORCE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg"
CACHE TYPE STRING FORCE)
set(profile)
CACHE TYPE STRING FORCE)
endif()
if(release)
if(LYX_RELEASE)
set(CMAKE_BUILD_TYPE Release CACHE TYPE STRING FORCE)
set(release TRUE CACHE TYPE STRING FORCE)
set(release)
endif()
if(debug)
if(LYX_DEBUG)
set(CMAKE_BUILD_TYPE Debug CACHE TYPE STRING FORCE)
set(debug TRUE CACHE TYPE STRING FORCE)
set(debug)
endif()
if(shared)
if(LYX_SHARED_LIBRARIES)
set(library_type SHARED)
message(STATUS "building shared libraries")
else()
set(library_type STATIC)
endif()
if(NOT MSVC)
if(NOT quiet)
set(CMAKE_VERBOSE_MAKEFILE ON CACHE TYPE STRING FORCE)
message(STATUS "verbose Makefile, disable with -Dquiet=1")
message(STATUS "")
else()
set(CMAKE_VERBOSE_MAKEFILE OFF CACHE TYPE STRING FORCE)
if(NOT LYX_QUIET)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()
set(LYX_CXX_FLAGS -Wall)
if(stdlib-debug)
if(LYX_STDLIB_DEBUG)
set(LYX_CXX_FLAGS "${LYX_CXX_FLAGS} -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC")
endif()
if(concept-checks)
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)
@ -220,21 +219,19 @@ add_definitions(-DQT_NO_STL -DQT_NO_KEYWORDS)
find_package(ZLIB REQUIRED)
if(all OR LYX_ASPELL)
set(LYX_ASPELL TRUE CACHE TYPE STRING)
if(LYX_ASPELL)
find_package(ASPELL REQUIRED)
else()
find_package(ASPELL)
endif()
set(LYX_ASPELL)
set(use_external_libintl TRUE)
if(use_external_libintl)
if(LYX_USE_EXTERNAL_LIBINTL)
find_package(Libintl REQUIRED)
add_definitions(-DHAVE_GETTEXT)
endif()
if(WIN32)
find_library(HUNSPELL_LIBRARY "libhunspell")
else()
@ -247,9 +244,9 @@ endif()
if (HUNSPELL_FOUND)
add_definitions(-DUSE_HUNSPELL=1)
message(STATUS "----- Building with USE_HUNSPELL")
message(STATUS "Building with USE_HUNSPELL")
else()
message(STATUS "----- Hunspell not found, building without hunspell support")
message(STATUS "Hunspell not found, building without hunspell support")
endif()
if(WIN32)
@ -262,37 +259,24 @@ endif()
if (ENCHANT_LIBRARY AND ENCHANT_INCLUDE_DIR)
set(ENCHANT_FOUND TRUE)
add_definitions(-DUSE_ENCHANT=1)
message(STATUS "----- Building with USE_ENCHANT")
message(STATUS "Building with USE_ENCHANT")
else()
message(STATUS "----- Enchant not found, building without enchant support")
message(STATUS "Enchant not found, building without enchant support")
endif()
message(STATUS "")
if(LYX_NLS OR all)
set(LYX_NLS TRUE CACHE TYPE STRING)
add_definitions(-DENABLE_NLS=1)
message(STATUS "----- Building with ENABLE_NLS")
else()
message(STATUS "----- No nls, to enable use -DLYX_NLS=1")
if(LYX_NLS)
add_definitions(-DENABLE_NLS=1)
endif()
set(LYX_NLS)
if(ASPELL_FOUND)
add_definitions(-DUSE_ASPELL=1)
message(STATUS "----- Building with USE_ASPELL")
else()
message(STATUS "----- No aspell, to get more information use -DLYX_ASPELL=ON")
endif()
set(all)
if(WIN32)
option(LYX_NO_CONSOLE "Compile LyX as a GUI" OFF)
if(LYX_NO_CONSOLE)
set(LYX_NO_CONSOLE TRUE CACHE TYPE STRING)
if(LYX_NO_CONSOLE)
set(WIN32_CONSOLE WIN32)
set(LYX_QTMAIN_LIBRARY ${QT_QTMAIN_LIBRARY})
message(STATUS "----- Console disabled")
else()
message(STATUS "----- Console enabled, disable it with -DLYX_NO_CONSOLE=ON")
endif()
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DNOMINMAX)
@ -323,9 +307,6 @@ include(PCHSupport_26)
if(NOT LYX_DISABLE_PCH)
message(STATUS "-----")
message(STATUS "----- using precompiled headers, disable with -DLYX_DISABLE_PCH=1")
message(STATUS "-----")
configure_file(${CMAKE_SOURCE_DIR}/pcheaders.h ${CMAKE_BINARY_DIR}/pcheaders.h)
configure_file(${CMAKE_SOURCE_DIR}/config.cpp.cmake ${CMAKE_BINARY_DIR}/config_pch.cpp)
add_definitions(-DLYX_ENABLE_PCH)
@ -353,11 +334,6 @@ if(NOT LYX_DISABLE_PCH)
endmacro()
endif()
else()
if(MSVC)
message(STATUS "-----")
message(STATUS "----- precompiled headers disabled, enable with -DLYX_DISABLE_PCH=0")
message(STATUS "-----")
endif()
set(LYX_DISABLE_PCH TRUE CACHE TYPE STRING)
macro(lyx_add_msvc_pch)
endmacro(lyx_add_msvc_pch)
@ -366,23 +342,14 @@ else()
endif()
if(MSVC)
if(vld)
set(vld 1 CACHE TYPE STRING FORCE)
if(LYX_VLD)
set(LYX_LEAK_DETECTION 1 CACHE TYPE STRING FORCE)
message(STATUS "")
message(STATUS "Leak detection enabled, disable with -Dvld=0")
message(STATUS "")
set(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH})
set(vld_path ${CMAKE_CURRENT_SOURCE_DIR}/../Win32/vld)
include(${vld_path}/tools/cmake/vld.cmake)
else()
set(vld 0 CACHE TYPE STRING FORCE)
set(LYX_LEAK_DETECTION 0 CACHE TYPE STRING FORCE)
message(STATUS "")
message(STATUS "Enable leak detection with -Dvld=1")
message(STATUS "")
endif()
# TODO options
if(WALL)
set(WALL 1 CACHE TYPE STRING FORCE)
@ -450,13 +417,15 @@ endif()
FIND_PROGRAM(_PERL_EXECUTABLE perl)
if(NOT ${_PERL_EXECUTABLE} MATCHES "-NOTFOUND")
if(LYX_NLS OR all)
if(LYX_NLS)
find_package(LyXGettext REQUIRED)
include_directories(${TOP_SRC_DIR}/po)
add_subdirectory(po)
endif()
endif()
if(LYX_DEBUG_GLIBC)
set(_GLIBCXX_DEBUG 1)
endif()
@ -483,6 +452,7 @@ include_directories(
${CMAKE_BINARY_DIR}
${TOP_SRC_DIR}/src)
if(LYX_USE_EXTERNAL_BOOST)
message(STATUS "Searching for boost")
find_package(Boost COMPONENTS signals regex)
@ -494,7 +464,6 @@ if(LYX_USE_EXTERNAL_BOOST)
message(FATAL_ERROR "Boost not found" ${Boost_ERROR_REASON})
endif()
else()
message(STATUS "----- Using internal boost. To build with installed version use -DLYX_USE_EXTERNAL_BOOST:BOOL=ON")
if(LYX_USE_TR1_REGEX)
set(Lyx_Boost_Libraries boost_signals)
else()
@ -506,7 +475,7 @@ else()
endif()
if(NOT use_external_libintl)
if(NOT LYX_USE_EXTERNAL_LIBINTL)
add_subdirectory(intl)
endif()
add_subdirectory(src)
@ -553,10 +522,10 @@ SET(CPACK_RESOURCE_FILE_LICENSE "${TOP_SRC_DIR}/development/cmake/LyX_license.tx
# Find the revision number and use it as the release in rpm-package-build.
# This way we may omit the otherwise needed "--force" parameter when
# installing from that rpm package.
FIND_PROGRAM(_svnversion svnversion)
message(STATUS "svnversion = ${_svnversion}")
if(NOT ${_svnversion} MATCHES "-NOTFOUND")
EXECUTE_PROCESS(COMMAND ${_svnversion} WORKING_DIRECTORY "${TOP_SRC_DIR}" OUTPUT_VARIABLE CPACK_RPM_PACKAGE_RELEASE OUTPUT_STRIP_TRAILING_WHITESPACE)
FIND_PROGRAM(LYX_SVNVERSION svnversion)
#message(STATUS "svnversion = ${LYX_SVNVERSION}")
if(NOT ${LYX_SVNVERSION} MATCHES "-NOTFOUND")
EXECUTE_PROCESS(COMMAND ${LYX_SVNVERSION} WORKING_DIRECTORY "${TOP_SRC_DIR}" OUTPUT_VARIABLE CPACK_RPM_PACKAGE_RELEASE OUTPUT_STRIP_TRAILING_WHITESPACE)
# We use this value also to set the package-patch-value
if(CPACK_RPM_PACKAGE_RELEASE MATCHES "^\([0-9]+\)")
set(CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_1})
@ -591,3 +560,4 @@ endif()
# list # rpm -qlp lyx-2.0.1-Linux.rpm # dpkg-deb -c lyx-2.0.1-Linux.deb
# install # rpm -U lyx-2.0.1-Linux.rpm # dpkg -i lyx-2.0.1-Linux.deb
#
message(STATUS)

View File

@ -2,7 +2,7 @@
# TODO: set correct path in call to cmake
# e.g. cmake /usr/src/lyx/lyx-devel/development/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/share/lyx2.0 -Dnls=1
message(STATUS "installing to ${CMAKE_INSTALL_PREFIX}, defined by CMAKE_INSTALL_PREFIX")
message(STATUS "Installing to ${CMAKE_INSTALL_PREFIX}, defined by CMAKE_INSTALL_PREFIX")
# the macro scans the directories "_parent_src_dir/_dir/_current_dir" for *._file_type files
# and installs the files in CMAKE_INSTALL_PREFIX/_current_dir

View File

@ -16,7 +16,7 @@ set(boost_signals_sources
lyx_add_path(boost_signals_sources ${TOP_SRC_DIR}/boost/libs/signals/src)
if(NOT MERGE_FILES)
if(NOT LYX_MERGE_FILES)
add_library(boost_signals STATIC ${boost_signals_sources})
else()
lyx_const_touched_files(_allinone boost_signals_sources)

View File

@ -226,3 +226,14 @@ macro(lyx_qt_resources_file _qrc_name _to_dir _list)
endif()
endmacro(lyx_qt_resources_file)
macro(LYX_OPTION _name _description _default)
option(LYX_${_name} ${_description} ${_default})
set(_msg ON)
if(_msg)
string(SUBSTRING "LYX_${_name} " 0 25 _var)
string(SUBSTRING "${LYX_${_name}} " 0 4 _val)
message(STATUS "${_var}: ${_val} (${_description})")
endif()
endmacro()

View File

@ -67,12 +67,12 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}
lyx_add_msvc_pch(lyx)
if (MERGE_FILES)
if (LYX_MERGE_FILES)
lyx_const_touched_files(_allinone lyx_sources)
set(lyx_sources ${_allinone_files})
endif()
if (LYX_LEAK_DETECTION)
if (LYX_VLD)
configure_file(${vld_path}/vld.ini ${CMAKE_CURRENT_BINARY_DIR}/vld.ini COPYONLY)
configure_file(${vld_path}/vld.ini ${CMAKE_CURRENT_BINARY_DIR}/memory_leak_report.txt COPYONLY)
set(vld_files ${CMAKE_CURRENT_BINARY_DIR}/vld.ini ${CMAKE_CURRENT_BINARY_DIR}/memory_leak_report.txt)

View File

@ -14,7 +14,7 @@ file(GLOB frontends_sources ${TOP_SRC_DIR}/src/frontends/${LYX_CPP_FILES})
file(GLOB frontends_headers ${TOP_SRC_DIR}/src/frontends/${LYX_HPP_FILES})
if(NOT MERGE_FILES)
if(NOT LYX_MERGE_FILES)
add_library(frontends ${library_type} ${frontends_sources} ${frontends_headers})
else()
lyx_const_touched_files(_allinone frontends_sources)

View File

@ -36,7 +36,7 @@ include_directories(
${QT_INCLUDES}
${CMAKE_CURRENT_BINARY_DIR})
if(MERGE_FILES)
if(LYX_MERGE_FILES)
lyx_const_touched_files(_allinone frontends_qt4_sources)
set(depends_moc_uic ${frontends_qt4_headers} ${ui_files})
set_source_files_properties(_allinone_const.C

View File

@ -14,7 +14,7 @@ lyx_add_msvc_pch(graphics)
include_directories(${TOP_SRC_DIR}/src/graphics)
if(NOT MERGE_FILES)
if(NOT LYX_MERGE_FILES)
add_library(graphics ${library_type} ${graphics_sources} ${graphics_headers})
else()
lyx_const_touched_files(_allinone graphics_sources)

View File

@ -16,7 +16,7 @@ lyx_add_msvc_pch(insets)
include_directories(${TOP_SRC_DIR}/src/insets ${QT_INCLUDES})
if(NOT MERGE_FILES)
if(NOT LYX_MERGE_FILES)
add_library(insets ${library_type} ${insets_sources} ${insets_headers})
else()
lyx_const_touched_files(_allinone insets_sources)

View File

@ -17,7 +17,7 @@ lyx_add_msvc_pch(mathed)
include_directories(${TOP_SRC_DIR}/src/mathed)
if(NOT MERGE_FILES)
if(NOT LYX_MERGE_FILES)
add_library(mathed ${library_type} ${mathed_sources} ${mathed_headers})
else()
lyx_const_touched_files(_allinone mathed_sources)

View File

@ -49,7 +49,7 @@ include_directories(${TOP_SRC_DIR}/src/support
${ZLIB_INCLUDE_DIR})
if(NOT MERGE_FILES)
if(NOT LYX_MERGE_FILES)
set(support_sources ${support_sources} ${support_mythes_sources} ${support_linkback_sources})
set(support_headers ${support_headers} ${support_mythes_headers} ${support_linkback_headers})
add_library(support ${library_type} ${support_sources} ${support_headers} ${dont_merge})

View File

@ -29,7 +29,7 @@ include_directories(BEFORE ${TOP_SRC_DIR}/src/tex2lyx
add_definitions(-DTEX2LYX)
if(NOT MERGE_FILES)
if(NOT LYX_MERGE_FILES)
add_executable(${_tex2lyx} ${tex2lyx_sources} ${LINKED_sources}
${tex2lyx_headers} ${LINKED_headers})
else()