]> git.lyx.org Git - features.git/blob - development/cmake/ConfigureChecks.cmake
Adapt to new hunspell C++ ABI for cmake
[features.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 # check whether hunspell C++ (rather than C) ABI is provided
76 if(LYX_EXTERNAL_HUNSPELL)
77   set(CMAKE_REQUIRED_INCLUDES ${HUNSPELL_INCLUDE_DIR})
78   set(CMAKE_REQUIRED_LIBRARIES ${HUNSPELL_LIBRARY})
79   check_cxx_source_compiles(
80         "
81         #include <hunspell/hunspell.hxx>
82         int main()
83         {
84                 Hunspell sp(\"foo\", \"bar\");
85                 int i = sp.stem(\"test\").size();
86                 return(0);
87         }
88         "
89   HAVE_HUNSPELL_CXXABI)
90 else()
91   # Not compiling the 3rdparty source, because ${HUNSPELL_LIBRARY} does not exists yet to link with
92   set(HAVE_HUNSPELL_CXXABI 1 CACHE BOOL "whether hunspell C++ (rather than C) ABI is provided")
93 endif()
94
95 #check_cxx_source_compiles(
96 #       "
97 #       #include <algorithm>
98 #       using std::count;
99 #       int countChar(char * b, char * e, char const c)
100 #       {
101 #               return count(b, e, c);
102 #       }
103 #       int main(){return 0;}
104 #       "
105 #HAVE_STD_COUNT)
106
107 #check_cxx_source_compiles(
108 #       "
109 #       #include <cctype>
110 #       using std::tolower;
111 #       int main(){return 0;}
112 #       "
113 #CXX_GLOBAL_CSTD)
114
115 check_cxx_source_compiles(
116         "
117         #include <iconv.h>
118         // this declaration will fail when there already exists a non const char** version which returns size_t
119         double iconv(iconv_t cd,  char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
120         int main() { return 0; }
121         "
122 HAVE_ICONV_CONST)
123
124 check_cxx_source_compiles(
125         "
126         int i[ ( sizeof(wchar_t)==2 ? 1 : -1 ) ];
127         int main(){return 0;}
128         "
129 SIZEOF_WCHAR_T_IS_2)
130
131 check_cxx_source_compiles(
132         "
133         int i[ ( sizeof(wchar_t)==4 ? 1 : -1 ) ];
134         int main(){return 0;}
135         "
136 SIZEOF_WCHAR_T_IS_4)
137
138 check_cxx_source_compiles(
139         "
140         int i[ ( sizeof(long long)>sizeof(long) ? 1 : -1 ) ];
141         int main(){return 0;}
142         "
143 SIZEOF_LONG_LONG_GREATER_THAN_SIZEOF_LONG)
144
145 check_cxx_source_compiles(
146         "
147         #include <execinfo.h>
148         #include <cxxabi.h>
149         int main() {
150                 void* array[200];
151                 size_t size = backtrace(array, 200);
152                 backtrace_symbols(array, size);
153                 int status = 0;
154                 abi::__cxa_demangle(\"abcd\", 0, 0, &status);
155         }
156         "
157 LYX_CALLSTACK_PRINTING)
158
159 # Check whether STL is libstdc++
160 check_cxx_source_compiles(
161         "
162         #include <vector>
163         int main() {
164         #if ! defined(__GLIBCXX__) && ! defined(__GLIBCPP__)
165                 this is not libstdc++
166         #endif
167                 return(0);
168         }
169         "
170 lyx_cv_lib_stdcxx)
171
172 # Check whether STL is libstdc++ with C++11 ABI
173 check_cxx_source_compiles(
174         "
175         #include <vector>
176         int main() {
177         #if ! defined(_GLIBCXX_USE_CXX11_ABI) || ! _GLIBCXX_USE_CXX11_ABI
178                 this is not libstdc++ using the C++11 ABI
179         #endif
180                 return(0);
181         }
182         "
183 USE_GLIBCXX_CXX11_ABI)
184
185 check_cxx_source_compiles(
186         "
187         #ifndef __clang__
188                 this is not clang
189         #endif
190         int main() {
191           return(0);
192         }
193         "
194 lyx_cv_prog_clang)
195
196 check_cxx_source_compiles(
197   "
198   #include <memory>
199   using std::make_unique;
200   int main() {
201     return(0);
202   }
203   "
204 HAVE_DEF_MAKE_UNIQUE)
205
206 check_cxx_source_compiles(
207   "
208   #include <mutex>
209   static std::once_flag flag;
210   int main() {
211     std::call_once(flag, [](){ return; });
212     return(0);
213   }
214   "
215 LYX_USE_STD_CALL_ONCE)
216
217 if (ENCHANT_FOUND)
218   set(CMAKE_REQUIRED_INCLUDES ${ENCHANT_INCLUDE_DIR})
219   set(CMAKE_REQUIRED_LIBRARIES ${ENCHANT_LIBRARY})
220   # Check, whether enchant is version 2.x at least
221   check_cxx_source_compiles(
222     "
223     #include <enchant++.h>
224     enchant::Broker broker;
225     int main() {
226       return(0);
227     }
228     "
229   HAVE_ENCHANT2)
230   if (HAVE_ENCHANT2)
231     message(STATUS "ENCHANT2 found")
232   endif()
233 endif()
234
235 set(USE_LLVM_LIBCPP)
236 set(STD_STRING_USES_COW)
237 set(USE_GLIBCXX_CXX11_ABI)
238 if(lyx_cv_lib_stdcxx)
239   if(NOT USE_GLIBCXX_CXX11_ABI)
240     set(STD_STRING_USES_COW 1)
241   endif()
242 else()
243   if(lyx_cv_prog_clang)
244     # use libc++ provided by llvm instead of GNU libstdc++
245     set(USE_LLVM_LIBCPP 1)
246   endif()
247 endif()
248
249 set(QPA_XCB)
250 set(HAVE_QT5_X11_EXTRAS)
251 if(LYX_USE_QT MATCHES "QT5")
252
253   set(CMAKE_REQUIRED_INCLUDES ${Qt5Core_INCLUDE_DIRS})
254   set(CMAKE_REQUIRED_FLAGS)
255   #message(STATUS "Qt5Core_INCLUDE_DIRS = ${Qt5Core_INCLUDE_DIRS}")
256   check_include_file_cxx(QtGui/qtgui-config.h HAVE_QTGUI_CONFIG_H)
257   if (HAVE_QTGUI_CONFIG_H)
258     set(lyx_qt5_config "QtGui/qtgui-config.h")
259   else()
260     set(lyx_qt5_config "QtCore/qconfig.h")
261   endif()
262   if(WIN32)
263     set(QT_USES_X11 CACHE "Win32 compiled without X11" 0)
264     # The try_run for minngw would not work here anyway
265   else()
266     check_cxx_source_runs(
267       "
268       #include <${lyx_qt5_config}>
269       #include <string>
270       using namespace std;
271       string a(QT_QPA_DEFAULT_PLATFORM_NAME);
272       int main(int argc, char **argv)
273       {
274         if (a.compare(\"xcb\") == 0)
275           return(0);
276         else
277           return 1;
278       }
279       "
280       QT_USES_X11)
281     if(QT_USES_X11)
282       set(QPA_XCB ${QT_USES_X11})
283     endif()
284   endif()
285
286   if (Qt5X11Extras_FOUND)
287     get_target_property(_x11extra_prop Qt5::X11Extras IMPORTED_CONFIGURATIONS)
288     get_target_property(_x11extra_link_libraries Qt5::X11Extras IMPORTED_LOCATION_${_x11extra_prop})
289     set(CMAKE_REQUIRED_LIBRARIES ${_x11extra_link_libraries})
290     set(CMAKE_REQUIRED_INCLUDES ${Qt5X11Extras_INCLUDE_DIRS})
291     set(CMAKE_REQUIRED_FLAGS "${Qt5X11Extras_EXECUTABLE_COMPILE_FLAGS} -fPIC -DQT_NO_VERSION_TAGGING")
292     #message(STATUS "CMAKE_REQUIRED_LIBRARIES = ${_x11extra_link_libraries}")
293     #message(STATUS "CMAKE_REQUIRED_INCLUDES = ${Qt5X11Extras_INCLUDE_DIRS}")
294     #message(STATUS "CMAKE_REQUIRED_FLAGS = ${CMAKE_REQUIRED_FLAGS}")
295     check_cxx_source_compiles(
296             "
297             #include <QtX11Extras/QX11Info>
298             int main()
299             {
300               bool isX11 = QX11Info::isPlatformX11();
301             }
302             "
303       QT_HAS_X11_EXTRAS)
304     set(HAVE_QT5_X11_EXTRAS ${QT_HAS_X11_EXTRAS})
305     set(LYX_QT5_X11_EXTRAS_LIBRARY ${_x11extra_link_libraries})
306   endif()
307   if (Qt5WinExtras_FOUND)
308     get_target_property(_winextra_prop Qt5::WinExtras IMPORTED_CONFIGURATIONS)
309     string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
310     get_target_property(_winextra_link_libraries Qt5::WinExtras IMPORTED_LOCATION_${BUILD_TYPE})
311     set(CMAKE_REQUIRED_LIBRARIES ${_winextra_link_libraries})
312     set(CMAKE_REQUIRED_INCLUDES ${Qt5WinExtras_INCLUDE_DIRS})
313     set(CMAKE_REQUIRED_FLAGS ${Qt5WinExtras_EXECUTABLE_COMPILE_FLAGS})
314   endif()
315 elseif(LYX_USE_QT MATCHES "QT4")
316   set(CMAKE_REQUIRED_LIBRARIES ${QT_QTGUI_LIBRARY})
317   set(CMAKE_REQUIRED_INCLUDES ${QT_INCLUDES})
318   check_cxx_source_compiles(
319           "
320           #include <QtGui/QX11Info>
321           int main()
322           {
323             QX11Info *qxi = new QX11Info;
324             qxi->~QX11Info();
325           }
326           "
327   QT_USES_X11)
328 else()
329   message(FATAL_ERROR "Check for QT_USES_X11: Not handled LYX_USE_QT (= ${LYX_USE_QT})")
330 endif()