]> git.lyx.org Git - lyx.git/blob - development/cmake/ConfigureChecks.cmake
Allow for cite engine and format definitions/modifications in layouts
[lyx.git] / development / cmake / ConfigureChecks.cmake
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, Peter Kümmel, <syntheticpp@gmx.net>
5 #
6
7 include(CheckIncludeFile)
8 include(CheckIncludeFileCXX)
9 include(CheckIncludeFiles)
10 include(CheckSymbolExists)
11 include(CheckFunctionExists)
12 include(CheckLibraryExists)
13 include(CheckTypeSize)
14 include(CheckCXXSourceCompiles)
15 include(CheckCXXSourceRuns)
16 include(MacroBoolTo01)
17 include(TestBigEndian)
18
19 test_big_endian(WORDS_BIGENDIAN)
20
21 #check_include_file_cxx(istream HAVE_ISTREAM)
22 #check_include_file_cxx(ostream HAVE_OSTREAM)
23 #check_include_file_cxx(sstream HAVE_SSTREAM)
24 #check_include_file_cxx(ios HAVE_IOS)
25 #check_include_file_cxx(locale HAVE_LOCALE)
26
27 # defines will be written to configIncludes.h
28 set(Include_Defines)
29 foreach(_h_file aspell.h aspell/aspell.h limits.h locale.h
30         stdlib.h sys/stat.h sys/time.h sys/types.h sys/utime.h
31         sys/socket.h unistd.h inttypes.h utime.h string.h argz.h)
32         string(REGEX REPLACE "[/\\.]" "_" _hf ${_h_file})
33         string(TOUPPER ${_hf} _HF)
34         check_include_files(${_h_file} HAVE_${_HF})
35         set(Include_Defines "${Include_Defines}#cmakedefine HAVE_${_HF} 1\n")
36 endforeach()
37 check_include_file_cxx(regex HAVE_REGEX)
38 set(Include_Defines "${Include_Defines}#cmakedefine HAVE_REGEX 1\n")
39 configure_file(${LYX_CMAKE_DIR}/configIncludes.cmake ${TOP_BINARY_DIR}/configIncludes.h.cmake)
40 configure_file(${TOP_BINARY_DIR}/configIncludes.h.cmake ${TOP_BINARY_DIR}/configIncludes.h)
41
42 # defines will be written to configFunctions.h
43 set(Function_Defines)
44 foreach(_f alloca __argz_count __argz_next __argz_stringify
45         chmod close _close dcgettext fcntl fork __fsetlocking
46         getcwd getegid getgid getpid _getpid gettext getuid lstat lockf mempcpy mkdir _mkdir
47         mkfifo open _open pclose _pclose popen _popen putenv readlink
48         setenv setlocale strcasecmp stpcpy strdup strerror strtoul tsearch unsetenv wcslen)
49   string(TOUPPER ${_f} _UF)
50   check_function_exists(${_f} HAVE_${_UF})
51   set(Function_Defines "${Function_Defines}#cmakedefine HAVE_${_UF} 1\n")
52 endforeach()
53 configure_file(${LYX_CMAKE_DIR}/configFunctions.cmake ${TOP_BINARY_DIR}/configFunctions.h.cmake)
54 configure_file(${TOP_BINARY_DIR}/configFunctions.h.cmake ${TOP_BINARY_DIR}/configFunctions.h)
55
56 check_symbol_exists(alloca "malloc.h" HAVE_SYMBOL_ALLOCA)
57 check_symbol_exists(asprintf "stdio.h" HAVE_ASPRINTF)
58 check_symbol_exists(wprintf "stdio.h" HAVE_WPRINTF)
59 check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF)
60 check_symbol_exists(printf "stdio.h" HAVE_POSIX_PRINTF)
61 check_symbol_exists(pid_t "sys/types.h" HAVE_PID_T)
62 check_symbol_exists(intmax_t "inttypes.h" HAVE_INTTYPES_H_WITH_UINTMAX)
63 check_symbol_exists(uintmax_t "stdint.h" HAVE_STDINT_H_WITH_UINTMAX)
64 check_symbol_exists(LC_MESSAGES "locale.h" HAVE_LC_MESSAGES)
65 check_symbol_exists(PATH_MAX "limits.h" HAVE_DEF_PATH_MAX)
66
67 check_type_size(intmax_t HAVE_INTMAX_T)
68 macro_bool_to_01(HAVE_UINTMAX_T HAVE_STDINT_H_WITH_UINTMAX)
69
70 check_type_size("long double"  HAVE_LONG_DOUBLE)
71 check_type_size("long long"  HAVE_LONG_LONG)
72 check_type_size(wchar_t HAVE_WCHAR_T)
73 check_type_size(wint_t  HAVE_WINT_T)
74
75 if(HUNSPELL_FOUND)
76   # check whether hunspell C++ (rather than C) ABI is provided
77   set(HunspellTestFile "${CMAKE_BINARY_DIR}/hunspelltest.cpp")
78   file(WRITE "${HunspellTestFile}"
79   "
80   #include <hunspell/hunspell.hxx>
81
82   int main()
83   {
84     Hunspell sp(\"foo\", \"bar\");
85     int i = sp.stem(\"test\").size();
86   return(0);
87   }
88   "
89   )
90
91   try_compile(HAVE_HUNSPELL_CXXABI
92     "${CMAKE_BINARY_DIR}"
93     "${HunspellTestFile}"
94     CMAKE_FLAGS
95       "-DINCLUDE_DIRECTORIES:STRING=${HUNSPELL_INCLUDE_DIR}"
96       "-DCMAKE_CXX_LINK_EXECUTABLE='${CMAKE_COMMAD} echo not linking now...'"
97   OUTPUT_VARIABLE  LOG2)
98
99   message(STATUS "HAVE_HUNSPELL_CXXABI = ${HAVE_HUNSPELL_CXXABI}")
100   #message(STATUS "LOG2 = ${LOG2}")
101   if(LYX_EXTERNAL_HUNSPELL AND LYX_STDLIB_DEBUG AND HAVE_HUNSPELL_CXXABI)
102     message(WARNING "Compiling LyX with stdlib-debug and system hunspell libraries may lead to crashes. Consider using -DLYX_STDLIB_DEBUG=OFF or -DLYX_EXTERNAL_HUNSPELL=OFF.")
103   endif()
104 endif()
105
106 #check_cxx_source_compiles(
107 #       "
108 #       #include <algorithm>
109 #       using std::count;
110 #       int countChar(char * b, char * e, char const c)
111 #       {
112 #               return count(b, e, c);
113 #       }
114 #       int main(){return 0;}
115 #       "
116 #HAVE_STD_COUNT)
117
118 #check_cxx_source_compiles(
119 #       "
120 #       #include <cctype>
121 #       using std::tolower;
122 #       int main(){return 0;}
123 #       "
124 #CXX_GLOBAL_CSTD)
125
126 check_cxx_source_compiles(
127         "
128         #include <iconv.h>
129         // this declaration will fail when there already exists a non const char** version which returns size_t
130         double iconv(iconv_t cd,  char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
131         int main() { return 0; }
132         "
133 HAVE_ICONV_CONST)
134
135 check_cxx_source_compiles(
136         "
137         int i[ ( sizeof(wchar_t)==2 ? 1 : -1 ) ];
138         int main(){return 0;}
139         "
140 SIZEOF_WCHAR_T_IS_2)
141
142 check_cxx_source_compiles(
143         "
144         int i[ ( sizeof(wchar_t)==4 ? 1 : -1 ) ];
145         int main(){return 0;}
146         "
147 SIZEOF_WCHAR_T_IS_4)
148
149 check_cxx_source_compiles(
150         "
151         int i[ ( sizeof(long long)>sizeof(long) ? 1 : -1 ) ];
152         int main(){return 0;}
153         "
154 SIZEOF_LONG_LONG_GREATER_THAN_SIZEOF_LONG)
155
156 check_cxx_source_compiles(
157         "
158         #include <execinfo.h>
159         #include <cxxabi.h>
160         int main() {
161                 void* array[200];
162                 size_t size = backtrace(array, 200);
163                 backtrace_symbols(array, size);
164                 int status = 0;
165                 abi::__cxa_demangle(\"abcd\", 0, 0, &status);
166         }
167         "
168 LYX_CALLSTACK_PRINTING)
169
170 # Check whether STL is libstdc++
171 check_cxx_source_compiles(
172         "
173         #include <vector>
174         int main() {
175         #if ! defined(__GLIBCXX__) && ! defined(__GLIBCPP__)
176                 this is not libstdc++
177         #endif
178                 return(0);
179         }
180         "
181 lyx_cv_lib_stdcxx)
182
183 # Check whether STL is libstdc++ with C++11 ABI
184 check_cxx_source_compiles(
185         "
186         #include <vector>
187         int main() {
188         #if ! defined(_GLIBCXX_USE_CXX11_ABI) || ! _GLIBCXX_USE_CXX11_ABI
189                 this is not libstdc++ using the C++11 ABI
190         #endif
191                 return(0);
192         }
193         "
194 USE_GLIBCXX_CXX11_ABI)
195
196 check_cxx_source_compiles(
197         "
198         #ifndef __clang__
199                 this is not clang
200         #endif
201         int main() {
202           return(0);
203         }
204         "
205 lyx_cv_prog_clang)
206
207 check_cxx_source_compiles(
208   "
209   #include <memory>
210   using std::make_unique;
211   int main() {
212     return(0);
213   }
214   "
215 HAVE_DEF_MAKE_UNIQUE)
216
217 check_cxx_source_compiles(
218   "
219   #include <mutex>
220   static std::once_flag flag;
221   int main() {
222     std::call_once(flag, [](){ return; });
223     return(0);
224   }
225   "
226 LYX_USE_STD_CALL_ONCE)
227
228 if (ENCHANT_FOUND)
229   set(CMAKE_REQUIRED_INCLUDES ${ENCHANT_INCLUDE_DIR})
230   set(CMAKE_REQUIRED_LIBRARIES ${ENCHANT_LIBRARY})
231   # Check, whether enchant is version 2.x at least
232   check_cxx_source_compiles(
233     "
234     #include <enchant++.h>
235     enchant::Broker broker;
236     int main() {
237       return(0);
238     }
239     "
240   HAVE_ENCHANT2)
241   if (HAVE_ENCHANT2)
242     message(STATUS "ENCHANT2 found")
243   endif()
244 endif()
245
246 set(USE_LLVM_LIBCPP)
247 set(STD_STRING_USES_COW)
248 set(USE_GLIBCXX_CXX11_ABI)
249 if(lyx_cv_lib_stdcxx)
250   if(NOT USE_GLIBCXX_CXX11_ABI)
251     set(STD_STRING_USES_COW 1)
252   endif()
253 else()
254   if(lyx_cv_prog_clang)
255     # use libc++ provided by llvm instead of GNU libstdc++
256     set(USE_LLVM_LIBCPP 1)
257   endif()
258 endif()
259
260 set(QPA_XCB)
261 set(HAVE_QT5_X11_EXTRAS)
262 if(LYX_USE_QT MATCHES "QT5")
263
264   set(CMAKE_REQUIRED_INCLUDES ${Qt5Core_INCLUDE_DIRS})
265   set(CMAKE_REQUIRED_FLAGS)
266   #message(STATUS "Qt5Core_INCLUDE_DIRS = ${Qt5Core_INCLUDE_DIRS}")
267   check_include_file_cxx(QtGui/qtgui-config.h HAVE_QTGUI_CONFIG_H)
268   if (HAVE_QTGUI_CONFIG_H)
269     set(lyx_qt5_config "QtGui/qtgui-config.h")
270   else()
271     set(lyx_qt5_config "QtCore/qconfig.h")
272   endif()
273   if(WIN32)
274     set(QT_USES_X11 CACHE "Win32 compiled without X11" 0)
275     # The try_run for minngw would not work here anyway
276   else()
277     check_cxx_source_runs(
278       "
279       #include <${lyx_qt5_config}>
280       #include <string>
281       using namespace std;
282       string a(QT_QPA_DEFAULT_PLATFORM_NAME);
283       int main(int argc, char **argv)
284       {
285         if (a.compare(\"xcb\") == 0)
286           return(0);
287         else
288           return 1;
289       }
290       "
291       QT_USES_X11)
292     if(QT_USES_X11)
293       set(QPA_XCB ${QT_USES_X11})
294     endif()
295   endif()
296
297   if (Qt5X11Extras_FOUND)
298     get_target_property(_x11extra_prop Qt5::X11Extras IMPORTED_CONFIGURATIONS)
299     get_target_property(_x11extra_link_libraries Qt5::X11Extras IMPORTED_LOCATION_${_x11extra_prop})
300     set(CMAKE_REQUIRED_LIBRARIES ${_x11extra_link_libraries})
301     set(CMAKE_REQUIRED_INCLUDES ${Qt5X11Extras_INCLUDE_DIRS})
302     set(CMAKE_REQUIRED_FLAGS "${Qt5X11Extras_EXECUTABLE_COMPILE_FLAGS} -fPIC -DQT_NO_VERSION_TAGGING")
303     #message(STATUS "CMAKE_REQUIRED_LIBRARIES = ${_x11extra_link_libraries}")
304     #message(STATUS "CMAKE_REQUIRED_INCLUDES = ${Qt5X11Extras_INCLUDE_DIRS}")
305     #message(STATUS "CMAKE_REQUIRED_FLAGS = ${CMAKE_REQUIRED_FLAGS}")
306     check_cxx_source_compiles(
307             "
308             #include <QtX11Extras/QX11Info>
309             int main()
310             {
311               bool isX11 = QX11Info::isPlatformX11();
312             }
313             "
314       QT_HAS_X11_EXTRAS)
315     set(HAVE_QT5_X11_EXTRAS ${QT_HAS_X11_EXTRAS})
316     set(LYX_QT5_X11_EXTRAS_LIBRARY ${_x11extra_link_libraries})
317   endif()
318   if (Qt5WinExtras_FOUND)
319     get_target_property(_winextra_prop Qt5::WinExtras IMPORTED_CONFIGURATIONS)
320     string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
321     get_target_property(_winextra_link_libraries Qt5::WinExtras IMPORTED_LOCATION_${BUILD_TYPE})
322     set(CMAKE_REQUIRED_LIBRARIES ${_winextra_link_libraries})
323     set(CMAKE_REQUIRED_INCLUDES ${Qt5WinExtras_INCLUDE_DIRS})
324     set(CMAKE_REQUIRED_FLAGS ${Qt5WinExtras_EXECUTABLE_COMPILE_FLAGS})
325   endif()
326 elseif(LYX_USE_QT MATCHES "QT4")
327   set(CMAKE_REQUIRED_LIBRARIES ${QT_QTGUI_LIBRARY})
328   set(CMAKE_REQUIRED_INCLUDES ${QT_INCLUDES})
329   check_cxx_source_compiles(
330           "
331           #include <QtGui/QX11Info>
332           int main()
333           {
334             QX11Info *qxi = new QX11Info;
335             qxi->~QX11Info();
336           }
337           "
338   QT_USES_X11)
339 else()
340   message(FATAL_ERROR "Check for QT_USES_X11: Not handled LYX_USE_QT (= ${LYX_USE_QT})")
341 endif()