]> git.lyx.org Git - features.git/blob - CMakeLists.txt
cmake: build a .dmg file on Mac, looks not as nice as the official installer but...
[features.git] / CMakeLists.txt
1 # This file is part of LyX, the document processor.
2 # Licence details can be found in the file COPYING.
3 #
4 # Copyright (c) 2006-2011 Peter Kümmel, <syntheticpp@gmx.net>
5 # Copyright (c) 2008-2011 Kornel Benko, <Kornel.Benko@berlin.de>
6
7 cmake_minimum_required(VERSION 2.6.4)
8
9 set(LYX_PROJECT lyx)
10
11 set(LYX_CMAKE_DIR "development/cmake")
12 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/${LYX_CMAKE_DIR}/modules")
13
14 get_filename_component(lyx_dir_readme ${CMAKE_SOURCE_DIR}/README ABSOLUTE)
15 get_filename_component(TOP_SRC_DIR ${lyx_dir_readme} PATH)
16
17 set(CMAKE_PROJECT_NAME ${LYX_PROJECT})
18
19 message(STATUS)
20 if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) 
21         message(STATUS "Building in-source")
22         set(TOP_BINARY_DIR "${CMAKE_BINARY_DIR}/build")
23 else()
24         message(STATUS "Building out-of-source")
25         set(TOP_BINARY_DIR "${CMAKE_BINARY_DIR}")
26 endif()
27
28
29 if(COMMAND cmake_policy)
30         cmake_policy(SET CMP0003 OLD)
31         cmake_policy(SET CMP0005 OLD)
32 endif()
33
34 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
35
36 # Supress regeneration
37 set(CMAKE_SUPPRESS_REGENERATION FALSE)
38
39
40 include(LyXMacros)
41
42 # Usage LYX_OPTION
43 # 1. parameter: option name without prefix 'LYX_'
44 # 2. parameter: description
45 # 3. parameter: default value, ON or OFF
46 # 4. parameter: system on which option is used: ALL, GCC, MSVC, ...
47
48
49 LYX_OPTION_INIT()
50
51 # Options for all compilers/systems
52 LYX_OPTION(CPACK            "Use the CPack management (Implies LYX_INSTALL option)" OFF ALL)
53 LYX_OPTION(INSTALL          "Build install projects/rules (implies a bunch of other options)" OFF ALL)
54 LYX_OPTION(NLS              "Enable Native Language Support (NLS)" ON ALL)
55 LYX_OPTION(ASPELL           "Require aspell" OFF ALL)
56 LYX_OPTION(ENCHANT          "Require Enchant" OFF ALL)
57 LYX_OPTION(HUNSPELL         "Require Hunspell" OFF ALL)
58 LYX_OPTION(DEVEL_VERSION    "Build developer version" OFF ALL) 
59 LYX_OPTION(RELEASE          "Build release version, build debug when disabled" OFF ALL)
60 LYX_OPTION(DEBUG            "Enforce debug build"  OFF ALL)
61 LYX_OPTION(NO_OPTIMIZE      "Don't use any optimization/debug flags"  OFF ALL)
62 LYX_OPTION(PACKAGE_SUFFIX   "Use version suffix for packaging" ON ALL)
63 LYX_OPTION(PCH              "Use precompiled headers" OFF ALL)
64 LYX_OPTION(MERGE_FILES      "Merge source files into one compilation unit" OFF ALL)
65 LYX_OPTION(MERGE_REBUILD    "Rebuild generated files from merged files build" OFF ALL)
66 LYX_OPTION(QUIET            "Don't generate verbose makefiles" OFF ALL)
67 LYX_OPTION(INSTALL_PREFIX   "Install path for LyX" OFF ALL)
68 LYX_OPTION(EXTERNAL_LIBINTL "Use external libintl" ON ALL)
69
70 # GCC specific
71 LYX_OPTION(PROFILE              "Build profile version" OFF GCC)
72 LYX_OPTION(EXTERNAL_BOOST       "Use external boost" OFF GCC)
73 LYX_OPTION(PROGRAM_SUFFIX       "Append version suffix to binaries" ON GCC)
74 LYX_OPTION(DEBUG_GLIBC          "Enable libstdc++ debug mode" OFF GCC)
75 LYX_OPTION(DEBUG_GLIBC_PEDANTIC "Enable libstdc++pedantic debug mode" OFF GCC)
76 LYX_OPTION(STDLIB_DEBUG         "Use debug stdlib" OFF GCC)
77 LYX_OPTION(CONCEPT_CHECKS       "Enable concept-checks" OFF GCC)
78
79 # MSVC specific
80 LYX_OPTION(CONSOLE               "Show console on Windows" ON MSVC)
81 LYX_OPTION(VLD                   "Use VLD with MSVC" OFF MSVC)
82 LYX_OPTION(WALL                  "Enable all warnings" OFF MSVC)
83 LYX_OPTION(CONFIGURE_CHECKS      "Also run configure checks for MSVC" OFF MSVC)
84 LYX_OPTION(DEPENDENCIES_DOWNLOAD "Download dependencies for MSVC 10" OFF MSVC)
85
86 # APPLE specific
87 LYX_OPTION(DMG                   "Build as Mac bundle, needed for .dmg  (experimental) " OFF GCC)
88 LYX_OPTION(COCOA                 "Use Cocoa on Mac" OFF GCC)
89
90 if(help OR HELP)
91         message(STATUS)
92         message(STATUS "Available options: (dis/enable with -D=0/1)")
93         message(STATUS)
94         LYX_OPTION_LIST_ALL(help)       
95         message(STATUS)
96 else()
97
98 # 'project' triggers the searching for a compiler
99 project(${LYX_PROJECT})
100
101
102 # Check option dependencies
103
104 if(LYX_CPACK)
105         set(LYX_INSTALL ON)
106 endif()
107
108 if(LYX_INSTALL)
109         set(LYX_NLS ON)
110         if (WIN32)
111                 set(LYX_HUNSPELL ON)
112         endif()
113         set(LYX_CONSOLE OFF)
114         set(LYX_PACKAGE_SUFFIX ON)
115         set(LYX_RELEASE ON)
116         set(LYX_PROFILE OFF)
117 endif()
118
119
120 if(LYX_MERGE_FILES)
121         set(LYX_PCH OFF)
122 else()
123         set(LYX_MERGE_REBUILD OFF)
124 endif()
125
126 if(LYX_DEPENDENCIES_DOWNLOAD)
127         message(STATUS)
128         set(LYX_DEPENDENCIES_DIR ${TOP_BINARY_DIR}/msvc2010-deps)
129         message(STATUS "Using downloaded dependencies in ${LYX_DEPENDENCIES_DIR}")
130         set(deps_files lyx20-deps-msvc2010-x86.zip)
131         foreach(it ${deps_files})
132                 set(already_downloaded already_downloaded-NOTFOUND CACHE PATH "downloaded" FORCE)
133                 find_file(already_downloaded ${it} "${LYX_DEPENDENCIES_DIR}/download")
134                 if(NOT already_downloaded)
135                         message(STATUS "Downloading ${it} ...")
136                         file(DOWNLOAD ftp://ftp.devel.lyx.org/pub/contrib/windows/${it} ${LYX_DEPENDENCIES_DIR}/download/${it} SHOW_PROGRESS)
137                         execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf ${LYX_DEPENDENCIES_DIR}/download/${it}
138                                       WORKING_DIRECTORY ${LYX_DEPENDENCIES_DIR})
139                 endif()
140         endforeach()
141         set(GNUWIN32_DIR ${LYX_DEPENDENCIES_DIR}/deps20)
142 endif()
143
144
145
146 message(STATUS)
147
148 set(EXECUTABLE_OUTPUT_PATH  ${TOP_BINARY_DIR}/bin)
149 set(LIBRARY_OUTPUT_PATH  ${TOP_BINARY_DIR}/lib)
150
151
152
153 if(UNIX OR MINGW)
154         execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
155         message(STATUS "Using GCC version ${GCC_VERSION}")
156         if(NOT GCC_VERSION VERSION_LESS 4.4)
157                 set(LYX_USE_TR1 1)
158                 # GCC <= 4.5 does not support regex: there are linker errors
159                 # http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.tr1
160                 set(LYX_USE_TR1_REGEX 0)
161         endif()
162 else()
163         if(MSVC10)
164                 set(LYX_USE_TR1 1)
165                 #set(LYX_USE_TR1_REGEX 1) #TODO should we use it in ECMAScript mode?
166         endif()
167 endif()
168
169
170 set(VERSION_INFO "CMake Build")
171
172 # Try to get some informations from configure.ac
173
174 include(LyXPaths)
175 file(STRINGS "${TOP_SRC_DIR}/configure.ac" _config_lines)
176
177 if(WIN32)
178         set(USE_WINDOWS_PACKAGING 1)
179 elseif(APPLE)
180         set(USE_MACOSX_PACKAGING 1)
181 else()
182         set(USE_POSIX_PACKAGING 1)
183 endif()
184
185 macro(setstripped _varname _value)
186         string(STRIP ${_value} _v)
187         if(USE_POSIX_PACKAGING)
188                 string(TOLOWER ${_v} ${_varname})
189         else()
190                 set(${_varname} ${_v})
191         endif()
192 endmacro(setstripped)
193
194 foreach(_c_l ${_config_lines} )
195         if(_c_l MATCHES "^AC_INIT\\(\([^,]+\),\([^,]+\), *\\[\([^,]+\)\\] *,\(.*\)")
196                 setstripped(PACKAGE_BASE ${CMAKE_MATCH_1})
197                 setstripped(PACKAGE_VERSION ${CMAKE_MATCH_2})
198                 setstripped(PACKAGE_BUGREPORT ${CMAKE_MATCH_3})
199                 if(PACKAGE_VERSION MATCHES "^\([0-9]+\)\\.\([0-9]+\).*$")
200                         set(LYX_MAJOR_VERSION ${CMAKE_MATCH_1})
201                         set(LYX_MINOR_VERSION ${CMAKE_MATCH_2})
202                         set(LYX_DIR_VER "LYX_DIR_${CMAKE_MATCH_1}${CMAKE_MATCH_2}x")
203                         set(LYX_USERDIR_VER "LYX_USERDIR_${CMAKE_MATCH_1}${CMAKE_MATCH_2}x")
204                         set(LYX_INSTALL_SUFFIX "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}")
205                 endif()
206         endif()
207         if(_c_l MATCHES "^AC_SUBST\\( *LYX_DATE *, *\\[\\\"(.*)\\\"\\].*")
208                 set(LYX_DATE "${CMAKE_MATCH_1}")
209         endif()
210 endforeach(_c_l)
211
212
213 if(LYX_DMG)
214     set(bundle_dir ${TOP_BINARY_DIR}/bin)
215         set(LYX_CPACK 1)
216         set(LYX_BUNDLE MACOSX_BUNDLE)
217         set(LYX_INSTALL_PREFIX LyX2.1 CACHE STRING "LyX bundle install prefix" FORCE)
218         set(LYX_DATA_SUBDIR LyX.app/Contents/Resources/ CACHE STRING "Bundle Contents dir" FORCE)
219         message(STATUS)
220         message(STATUS "Bundle creation is enabled.")
221         message(STATUS "It is experimental, to increase turn around speed use:")
222         message(STATUS "    cmake -DLYX_MERGE_FILES=1 -DLYX_NO_OPTIMIZE=1 -DLYX_INSTALL=1 -DLYX_DMG=1 ../trunk")
223         message(STATUS "or use the shell script 'developent/cmake/dmg'")
224         message(STATUS)
225 endif()
226
227
228 if(LYX_INSTALL_PREFIX)
229         set(CMAKE_INSTALL_PREFIX ${LYX_INSTALL_PREFIX} CACHE PATH "LyX user's choice install prefix" FORCE)
230         set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
231 endif()
232 set(LYX_INSTALL_PREFIX ${LYX_INSTALL_PREFIX} CACHE PATH "LyX user's choice install prefix" FORCE)
233
234 if(LYX_PACKAGE_SUFFIX)
235         set(PACKAGE ${PACKAGE_BASE}${LYX_INSTALL_SUFFIX})
236 else()  
237         set(PACKAGE ${PACKAGE_BASE})
238 endif()
239
240 if(LYX_PROGRAM_SUFFIX)
241         set(PROGRAM_SUFFIX "${LYX_INSTALL_SUFFIX}")
242 else()
243         set(PROGRAM_SUFFIX "")
244 endif()
245
246
247 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
248         # see http://www.cmake.org/pipermail/cmake/2006-October/011559.html
249         if (UNIX)
250                 # don't use the default "/usr/local"
251                 # but respect the user-choice on the command-line
252                 if(LYX_INSTALL_SUFFIX)
253                         set(CMAKE_INSTALL_PREFIX "/usr/local/lyx${LYX_INSTALL_SUFFIX}" CACHE PATH "LyX default install prefix" FORCE)
254                 else()
255                         set(CMAKE_INSTALL_PREFIX "/usr/local/${LYX_PROJECT}" CACHE PATH "LyX default install prefix" FORCE)
256                 endif()
257         endif()
258         if(WIN32)
259                 set(CMAKE_INSTALL_PREFIX LYX_INSTALLED CACHE PATH "LyX default install prefix" FORCE)
260         endif()
261 endif()
262
263 if(NOT LYX_DATA_SUBDIR)
264         if (WIN32)
265                 set(LYX_DATA_SUBDIR "Resources/" CACHE STRING "Subdirectory for all lyx-system-data" FORCE)
266         else()
267                 set(LYX_DATA_SUBDIR "" CACHE STRING "Subdirectory for all lyx-system-data" FORCE)
268         endif()
269 endif()
270
271 set(LYX_ABS_INSTALLED_DATADIR "${CMAKE_INSTALL_PREFIX}")
272 set(LYX_LOCALEDIR "locale")
273 set(LYX_ABS_INSTALLED_LOCALEDIR "${LYX_ABS_INSTALLED_DATADIR}/${LYX_DATA_SUBDIR}${LYX_LOCALEDIR}")
274 set(LYX_ABS_TOP_SRCDIR "${TOP_SRC_DIR}")
275
276
277
278 if(NOT GROUP_CODE)
279         #set(GROUP_CODE "The Golden Code")
280         set(GROUP_CODE flat)
281 endif()
282
283 # lyx's source files
284 set(LYX_CPP_FILES *.cpp)
285 set(LYX_HPP_FILES *.h)
286 set(LYX_MOC_FILES moc_*.cpp)
287
288 include(ProjectSourceGroup)
289
290
291 if(LYX_PROFILE)
292         set(CMAKE_BUILD_TYPE Profile CACHE TYPE STRING FORCE)
293         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg" CACHE TYPE STRING FORCE)
294 endif()
295
296
297 if(LYX_NO_OPTIMIZE)
298         set(CMAKE_BUILD_TYPE None)
299         set(LYX_DEBUG OFF)
300         set(LYX_RELEASE OFF)
301 elseif(LYX_RELEASE)
302         set(CMAKE_BUILD_TYPE Release)
303         set(LYX_DEBUG OFF)
304 else()
305         set(CMAKE_BUILD_TYPE Debug)
306 endif()
307
308
309 # When shared libs are supported enable this option
310 #LYX_OPTION(SHARED_LIBRARIES "Build shared libraries" OFF ALL)
311 if(LYX_SHARED_LIBRARIES)
312         set(library_type SHARED)
313 else()
314         set(library_type STATIC)
315 endif()
316
317 if(NOT MSVC)
318         if(NOT LYX_QUIET)
319                 set(CMAKE_VERBOSE_MAKEFILE ON)
320         endif()
321         set(LYX_CXX_FLAGS "-Wall -Wunused-parameter")
322         if(LYX_STDLIB_DEBUG)
323                 set(LYX_CXX_FLAGS "${LYX_CXX_FLAGS} -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC")
324         endif()
325         if(LYX_CONCEPT_CHECKS)
326                 set(LYX_CXX_FLAGS "${LYX_CXX_FLAGS} -D_GLIBCPP_CONCEPT_CHECKS")
327         endif()
328         set(CMAKE_CXX_FLAGS       "${LYX_CXX_FLAGS} -fno-strict-aliasing " CACHE TYPE STRING FORCE)
329         set(CMAKE_CXX_FLAGS_DEBUG "${LYX_CXX_FLAGS} -fno-strict-aliasing -O0 -g -D_DEBUG" CACHE TYPE STRING FORCE)
330         if(MINGW)
331                 set(CMAKE_CXX_FLAGS_RELEASE "${LYX_CXX_FLAGS} -O2 -DNDEBUG" CACHE TYPE STRING FORCE)
332         else()
333                 set(CMAKE_CXX_FLAGS_RELEASE "${LYX_CXX_FLAGS} -O3 -DNDEBUG" CACHE TYPE STRING FORCE)
334         endif()
335         set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE} -pg" CACHE TYPE STRING FORCE)
336 endif()
337
338
339 find_package(Qt4 REQUIRED)
340
341
342 include_directories(${TOP_BINARY_DIR} ${TOP_SRC_DIR}/src)
343   
344 if(LYX_ASPELL)
345         find_package(ASPELL)
346         include_directories(${ASPELL_INCLUDE_DIR})
347 endif()
348
349 if(LYX_ENCHANT)
350         find_package(Enchant REQUIRED)
351         include_directories(${ENCHANT_INCLUDE_DIR})
352 endif()
353
354 if(LYX_HUNSPELL)
355         find_package(Hunspell REQUIRED)
356         include_directories(${HUNSPELL_INCLUDE_DIR})
357 endif()
358
359 if(LYX_NLS)
360         FIND_PROGRAM(LYX_PYTHON_EXECUTABLE python HINTS ${GNUWIN32_DIR}/python)
361         if(${LYX_PYTHON_EXECUTABLE} MATCHES "-NOTFOUND")
362                 message(FATAL_ERROR "Python 2.6 needed!")
363         endif()
364         find_package(LyXGettext REQUIRED)
365         include_directories(${TOP_SRC_DIR}/po)
366         add_subdirectory(po "${TOP_BINARY_DIR}/po")
367 endif()
368
369 if(LYX_NLS)
370         if(LYX_EXTERNAL_LIBINTL)
371                 find_package(Libintl REQUIRED)  
372                 if(DEFINED LIBINTL_LIBRARIES)
373                         # find getext when configuring
374                         list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBINTL_LIBRARIES})      
375                         # on mac use iconv also form ports
376                         get_filename_component(ICONV_RELATIVE_TO_LIBINTL ${LIBINTL_LIBRARIES} PATH)
377                 endif()
378         else()
379                 add_subdirectory(intl "${TOP_BINARY_DIR}/intl")
380         endif()
381 endif()
382
383 find_package(ICONV REQUIRED)
384 find_package(ZLIB REQUIRED)
385
386 if(LYX_EXTERNAL_BOOST)
387         message(STATUS "Searching for boost")
388         find_package(Boost COMPONENTS signals regex) #TODO could REQUIRED be used
389         if(Boost_FOUND)
390                 message(STATUS "Boost found")
391                 message(STATUS "Boost-libs = ${Boost_LIBRARIES}")
392                 set(Lyx_Boost_Libraries ${Boost_LIBRARIES})
393         else()
394                 message(FATAL_ERROR "Boost not found" ${Boost_ERROR_REASON})
395         endif()
396 else()
397         if(LYX_USE_TR1_REGEX)
398                 set(Lyx_Boost_Libraries boost_signals)
399         else()
400                 set(Lyx_Boost_Libraries boost_signals boost_regex)
401         endif()
402         add_definitions(-DBOOST_USER_CONFIG="<config.h>")
403         include_directories(${TOP_SRC_DIR}/boost)
404         add_subdirectory(boost "${TOP_BINARY_DIR}/boost")
405 endif()
406
407
408
409
410 if(WIN32)
411         if(NOT LYX_CONSOLE)
412                 set(WIN32_CONSOLE WIN32)
413                 set(LYX_QTMAIN_LIBRARY ${QT_QTMAIN_LIBRARY})
414         endif()
415         if(MSVC)
416                 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DNOMINMAX)
417                 # disable checked iterators for msvc release builds to get maximum speed
418                 set(CMAKE_CXX_FLAGS_RELEASE  "${CMAKE_CXX_FLAGS_RELEASE} /D_SECURE_SCL=0")
419         else()
420                 add_definitions(-DWINVER=0x0500)
421         endif()
422 endif()
423
424 message(STATUS "")
425 foreach(_v PACKAGE PACKAGE_VERSION
426         PROGRAM_SUFFIX LYX_DATE LYX_DIR_VER LYX_USERDIR_VER
427         LYX_ABS_TOP_SRCDIR
428         LYX_ABS_INSTALLED_DATADIR LYX_ABS_INSTALLED_LOCALEDIR LYX_INSTALL_SUFFIX)
429         if(NOT DEFINED ${_v})
430                 message(FATAL_ERROR "${_v} not defined")
431         endif()
432         string(SUBSTRING "${_v}                            " 0 28 _v1)
433         message(STATUS "----- ${_v1}: ${${_v}}")
434 endforeach(_v)
435 message(STATUS "")
436
437
438 if(LYX_PCH)
439         # PCHs not supported by cmake: http://www.cmake.org/Bug/view.php?id=1260
440         # Not sure if it works for all non-msvc compilers
441         include(PCHSupport_26)
442         configure_file(${TOP_SRC_DIR}/${LYX_CMAKE_DIR}/pcheaders.h      ${TOP_BINARY_DIR}/pcheaders.h)
443         configure_file(${TOP_SRC_DIR}/${LYX_CMAKE_DIR}/config.cpp.cmake ${TOP_BINARY_DIR}/config_pch.cpp)
444         add_definitions(-DLYX_ENABLE_PCH)
445
446         if(MSVC)
447                 macro(lyx_add_msvc_pch name_)
448                         set_source_files_properties(${${name_}_sources} PROPERTIES
449                                 COMPILE_FLAGS "/Yuconfig.h /Fp\$(IntDir)/config.pch")
450                         set_source_files_properties(${TOP_BINARY_DIR}/config_pch.cpp PROPERTIES
451                                 COMPILE_FLAGS "/Ycconfig.h /Fp\$(IntDir)/config.pch")
452                         set(${name_}_sources ${${name_}_sources} ${TOP_BINARY_DIR}/config_pch.cpp
453                                 ${TOP_BINARY_DIR}/pcheaders.h)
454                         set(CMAKE_CXX_FLAGS_DEBUG       "${CMAKE_CXX_FLAGS_DEBUG} /DLYX_PCH_STL /DLYX_PCH_BOOST /DLYX_PCH_QT4")
455                         set(CMAKE_CXX_FLAGS_RELEASE     "${CMAKE_CXX_FLAGS_RELEASE} /DLYX_PCH_STL /DLYX_PCH_BOOST /DLYX_PCH_QT4")
456                         set(CMAKE_CXX_FLAGS_MINSIZEREL  "${CMAKE_CXX_FLAGS_MINSIZEREL} /DLYX_PCH_STL /DLYX_PCH_BOOST")                  
457                 endmacro(lyx_add_msvc_pch)
458                 macro(lyx_add_gcc_pch name_)
459                 endmacro()
460         else()
461                 macro(lyx_add_msvc_pch name_)
462                 endmacro()
463                 macro(lyx_add_gcc_pch name_)
464                         add_definitions(-DLYX_PCH_STL -DLYX_PCH_BOOST -DLYX_PCH_QT4)
465                         ADD_PRECOMPILED_HEADER(${name_} ${TOP_BINARY_DIR}/config_pch.cpp ${TOP_BINARY_DIR}/config.h.gch)
466                 endmacro()
467         endif()
468 else()
469         macro(lyx_add_msvc_pch)
470         endmacro(lyx_add_msvc_pch)
471         macro(lyx_add_gcc_pch name_)
472         endmacro()
473 endif()
474
475 if(MSVC)
476         if(LYX_VLD)
477                 set(LYX_LEAK_DETECTION 1 CACHE TYPE STRING FORCE)
478                 set(LIBRARY_OUTPUT_PATH  ${EXECUTABLE_OUTPUT_PATH})
479                 set(LYX_VLD_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../Win32/vld)
480                 include(${LYX_VLD_PATH}/tools/cmake/vld.cmake)
481         endif()
482
483         if(LYX_WALL)
484                 # Use the highest warning level
485                 set(CMAKE_CXX_WARNING_LEVEL 4 CACHE TYPE STRING FORCE)
486
487                 if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
488                         string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
489                 else()
490                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
491                 endif()
492
493                 if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
494                         string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
495                 else()
496                         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
497                 endif()
498
499                 # add here warnings which should produce an error /weXXXX
500                 set(MSVC_W_ERROR   "/we4101 /we4189")
501                 # add here warnings which should be disabled /wdXXXX
502                 set(MSVC_W_DISABLE "/wd4288 /wd4355 /wd4800 /wd4996 /wd4311 /wd4312 /wd4505 /wd4267 /wd4512 /wd4245 /wd4127 /wd4180 /wd4231")
503
504                 set(CMAKE_CXX_FLAGS_DEBUG      "${CMAKE_CXX_FLAGS_DEBUG} /Wp64 ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
505                 set(CMAKE_CXX_FLAGS_RELEASE    "${CMAKE_CXX_FLAGS_RELEASE} /Wp64 ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
506                 set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /Wp64 ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
507
508         else()
509                 set(CMAKE_CXX_WARNING_LEVEL 3 CACHE TYPE STRING FORCE)
510
511                 # add here warnings which should produce an error /weXXXX
512                 set(MSVC_W_ERROR   "/we4101 /we4189")
513                 # add here warnings which should be disabled /wdXXXX
514                 set(MSVC_W_DISABLE "/wd4288 /wd4355 /wd4800 /wd4996 /wd4267 /wd4180 /wd4231")
515
516                 set(CMAKE_CXX_FLAGS_DEBUG      "${CMAKE_CXX_FLAGS_DEBUG} ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
517                 set(CMAKE_CXX_FLAGS_RELEASE    "${CMAKE_CXX_FLAGS_RELEASE} ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
518                 set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${MSVC_W_ERROR} ${MSVC_W_DISABLE}")
519
520         endif()
521         set(CMAKE_CXX_FLAGS_DEBUG      "${CMAKE_CXX_FLAGS_DEBUG} /Zc:wchar_t-")
522         set(CMAKE_CXX_FLAGS_RELEASE    "${CMAKE_CXX_FLAGS_RELEASE} /Zc:wchar_t-")
523         set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /Zc:wchar_t-")
524
525         message(STATUS "----- Warning level      : ${CMAKE_CXX_WARNING_LEVEL}  ${WARNING_LEVEL_MESSAGE}")
526         message(STATUS "----- Warnings as errors : ${MSVC_W_ERROR}")
527         message(STATUS "----- Warnings disabled  : ${MSVC_W_DISABLE}")
528         message(STATUS "")
529 endif()
530
531
532 if(LYX_DEBUG_GLIBC)
533         set(_GLIBCXX_DEBUG 1)
534 endif()
535
536 if(LYX_DEBUG_GLIBC_PEDANTIC)
537         set(_GLIBCXX_DEBUG_PEDANTIC 1)
538 endif()
539
540 # compiler tests, config.h generation
541 if(MSVC AND NOT LYX_CONFIGURE_CHECKS)
542         configure_file(${LYX_CMAKE_DIR}/configCompiler.h.msvc ${TOP_BINARY_DIR}/configCompiler.h)
543 else()
544         include(${LYX_CMAKE_DIR}/ConfigureChecks.cmake)
545         configure_file(${LYX_CMAKE_DIR}/configCompiler.h.cmake ${TOP_BINARY_DIR}/configCompiler.h)
546 endif()
547
548 configure_file(${LYX_CMAKE_DIR}/config.h.cmake ${TOP_BINARY_DIR}/config.h)
549
550
551 add_subdirectory(src "${TOP_BINARY_DIR}/src")
552 add_subdirectory(lib/lyx2lyx "${TOP_BINARY_DIR}/lyx2lyx")
553 add_subdirectory(lib/scripts "${TOP_BINARY_DIR}/scripts")
554
555
556 if(LYX_INSTALL)
557         FIND_PROGRAM(LYX_PERL_EXECUTABLE perl)
558         if(${LYX_PERL_EXECUTABLE} MATCHES "-NOTFOUND")
559                 message(FATAL_ERROR "Perl required!")
560         endif()
561         add_subdirectory(${LYX_CMAKE_DIR}/man "${TOP_BINARY_DIR}/man")
562         add_subdirectory(${LYX_CMAKE_DIR}/doc "${TOP_BINARY_DIR}/doc")
563         include(../Install)
564 endif()
565
566
567 message(STATUS)
568 message(STATUS "Build options, switch LYX_* variables by -DLYX_*=1 or 0:")
569 message(STATUS)
570 LYX_OPTION_LIST_ALL(used)
571
572
573 if(LYX_NLS)
574         message(STATUS)
575         message(STATUS "Building Native Language Support (LYX_NLS is set), used libraries:")
576         message(STATUS)
577         message(STATUS "  * intl")
578         message(STATUS "     - header : ${LIBINTL_HEADER}")
579         message(STATUS "     - library: ${LIBINTL_LIBRARIES}")
580         message(STATUS "  * iconv")
581         message(STATUS "     - header : ${ICONV_HEADER}")
582         message(STATUS "     - library: ${ICONV_LIBRARY}")
583         message(STATUS "  * zlib")
584         message(STATUS "     - header : ${ZLIB_HEADER}")
585         message(STATUS "     - library: ${ZLIB_LIBRARY}")
586         message(STATUS)
587 endif()
588
589
590 # CPack packaging
591 #
592 # http://cmake.org/cmake/help/cmake-2-8-docs.html#module:CPack
593
594 set(CPACK_PACKAGE_VERSION_MAJOR "${LYX_MAJOR_VERSION}")
595 set(CPACK_PACKAGE_VERSION_MINOR "${LYX_MINOR_VERSION}")
596 FILE(STRINGS "${TOP_SRC_DIR}/${LYX_CMAKE_DIR}/LyX_summary.txt" CPACK_PACKAGE_DESCRIPTION_SUMMARY)
597
598 set(CPACK_SOURCE_GENERATOR TGZ ZIP TBZ2)
599 set(CPACK_SOURCE_INSTALLED_DIRECTORIES "${TOP_SRC_DIR};/") # http://www.mail-archive.com/cmake@cmake.org/msg33720.html
600
601 set(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${LYX_INSTALL_SUFFIX}")
602
603 set(CPACK_SOURCE_GENERATOR TGZ ZIP TBZ2)
604 set(CPACK_SOURCE_INSTALLED_DIRECTORIES "${TOP_SRC_DIR};/") # http://www.mail-archive.com/cmake@cmake.org/msg33720.html
605 #
606 # needed by rpm
607 set(CPACK_SET_DESTDIR "ON")
608 FILE(READ "${TOP_SRC_DIR}/${LYX_CMAKE_DIR}/LyX_license.txt" CPACK_RPM_PACKAGE_LICENSE)
609 set(CPACK_RPM_PACKAGE_GROUP "Applications/Publishing")
610 set(CPACK_RPM_PACKAGE_VENDOR "The LyX team")
611 #
612 # the next ones are needed by deb
613 set(CPACK_PACKAGE_CONTACT "${PACKAGE_BUGREPORT}")
614 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${LYX_PROJECT}-${LYX_INSTALL_SUFFIX}")
615
616 # This is experimental, valid on _my_ system (Kornel)
617 set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqtgui4 (>= 4.4.3-0)")
618 if(ASPELL_FOUND)
619         set(CPACK_DEBIAN_PACKAGE_DEPENDS "libaspell15 (>= 0.60.6-1),${CPACK_DEBIAN_PACKAGE_DEPENDS}")
620 endif()
621 if(ENCHANT_FOUND)
622         set(CPACK_DEBIAN_PACKAGE_DEPENDS "libenchant1c2a (>= 1.6.0-0),${CPACK_DEBIAN_PACKAGE_DEPENDS}")
623 endif()
624 if(LYX_EXTERNAL_BOOST)
625         if(Boost_FOUND)
626                 set(CPACK_DEBIAN_PACKAGE_DEPENDS "libboost-regex1.40.0 (>= 1.40.0-4),libboost-signals1.40.0 (>= 1.40.0-4),${CPACK_DEBIAN_PACKAGE_DEPENDS}")
627         endif()
628 endif()
629 #
630 # for the next ones, cpack insists on data with values in some file
631 set(CPACK_PACKAGE_DESCRIPTION_FILE "${TOP_SRC_DIR}/${LYX_CMAKE_DIR}/LyX_description.txt")
632 set(CPACK_RESOURCE_FILE_LICENSE "${TOP_SRC_DIR}/${LYX_CMAKE_DIR}/LyX_license.txt")
633
634 # Find the revision number and use it as the release in rpm-package-build.
635 # This way we may omit the otherwise needed "--force" parameter when
636 # installing from that rpm package.
637 FIND_PROGRAM(LYX_SVNVERSION svnversion)
638 #message(STATUS "svnversion = ${LYX_SVNVERSION}")
639 if(NOT ${LYX_SVNVERSION} MATCHES "-NOTFOUND")
640         EXECUTE_PROCESS(COMMAND ${LYX_SVNVERSION} WORKING_DIRECTORY "${TOP_SRC_DIR}" OUTPUT_VARIABLE CPACK_RPM_PACKAGE_RELEASE OUTPUT_STRIP_TRAILING_WHITESPACE)
641         # We use this value also to set the package-patch-value
642         if(CPACK_RPM_PACKAGE_RELEASE MATCHES "^\([0-9]+\)")
643                 set(CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_1})
644         endif()
645 endif()
646
647 # we do not have a readme or welcome data,
648 # so we do not provide infofiles for
649 # CPACK_RESOURCE_FILE_README and CPACK_RESOURCE_FILE_WELCOME
650
651 if(WIN32)
652         set(CPACK_GENERATOR NSIS ZIP)
653         set(CPACK_BINARY_ZIP 1)
654 endif()
655
656
657 set(CPACK_STRIP_FILES 1)
658
659 # sources
660 set(CPACK_SOURCE_INSTALLED_DIRECTORIES "${TOP_SRC_DIR};/") # http://www.mail-archive.com/cmake@cmake.org/msg33720.html
661 set(CPACK_SOURCE_GENERATOR TGZ ZIP TBZ2)
662
663
664 if(LYX_DMG)
665         set(CPACK_PACKAGE_NAME LyX)
666         set(CPACK_GENERATOR DragNDrop)
667         
668         # We start from bin/lyx.app, all is build into the final bundle folder
669         # On Mac the paths to required shared libraries are hardcoded in the
670         # binary/library. This is fixed by the macro 'fixup_bundle' 
671         # Hardcoded pathes to libraries are resolved automatically
672
673         
674         set(app          ${bundle_dir}/LyX.app)
675         set(contents_dir LyX.app/Contents/)
676         install(DIRECTORY "${QT_PLUGINS_DIR}/imageformats" DESTINATION ${bundle_dir}/${contents_dir}/plugins COMPONENT Runtime)
677         
678         message(STATUS "Qt Plugins: ${QT_PLUGINS_DIR}/imageformats DESTINATION ${bundle_dir}/${contents_dir}/plugins")
679         
680         install(CODE 
681                 "file(GLOB qt_plugins \"${bundle_dir}/${contents_dir}/plugins/imageformats/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
682                 include(BundleUtilities)
683                 fixup_bundle(\"${app}\" \"\${qt_plugins}\" \"${dir}\") "
684                 COMPONENT RUNTIME)
685         
686         file(WRITE ${CMAKE_BINARY_DIR}/qt.conf "")
687         install(FILES ${CMAKE_BINARY_DIR}/qt.conf DESTINATION ${contents_dir}/Resources COMPONENT Runtime)
688         
689 endif()
690
691
692 if(LYX_CPACK)
693         include(CPack)
694 endif()
695
696 #Now it is possible to create some packages
697 # cd <BuildDir>
698 # make package
699 #############################################################################################
700 # So, e.g. for variables
701 #    CMAKE_PROJECT_NAME                     : lyx
702 #    CPACK_PACKAGE_VERSION_MAJOR            : 2
703 #    CPACK_PACKAGE_VERSION_MINOR            : 0
704 #    CPACK_PACKAGE_VERSION_PATCH            : 1
705 #    CMAKE_SYSTEM_NAME                      : Linux
706 #    CPACK_BINARY_DEB:BOOL                  : ON
707 #
708 # the package name builds as "lyx-2.0.1-Linux.deb"
709 #
710 ############################## rpm ################################### deb ##################
711 # create    # cpack -G RPM --config CPackConfig.cmake   # cpack -G DEB --config CPackConfig.cmake
712 # creates =># lyx-2.0.1-Linux.rpm                       # lyx-2.0.1-Linux.deb
713 # list      # rpm -qlp lyx-2.0.1-Linux.rpm              # dpkg-deb -c lyx-2.0.1-Linux.deb
714 # install   # rpm -U lyx-2.0.1-Linux.rpm                # dpkg -i lyx-2.0.1-Linux.deb
715 #
716 message(STATUS)
717
718 endif() #help
719