]> git.lyx.org Git - features.git/blob - development/cmake/ConfigureChecks.cmake
Cmake build: Add needed libraries if using QT5_Extras
[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
76 #check_cxx_source_compiles(
77 #       "
78 #       #include <algorithm>
79 #       using std::count;
80 #       int countChar(char * b, char * e, char const c)
81 #       {
82 #               return count(b, e, c);
83 #       }
84 #       int main(){return 0;}
85 #       "
86 #HAVE_STD_COUNT)
87
88 #check_cxx_source_compiles(
89 #       "
90 #       #include <cctype>
91 #       using std::tolower;
92 #       int main(){return 0;}
93 #       "
94 #CXX_GLOBAL_CSTD)
95
96 check_cxx_source_compiles(
97         "
98         #include <iconv.h>
99         // this declaration will fail when there already exists a non const char** version which returns size_t
100         double iconv(iconv_t cd,  char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
101         int main() { return 0; }
102         "
103 HAVE_ICONV_CONST)
104
105 check_cxx_source_compiles(
106         "
107         int i[ ( sizeof(wchar_t)==2 ? 1 : -1 ) ];
108         int main(){return 0;}
109         "
110 SIZEOF_WCHAR_T_IS_2)
111
112 check_cxx_source_compiles(
113         "
114         int i[ ( sizeof(wchar_t)==4 ? 1 : -1 ) ];
115         int main(){return 0;}
116         "
117 SIZEOF_WCHAR_T_IS_4)
118
119 check_cxx_source_compiles(
120         "
121         int i[ ( sizeof(long long)>sizeof(long) ? 1 : -1 ) ];
122         int main(){return 0;}
123         "
124 SIZEOF_LONG_LONG_GREATER_THAN_SIZEOF_LONG)
125
126 check_cxx_source_compiles(
127         "
128         #include <execinfo.h>
129         #include <cxxabi.h>
130         int main() {
131                 void* array[200];
132                 size_t size = backtrace(array, 200);
133                 backtrace_symbols(array, size);
134                 int status = 0;
135                 abi::__cxa_demangle(\"abcd\", 0, 0, &status);
136         }
137         "
138 LYX_CALLSTACK_PRINTING)
139
140 # Check whether STL is libstdc++
141 check_cxx_source_compiles(
142         "
143         #include <vector>
144         int main() {
145         #if ! defined(__GLIBCXX__) && ! defined(__GLIBCPP__)
146                 this is not libstdc++
147         #endif
148                 return(0);
149         }
150         "
151 lyx_cv_lib_stdcxx)
152
153 # Check whether STL is libstdc++ with C++11 ABI
154 check_cxx_source_compiles(
155         "
156         #include <vector>
157         int main() {
158         #if ! defined(_GLIBCXX_USE_CXX11_ABI) || ! _GLIBCXX_USE_CXX11_ABI
159                 this is not libstdc++ using the C++11 ABI
160         #endif
161                 return(0);
162         }
163         "
164 USE_GLIBCXX_CXX11_ABI)
165
166 check_cxx_source_compiles(
167         "
168         #ifndef __clang__
169                 this is not clang
170         #endif
171         int main() {
172           return(0);
173         }
174         "
175 lyx_cv_prog_clang)
176
177 check_cxx_source_compiles(
178   "
179   #include <memory>
180   using std::make_unique;
181   int main() {
182     return(0);
183   }
184   "
185 HAVE_DEF_MAKE_UNIQUE)
186
187 set(USE_LLVM_LIBCPP)
188 set(STD_STRING_USES_COW)
189 set(USE_GLIBCXX_CXX11_ABI)
190 if(lyx_cv_lib_stdcxx)
191   if(NOT USE_GLIBCXX_CXX11_ABI)
192     set(STD_STRING_USES_COW 1)
193   endif()
194 else()
195   if(lyx_cv_prog_clang)
196     # use libc++ provided by llvm instead of GNU libstdc++
197     set(USE_LLVM_LIBCPP 1)
198   endif()
199 endif()
200
201 set(QPA_XCB)
202 set(HAVE_QT5_X11_EXTRAS)
203 if(LYX_USE_QT MATCHES "QT5")
204
205   set(CMAKE_REQUIRED_INCLUDES ${Qt5Core_INCLUDE_DIRS})
206   set(CMAKE_REQUIRED_FLAGS)
207   #message(STATUS "Qt5Core_INCLUDE_DIRS = ${Qt5Core_INCLUDE_DIRS}")
208   check_cxx_source_runs(
209     "
210     #include <QtCore/qconfig.h>
211     #include <string>
212     using namespace std;
213     string a(QT_QPA_DEFAULT_PLATFORM_NAME);
214     int main(int argc, char **argv)
215     {
216       if (a.compare(\"xcb\") == 0)
217         return(0);
218       else
219         return 1;
220     }
221     "
222     QT_USES_X11)
223   set(QPA_XCB ${QT_USES_X11})
224
225   if (Qt5X11Extras_FOUND)
226     get_target_property(_x11extra_prop Qt5::X11Extras IMPORTED_CONFIGURATIONS)
227     get_target_property(_x11extra_link_libraries Qt5::X11Extras IMPORTED_LOCATION_${_x11extra_prop})
228     set(CMAKE_REQUIRED_LIBRARIES ${_x11extra_link_libraries})
229     set(CMAKE_REQUIRED_INCLUDES ${Qt5X11Extras_INCLUDE_DIRS})
230     set(CMAKE_REQUIRED_FLAGS "${Qt5X11Extras_EXECUTABLE_COMPILE_FLAGS} -fPIC -DQT_NO_VERSION_TAGGING")
231     #message(STATUS "CMAKE_REQUIRED_LIBRARIES = ${_x11extra_link_libraries}")
232     #message(STATUS "CMAKE_REQUIRED_INCLUDES = ${Qt5X11Extras_INCLUDE_DIRS}")
233     #message(STATUS "CMAKE_REQUIRED_FLAGS = ${CMAKE_REQUIRED_FLAGS}")
234     check_cxx_source_compiles(
235             "
236             #include <QtX11Extras/QX11Info>
237             int main()
238             {
239               bool isX11 = QX11Info::isPlatformX11();
240             }
241             "
242       QT_HAS_X11_EXTRAS)
243     set(HAVE_QT5_X11_EXTRAS ${QT_HAS_X11_EXTRAS})
244     set(LYX_QT5_X11_EXTRAS_LIBRARY ${_x11extra_link_libraries})
245   endif()
246   if (Qt5WinExtras_FOUND)
247     get_target_property(_winextra_prop Qt5::WinExtras IMPORTED_CONFIGURATIONS)
248     string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
249     get_target_property(_winextra_link_libraries Qt5::WinExtras IMPORTED_LOCATION_${BUILD_TYPE})
250     set(CMAKE_REQUIRED_LIBRARIES ${_winextra_link_libraries})
251     set(CMAKE_REQUIRED_INCLUDES ${Qt5WinExtras_INCLUDE_DIRS})
252     set(CMAKE_REQUIRED_FLAGS ${Qt5WinExtras_EXECUTABLE_COMPILE_FLAGS})
253   endif()
254 elseif(LYX_USE_QT MATCHES "QT4")
255   set(CMAKE_REQUIRED_LIBRARIES ${QT_QTGUI_LIBRARY})
256   set(CMAKE_REQUIRED_INCLUDES ${QT_INCLUDES})
257   check_cxx_source_compiles(
258           "
259           #include <QtGui/QX11Info>
260           int main()
261           {
262             QX11Info *qxi = new QX11Info;
263             qxi->~QX11Info();
264           }
265           "
266   QT_USES_X11)
267 else()
268   message(FATAL_ERROR "Check for QT_USES_X11: Not handled LYX_USE_QT (= ${LYX_USE_QT})")
269 endif()