]> git.lyx.org Git - lyx.git/blob - development/cmake/ConfigureChecks.cmake
Position better the cursor after math-display
[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(MacroBoolTo01)
16 include(TestBigEndian)
17
18 test_big_endian(WORDS_BIGENDIAN)
19
20 #check_include_file_cxx(istream HAVE_ISTREAM)
21 #check_include_file_cxx(ostream HAVE_OSTREAM)
22 #check_include_file_cxx(sstream HAVE_SSTREAM)
23 #check_include_file_cxx(ios HAVE_IOS)
24 #check_include_file_cxx(locale HAVE_LOCALE)
25
26 # defines will be written to configIncludes.h
27 set(Include_Defines)
28 foreach(_h_file aspell.h aspell/aspell.h limits.h locale.h
29         stdlib.h sys/stat.h sys/time.h sys/types.h sys/utime.h
30         sys/socket.h unistd.h inttypes.h utime.h string.h argz.h)
31         string(REGEX REPLACE "[/\\.]" "_" _hf ${_h_file})
32         string(TOUPPER ${_hf} _HF)
33         check_include_files(${_h_file} HAVE_${_HF})
34         set(Include_Defines "${Include_Defines}#cmakedefine HAVE_${_HF} 1\n")
35 endforeach()
36 configure_file(${LYX_CMAKE_DIR}/configIncludes.cmake ${TOP_BINARY_DIR}/configIncludes.h.cmake)
37 configure_file(${TOP_BINARY_DIR}/configIncludes.h.cmake ${TOP_BINARY_DIR}/configIncludes.h)
38
39 # defines will be written to configFunctions.h
40 set(Function_Defines)
41 foreach(_f alloca __argz_count __argz_next __argz_stringify
42         chmod close _close dcgettext fcntl fork __fsetlocking
43         getcwd getegid getgid getpid _getpid gettext getuid lstat lockf mempcpy mkdir _mkdir
44         mkfifo open _open pclose _pclose popen _popen putenv readlink
45         setenv setlocale strcasecmp stpcpy strdup strerror strtoul tsearch unsetenv wcslen)
46   string(TOUPPER ${_f} _UF)
47   check_function_exists(${_f} HAVE_${_UF})
48   set(Function_Defines "${Function_Defines}#cmakedefine HAVE_${_UF} 1\n")
49 endforeach()
50 configure_file(${LYX_CMAKE_DIR}/configFunctions.cmake ${TOP_BINARY_DIR}/configFunctions.h.cmake)
51 configure_file(${TOP_BINARY_DIR}/configFunctions.h.cmake ${TOP_BINARY_DIR}/configFunctions.h)
52
53 check_symbol_exists(alloca "malloc.h" HAVE_SYMBOL_ALLOCA)
54 check_symbol_exists(asprintf "stdio.h" HAVE_ASPRINTF)
55 check_symbol_exists(wprintf "stdio.h" HAVE_WPRINTF)
56 check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF)
57 check_symbol_exists(printf "stdio.h" HAVE_POSIX_PRINTF)
58 check_symbol_exists(pid_t "sys/types.h" HAVE_PID_T)
59 check_symbol_exists(intmax_t "inttypes.h" HAVE_INTTYPES_H_WITH_UINTMAX)
60 check_symbol_exists(uintmax_t "stdint.h" HAVE_STDINT_H_WITH_UINTMAX)
61 check_symbol_exists(LC_MESSAGES "locale.h" HAVE_LC_MESSAGES)
62
63 check_type_size(intmax_t HAVE_INTMAX_T)
64 macro_bool_to_01(HAVE_UINTMAX_T HAVE_STDINT_H_WITH_UINTMAX)
65
66 check_type_size("long double"  HAVE_LONG_DOUBLE)
67 check_type_size("long long"  HAVE_LONG_LONG)
68 check_type_size(wchar_t HAVE_WCHAR_T)
69 check_type_size(wint_t  HAVE_WINT_T)
70
71
72 #check_cxx_source_compiles(
73 #       "
74 #       #include <algorithm>
75 #       using std::count;
76 #       int countChar(char * b, char * e, char const c)
77 #       {
78 #               return count(b, e, c);
79 #       }
80 #       int main(){return 0;}
81 #       "
82 #HAVE_STD_COUNT)
83
84 #check_cxx_source_compiles(
85 #       "
86 #       #include <cctype>
87 #       using std::tolower;
88 #       int main(){return 0;}
89 #       "
90 #CXX_GLOBAL_CSTD)
91
92 check_cxx_source_compiles(
93         "
94         #include <iconv.h>
95         // this declaration will fail when there already exists a non const char** version which returns size_t
96         double iconv(iconv_t cd,  char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
97         int main() { return 0; }
98         "
99 HAVE_ICONV_CONST)
100
101 check_cxx_source_compiles(
102         "
103         int i[ ( sizeof(wchar_t)==2 ? 1 : -1 ) ];
104         int main(){return 0;}
105         "
106 SIZEOF_WCHAR_T_IS_2)
107
108 check_cxx_source_compiles(
109         "
110         int i[ ( sizeof(wchar_t)==4 ? 1 : -1 ) ];
111         int main(){return 0;}
112         "
113 SIZEOF_WCHAR_T_IS_4)
114
115 check_cxx_source_compiles(
116         "
117         #include <execinfo.h>
118         #include <cxxabi.h>
119         int main() {
120                 void* array[200];
121                 size_t size = backtrace(array, 200);
122                 backtrace_symbols(array, size);
123                 int status = 0;
124                 abi::__cxa_demangle(\"abcd\", 0, 0, &status);
125         }
126         "
127 LYX_CALLSTACK_PRINTING)
128
129 # Check whether STL is libstdc++
130 check_cxx_source_compiles(
131         "
132         #include <vector>
133         int main() {
134         #if ! defined(__GLIBCXX__) && ! defined(__GLIBCPP__)
135                 this is not libstdc++
136         #endif
137                 return(0);
138         }
139         "
140 lyx_cv_lib_stdcxx)
141
142 # Check whether STL is libstdc++ with C++11 ABI
143 check_cxx_source_compiles(
144         "
145         #include <vector>
146         int main() {
147         #if ! defined(_GLIBCXX_USE_CXX11_ABI) || ! _GLIBCXX_USE_CXX11_ABI
148                 this is not libstdc++ using the C++11 ABI
149         #endif
150                 return(0);
151         }
152         "
153 USE_GLIBCXX_CXX11_ABI)
154
155 check_cxx_source_compiles(
156         "
157         #ifndef __clang__
158                 this is not clang
159         #endif
160         int main() {
161           return(0);
162         }
163         "
164 lyx_cv_prog_clang)
165
166 set(USE_LLVM_LIBCPP)
167 set(STD_STRING_USES_COW)
168 set(USE_GLIBCXX_CXX11_ABI)
169 if(lyx_cv_lib_stdcxx)
170   if(NOT USE_GLIBCXX_CXX11_ABI)
171     set(STD_STRING_USES_COW 1)
172   endif()
173 else()
174   if(lyx_cv_prog_clang)
175     # use libc++ provided by llvm instead of GNU libstdc++
176     set(USE_LLVM_LIBCPP 1)
177   endif()
178 endif()
179
180 if(LYX_USE_QT MATCHES "QT5")
181   if (Qt5X11Extras_FOUND)
182     get_target_property(_x11extra_prop Qt5::X11Extras IMPORTED_CONFIGURATIONS)
183     get_target_property(_x11extra_link_libraries Qt5::X11Extras IMPORTED_LOCATION_${_x11extra_prop})
184     set(CMAKE_REQUIRED_LIBRARIES ${_x11extra_link_libraries})
185     set(CMAKE_REQUIRED_INCLUDES ${Qt5X11Extras_INCLUDE_DIRS})
186     set(CMAKE_REQUIRED_FLAGS ${Qt5X11Extras_EXECUTABLE_COMPILE_FLAGS})
187     check_cxx_source_compiles(
188             "
189             #include <QtX11Extras/QX11Info>
190             int main()
191             {
192               bool isX11 = QX11Info::isPlatformX11();
193             }
194             "
195     QT_USES_X11)
196   endif()
197   if (Qt5WinExtras_FOUND)
198     get_target_property(_winextra_prop Qt5::WinExtras IMPORTED_CONFIGURATIONS)
199     get_target_property(_winextra_link_libraries Qt5::WinExtras IMPORTED_LOCATION_${_winextra_prop})
200     set(CMAKE_REQUIRED_LIBRARIES ${_winextra_link_libraries})
201     set(CMAKE_REQUIRED_INCLUDES ${Qt5WinExtras_INCLUDE_DIRS})
202     set(CMAKE_REQUIRED_FLAGS ${Qt5WinExtras_EXECUTABLE_COMPILE_FLAGS})
203   endif()
204 elseif(LYX_USE_QT MATCHES "QT4")
205   set(CMAKE_REQUIRED_LIBRARIES ${QT_QTGUI_LIBRARY})
206   set(CMAKE_REQUIRED_INCLUDES ${QT_INCLUDES})
207   check_cxx_source_compiles(
208           "
209           #include <QtGui/QX11Info>
210           int main()
211           {
212             QX11Info *qxi = new QX11Info;
213             qxi->~QX11Info();
214           }
215           "
216   QT_USES_X11)
217 else()
218   message(FATAL_ERROR "Check for QT_USES_X11: Not handled LYX_USE_QT (= ${LYX_USE_QT})")
219 endif()
220