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