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