]> git.lyx.org Git - lyx.git/blob - src/CMakeLists.txt
dc21812c128d984bc8cc5ab61abf6fd82664da7f
[lyx.git] / src / 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 #
6
7 project(${_lyx})
8
9 include_directories(${TOP_SRC_DIR}/src)
10
11 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
12 set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets")
13
14 add_subdirectory(frontends)
15 add_subdirectory(graphics)
16 add_subdirectory(insets)
17 add_subdirectory(mathed)
18 add_subdirectory(support)
19 add_subdirectory(tex2lyx)
20 add_subdirectory(convert)
21 if (UNIX)
22         add_subdirectory(client)
23 endif()
24
25 file(GLOB lyx_sources ${TOP_SRC_DIR}/src/${LYX_CPP_FILES})
26 file(GLOB moc_files ${TOP_SRC_DIR}/src/${LYX_MOC_FILES})
27 list(REMOVE_ITEM  lyx_sources ${moc_files} .)
28 file(GLOB lyx_headers ${TOP_SRC_DIR}/src/${LYX_HPP_FILES})
29 set(lyxwrap_sources ${TOP_SRC_DIR}/src/lyxwrap.cpp)
30
31 list(REMOVE_ITEM lyx_sources
32         ${TOP_SRC_DIR}/src/lyxwrap.cpp
33         ${TOP_SRC_DIR}/src/Variables.cpp
34         ${TOP_SRC_DIR}/src/Section.cpp
35         ${TOP_SRC_DIR}/src/lyxcore.cpp
36         ${TOP_SRC_DIR}/src/lyxinsets.cpp
37         ${TOP_SRC_DIR}/src/lyxmathed.cpp)
38
39 list(REMOVE_ITEM lyx_headers
40         ${TOP_SRC_DIR}/src/Variables.h
41         ${TOP_SRC_DIR}/src/Section.h)
42
43 if(NOT APPLE)
44         list(REMOVE_ITEM lyx_sources ${TOP_SRC_DIR}/src/AppleSpellChecker.cpp)
45         list(REMOVE_ITEM lyx_headers ${TOP_SRC_DIR}/src/AppleSpellChecker.h)
46 endif()
47
48 if(NOT ASPELL_FOUND)
49         list(REMOVE_ITEM lyx_sources ${TOP_SRC_DIR}/src/AspellChecker.cpp)
50         list(REMOVE_ITEM lyx_headers ${TOP_SRC_DIR}/src/AspellChecker.h)
51 else()
52         set(dont_merge ${dont_merge} ${TOP_SRC_DIR}/src/AspellChecker.cpp)
53 endif()
54
55 if(NOT ENCHANT_FOUND)
56         list(REMOVE_ITEM lyx_sources ${TOP_SRC_DIR}/src/EnchantChecker.cpp)
57         list(REMOVE_ITEM lyx_headers ${TOP_SRC_DIR}/src/EnchantChecker.h)
58 else()
59         set(dont_merge ${dont_merge} ${TOP_SRC_DIR}/src/EnchantChecker.cpp)
60 endif()
61
62 if(NOT HUNSPELL_FOUND)
63         list(REMOVE_ITEM lyx_sources ${TOP_SRC_DIR}/src/HunspellChecker.cpp)
64         list(REMOVE_ITEM lyx_headers ${TOP_SRC_DIR}/src/HunspellChecker.h)
65 else()
66         set(dont_merge ${dont_merge} ${TOP_SRC_DIR}/src/HunspellChecker.cpp)
67 endif()
68
69
70 lyx_automoc(${TOP_SRC_DIR}/src/Compare.cpp)
71 if(WIN32)
72         lyx_automoc(${TOP_SRC_DIR}/src/Server.cpp)
73 endif()
74
75 include_directories(${CMAKE_CURRENT_BINARY_DIR}
76         ${ZLIB_INCLUDE_DIR} ${ICONV_INCLUDE_DIR} ${QT_INCLUDES})
77
78 lyx_add_msvc_pch(lyx)
79
80 if (LYX_MERGE_FILES)
81         if(dont_merge)
82                 list(REMOVE_ITEM lyx_sources ${dont_merge})
83         endif()
84         lyx_const_touched_files(_allinone lyx_sources)
85         set(lyx_sources ${_allinone_files} ${dont_merge})
86 endif()
87
88 if (LYX_VLD)
89         configure_file(${vld_path}/vld.ini ${CMAKE_CURRENT_BINARY_DIR}/vld.ini COPYONLY)
90         set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/memory_leak_report.txt PROPERTIES GENERATED TRUE)
91         set(vld_files ${CMAKE_CURRENT_BINARY_DIR}/vld.ini ${CMAKE_CURRENT_BINARY_DIR}/memory_leak_report.txt)
92         lyx_add_info_files(VLD ${vld_files})
93 endif()
94
95 if(WIN32 AND NOT MINGW)
96         set(FILE_RC ${TOP_CMAKE_PATH}/lyx.rc)
97         message(STATUS "Using icon defined in resource file: ${FILE_RC}")
98 endif()
99
100 lyx_find_info_files(LyXInfoFiles ${TOP_SRC_DIR}/*)
101 lyx_find_info_files(LyXCMakeFiles ${TOP_CMAKE_PATH}/*.txt)
102 lyx_find_info_files(LyXCMakeFiles ${TOP_CMAKE_PATH}/*.cmake)
103 lyx_find_info_files(LyXCMakeFiles ${TOP_CMAKE_PATH}/*.h)
104 lyx_find_info_files(LyXCMakeFiles ${TOP_CMAKE_PATH}/*.msvc)
105 lyx_find_info_files(LyXCMakeFiles ${TOP_MODULE_PATH}/*)
106 lyx_find_info_files(LyXCMakeFiles ${TOP_SCRIPT_PATH}/*)
107 lyx_find_info_files(LyXUiFiles ${TOP_SRC_DIR}/lib/ui/*)
108
109 add_executable(${_lyx}
110         ${WIN32_CONSOLE}
111         ${LYX_BUILD_BUNDLE}
112         ${lyx_sources}
113         ${lyx_headers}
114         ${vld_files}
115         ${FILE_RC}
116         ${lyx_info_files}
117         ${lyx_cmake_files}
118         ${OSX_BUNDLE_FILES}
119 )
120
121 add_dependencies(${_lyx} lyx_version)
122
123 set_target_properties(${_lyx} PROPERTIES FOLDER "applications/LyX")
124
125 lyx_add_gcc_pch(${_lyx})
126
127 target_link_libraries(${_lyx}
128         mathed
129         insets
130         frontends
131         frontend_qt
132         graphics
133         support
134         ${MYTHESLIB_LIBRARY}
135         ${ICONV_LIBRARY}
136         ${LYX_QTMAIN_LIBRARY}
137         ${vld_dll})
138
139 qt_use_modules(${_lyx} Core Gui)
140
141 if(QT_USES_X11)
142   find_package(X11 REQUIRED)
143   target_link_libraries(${_lyx} ${X11_X11_LIB}) # we need it because we use XSendEvent
144   if(HAVE_QT5_X11_EXTRAS)
145     find_library(XCB_LIBRARY NAMES xcb)
146     if (XCB_LIBRARY MATCHES "NOTFOUND")
147       message(FATAL_ERROR "Need xcb library to use with QT5_X11_EXTRAS")
148     endif()
149     target_link_libraries(${_lyx} ${LYX_QT5_X11_EXTRAS_LIBRARY} ${XCB_LIBRARY})
150   endif()
151 endif()
152
153 lyx_target_link_libraries(${_lyx} HUNSPELL ASPELL ENCHANT Magic)
154
155 if(APPLE)
156         target_link_libraries(${_lyx} "-bind_at_load")
157         if(LYX_COCOA)
158                 target_link_libraries(${_lyx} "-framework Cocoa")
159         else()
160                 target_link_libraries(${_lyx} "-framework AppKit")
161         endif()
162 endif()
163
164 if(MINGW)
165         target_link_libraries(${_lyx} ole32)
166 endif()
167
168 if(CYGWIN)
169         target_link_libraries(${_lyx} gdi32 shlwapi ole32)
170 endif()
171
172 project_source_group("${GROUP_CODE}" lyx_sources lyx_headers)
173
174 install(TARGETS ${_lyx}
175     BUNDLE DESTINATION . COMPONENT Runtime
176     RUNTIME DESTINATION ${LYX_UTILITIES_INSTALL_PATH} COMPONENT Runtime)
177
178 if(LYX_BUNDLE)
179         if(APPLE)
180                 # Now that lyx executable is defined, we can the files that should be included
181                 # directly in the bundle. Note that resources are not copied with this mechanism:
182                 # only the files necessary to run the executable are processed here (LyX.sdef, LyX.icns, etc.)
183                 list(LENGTH OSX_BUNDLE_FILES OSX_BUNDLE_LAST_INDEX)
184                 math(EXPR OSX_BUNDLE_LAST_INDEX "${OSX_BUNDLE_LAST_INDEX} - 1")
185                 foreach(_i RANGE ${OSX_BUNDLE_LAST_INDEX})
186                     list(GET OSX_BUNDLE_FILES ${_i} _file)
187                     list(GET OSX_BUNDLE_DIRS ${_i} _directory)
188                     # Sets the location of the file into the OS X bundle
189                         set_source_files_properties("${_file}" PROPERTIES MACOSX_PACKAGE_LOCATION "${_directory}")
190                 endforeach()
191
192                 set_target_properties(${_lyx} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_BINARY_DIR}/../Info.plist")
193         endif()
194 endif()
195
196 set(dowrapper ON) # create and install wrapper for external commands
197 foreach(_f ${lyxwrap_sources})
198   if(NOT EXISTS "${_f}")
199     set(dowrapper OFF)
200   endif()
201 endforeach()
202 if(dowrapper AND USE_POSIX_PACKAGING)
203   add_executable(lyxwrap${PROGRAM_SUFFIX} ${lyxwrap_sources})
204   install(TARGETS lyxwrap${PROGRAM_SUFFIX} DESTINATION ${LYX_UTILITIES_INSTALL_PATH})
205 endif()
206
207 add_subdirectory(tests)