2006-09-15 17:05:20 +00:00
# This file is part of LyX, the document processor.
# Licence details can be found in the file COPYING.
#
# Copyright (c) 2006, Peter K<> mmel, <syntheticpp@gmx.net>
#
2006-06-11 11:57:25 +00:00
include ( CheckIncludeFile )
include ( CheckIncludeFileCXX )
include ( CheckIncludeFiles )
include ( CheckSymbolExists )
include ( CheckFunctionExists )
include ( CheckLibraryExists )
include ( CheckTypeSize )
include ( CheckCXXSourceCompiles )
2016-07-10 17:31:32 +00:00
include ( CheckCXXSourceRuns )
2008-04-20 11:06:08 +00:00
include ( MacroBoolTo01 )
2008-09-20 19:43:52 +00:00
include ( TestBigEndian )
2006-06-11 11:57:25 +00:00
2008-09-20 19:43:52 +00:00
test_big_endian ( WORDS_BIGENDIAN )
2006-06-11 11:57:25 +00:00
2007-08-23 21:18:53 +00:00
#check_include_file_cxx(istream HAVE_ISTREAM)
#check_include_file_cxx(ostream HAVE_OSTREAM)
#check_include_file_cxx(sstream HAVE_SSTREAM)
2013-02-12 18:01:16 +00:00
#check_include_file_cxx(ios HAVE_IOS)
2007-08-23 21:18:53 +00:00
#check_include_file_cxx(locale HAVE_LOCALE)
2006-06-11 11:57:25 +00:00
2013-02-12 18:01:16 +00:00
# defines will be written to configIncludes.h
set ( Include_Defines )
foreach ( _h_file aspell.h aspell/aspell.h limits.h locale.h
s t d l i b . h s y s / s t a t . h s y s / t i m e . h s y s / t y p e s . h s y s / u t i m e . h
2024-08-29 09:15:26 +00:00
s y s / s o c k e t . h u n i s t d . h i n t t y p e s . h u t i m e . h s t r i n g . h a r g z . h x c b / x c b . h )
2013-02-12 18:01:16 +00:00
string ( REGEX REPLACE "[/\\.]" "_" _hf ${ _h_file } )
string ( TOUPPER ${ _hf } _HF )
check_include_files ( ${ _h_file } HAVE_ ${ _HF } )
set ( Include_Defines "${Include_Defines}#cmakedefine HAVE_${_HF} 1\n" )
endforeach ( )
2015-12-06 19:04:21 +00:00
check_include_file_cxx ( regex HAVE_REGEX )
set ( Include_Defines "${Include_Defines}#cmakedefine HAVE_REGEX 1\n" )
2013-02-12 18:01:16 +00:00
configure_file ( ${ LYX_CMAKE_DIR } /configIncludes.cmake ${ TOP_BINARY_DIR } /configIncludes.h.cmake )
configure_file ( ${ TOP_BINARY_DIR } /configIncludes.h.cmake ${ TOP_BINARY_DIR } /configIncludes.h )
2006-06-11 11:57:25 +00:00
2013-02-12 18:01:16 +00:00
# defines will be written to configFunctions.h
2013-02-12 16:22:07 +00:00
set ( Function_Defines )
2013-02-12 14:27:39 +00:00
foreach ( _f alloca __argz_count __argz_next __argz_stringify
c h m o d c l o s e _ c l o s e d c g e t t e x t f c n t l f o r k _ _ f s e t l o c k i n g
2013-11-20 18:40:32 +00:00
g e t c w d g e t e g i d g e t g i d g e t p i d _ g e t p i d g e t t e x t g e t u i d l s t a t l o c k f m e m p c p y m k d i r _ m k d i r
2013-02-12 14:27:39 +00:00
m k f i f o o p e n _ o p e n p c l o s e _ p c l o s e p o p e n _ p o p e n p u t e n v r e a d l i n k
s e t e n v s e t l o c a l e s t r c a s e c m p s t p c p y s t r d u p s t r e r r o r s t r t o u l t s e a r c h u n s e t e n v w c s l e n )
string ( TOUPPER ${ _f } _UF )
check_function_exists ( ${ _f } HAVE_ ${ _UF } )
2013-02-12 16:22:07 +00:00
set ( Function_Defines "${Function_Defines}#cmakedefine HAVE_${_UF} 1\n" )
2013-02-12 14:27:39 +00:00
endforeach ( )
2013-02-12 18:01:16 +00:00
configure_file ( ${ LYX_CMAKE_DIR } /configFunctions.cmake ${ TOP_BINARY_DIR } /configFunctions.h.cmake )
configure_file ( ${ TOP_BINARY_DIR } /configFunctions.h.cmake ${ TOP_BINARY_DIR } /configFunctions.h )
2006-06-11 11:57:25 +00:00
2006-08-14 08:59:30 +00:00
check_symbol_exists ( alloca "malloc.h" HAVE_SYMBOL_ALLOCA )
2006-06-11 11:57:25 +00:00
check_symbol_exists ( asprintf "stdio.h" HAVE_ASPRINTF )
check_symbol_exists ( wprintf "stdio.h" HAVE_WPRINTF )
check_symbol_exists ( snprintf "stdio.h" HAVE_SNPRINTF )
check_symbol_exists ( printf "stdio.h" HAVE_POSIX_PRINTF )
check_symbol_exists ( pid_t "sys/types.h" HAVE_PID_T )
check_symbol_exists ( intmax_t "inttypes.h" HAVE_INTTYPES_H_WITH_UINTMAX )
check_symbol_exists ( uintmax_t "stdint.h" HAVE_STDINT_H_WITH_UINTMAX )
check_symbol_exists ( LC_MESSAGES "locale.h" HAVE_LC_MESSAGES )
2016-06-12 17:56:31 +00:00
check_symbol_exists ( PATH_MAX "limits.h" HAVE_DEF_PATH_MAX )
2006-06-11 11:57:25 +00:00
check_type_size ( intmax_t HAVE_INTMAX_T )
2008-04-20 11:06:08 +00:00
macro_bool_to_01 ( HAVE_UINTMAX_T HAVE_STDINT_H_WITH_UINTMAX )
2006-06-11 11:57:25 +00:00
check_type_size ( "long double" HAVE_LONG_DOUBLE )
2019-03-21 15:12:02 +00:00
check_type_size ( "long long" HAVE_LONG_LONG_INT )
2006-06-11 11:57:25 +00:00
check_type_size ( wchar_t HAVE_WCHAR_T )
check_type_size ( wint_t HAVE_WINT_T )
2018-03-30 17:40:08 +00:00
if ( HUNSPELL_FOUND )
# check whether hunspell C++ (rather than C) ABI is provided
set ( HunspellTestFile "${CMAKE_BINARY_DIR}/hunspelltest.cpp" )
file ( WRITE "${HunspellTestFile}"
"
2019-11-28 13:31:26 +00:00
#include <hunspell.hxx>
2018-03-30 17:40:08 +00:00
i n t main ( )
{
H u n s p e l l sp ( \"foo\", \"bar\");
i n t i = s p . stem ( \"test\").size();
2018-03-30 12:10:45 +00:00
return ( 0 ) ;
2018-03-30 17:40:08 +00:00
}
"
)
2021-01-20 08:39:03 +00:00
# The trick with faking the link command (see the else block) does not work
# with XCode (350a9daf).
if ( APPLE OR LYX_EXTERNAL_HUNSPELL )
2018-03-30 17:40:08 +00:00
try_compile ( HAVE_HUNSPELL_CXXABI
" $ { C M A K E _ B I N A R Y _ D I R } "
" $ { H u n s p e l l T e s t F i l e } "
C M A K E _ F L A G S
" - D I N C L U D E _ D I R E C T O R I E S : S T R I N G = $ { H U N S P E L L _ I N C L U D E _ D I R } "
2019-11-29 12:49:02 +00:00
L I N K _ L I B R A R I E S $ { H U N S P E L L _ L I B R A R Y }
O U T P U T _ V A R I A B L E L O G 2 )
2021-01-20 08:39:03 +00:00
else ( )
try_compile ( HAVE_HUNSPELL_CXXABI
" $ { C M A K E _ B I N A R Y _ D I R } "
" $ { H u n s p e l l T e s t F i l e } "
C M A K E _ F L A G S
" - D I N C L U D E _ D I R E C T O R I E S : S T R I N G = $ { H U N S P E L L _ I N C L U D E _ D I R } "
# At this point, ../lib/libhunspell.a has not been built so we
# cannot complete the linking.
" - D C M A K E _ C X X _ L I N K _ E X E C U T A B L E = ' $ { C M A K E _ C O M M A D } e c h o dummy ( fake ) l i n k c o m m a n d s i n c e l i b h u n s p e l l . a n o t b u i l t y e t . ' "
O U T P U T _ V A R I A B L E L O G 2 )
endif ( )
2018-03-30 12:10:45 +00:00
2018-03-30 17:40:08 +00:00
message ( STATUS "HAVE_HUNSPELL_CXXABI = ${HAVE_HUNSPELL_CXXABI}" )
#message(STATUS "LOG2 = ${LOG2}")
2020-07-11 10:43:17 +00:00
if ( LYX_EXTERNAL_HUNSPELL AND ( LYX_STDLIB_DEBUG OR LYX_DEBUG_GLIBC OR LYX_DEBUG_GLIBC_PEDANTIC ) AND HAVE_HUNSPELL_CXXABI )
message ( FATAL_ERROR "Compiling LyX with stdlib-debug and system hunspell libraries may lead to crashes. Consider using '-DLYX_STDLIB_DEBUG=OFF -DLYX_DEBUG_GLIBC=OFF -DLYX_DEBUG_GLIBC_PEDANTIC=OFF' or -DLYX_EXTERNAL_HUNSPELL=OFF." )
2018-04-09 15:13:52 +00:00
endif ( )
2018-03-30 17:40:08 +00:00
endif ( )
2006-06-11 11:57:25 +00:00
2007-08-23 21:18:53 +00:00
#check_cxx_source_compiles(
# "
# #include <algorithm>
# using std::count;
# int countChar(char * b, char * e, char const c)
# {
# return count(b, e, c);
# }
# int main(){return 0;}
# "
#HAVE_STD_COUNT)
#check_cxx_source_compiles(
# "
# #include <cctype>
# using std::tolower;
# int main(){return 0;}
# "
#CXX_GLOBAL_CSTD)
2006-06-11 11:57:25 +00:00
2007-08-10 15:09:34 +00:00
check_cxx_source_compiles (
"
#include <iconv.h>
/ / t h i s d e c l a r a t i o n w i l l f a i l w h e n t h e r e a l r e a d y e x i s t s a n o n c o n s t c h a r * * v e r s i o n w h i c h r e t u r n s s i z e _ t
d o u b l e iconv ( iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft ) ;
i n t main ( ) { r e t u r n 0 ; }
"
H A V E _ I C O N V _ C O N S T )
2006-08-14 16:38:04 +00:00
2006-09-13 21:45:52 +00:00
check_cxx_source_compiles (
"
i n t i [ ( sizeof ( wchar_t ) = = 2 ? 1 : - 1 ) ] ;
i n t main ( ) { r e t u r n 0 ; }
"
S I Z E O F _ W C H A R _ T _ I S _ 2 )
check_cxx_source_compiles (
"
i n t i [ ( sizeof ( wchar_t ) = = 4 ? 1 : - 1 ) ] ;
i n t main ( ) { r e t u r n 0 ; }
"
S I Z E O F _ W C H A R _ T _ I S _ 4 )
2016-05-05 11:05:12 +00:00
check_cxx_source_compiles (
"
i n t i [ ( sizeof ( long long ) > sizeof ( long ) ? 1 : - 1 ) ] ;
i n t main ( ) { r e t u r n 0 ; }
"
S I Z E O F _ L O N G _ L O N G _ G R E A T E R _ T H A N _ S I Z E O F _ L O N G )
2019-02-26 08:50:58 +00:00
if ( LYX_DISABLE_CALLSTACK_PRINTING )
set ( LYX_CALLSTACK_PRINTING OFF CACHE BOOL "Print callstack when crashing" )
else ( )
check_cxx_source_compiles (
2014-11-09 11:59:14 +00:00
"
#include <execinfo.h>
#include <cxxabi.h>
i n t main ( ) {
v o i d * a r r a y [ 2 0 0 ] ;
s i z e _ t s i z e = backtrace ( array, 200 ) ;
backtrace_symbols ( array, size ) ;
i n t s t a t u s = 0 ;
a b i : : __cxa_demangle ( \"abcd\", 0, 0, &status ) ;
}
"
2019-02-26 08:50:58 +00:00
L Y X _ C A L L S T A C K _ P R I N T I N G )
endif ( )
2014-11-09 11:59:14 +00:00
2014-12-19 11:32:14 +00:00
# Check whether STL is libstdc++
check_cxx_source_compiles (
"
#include <vector>
i n t main ( ) {
#if ! defined(__GLIBCXX__) && ! defined(__GLIBCPP__)
t h i s i s n o t l i b s t d c + +
#endif
return ( 0 ) ;
}
"
2015-05-08 19:12:42 +00:00
l y x _ c v _ l i b _ s t d c x x )
# Check whether STL is libstdc++ with C++11 ABI
check_cxx_source_compiles (
"
#include <vector>
i n t main ( ) {
#if ! defined(_GLIBCXX_USE_CXX11_ABI) || ! _GLIBCXX_USE_CXX11_ABI
t h i s i s n o t l i b s t d c + + u s i n g t h e C + + 1 1 A B I
#endif
return ( 0 ) ;
}
"
U S E _ G L I B C X X _ C X X 1 1 _ A B I )
2014-12-19 11:32:14 +00:00
2014-12-21 16:23:56 +00:00
check_cxx_source_compiles (
"
#ifndef __clang__
t h i s i s n o t c l a n g
#endif
i n t main ( ) {
return ( 0 ) ;
}
"
l y x _ c v _ p r o g _ c l a n g )
2016-06-12 17:56:31 +00:00
check_cxx_source_compiles (
"
#include <memory>
u s i n g s t d : : m a k e _ u n i q u e ;
i n t main ( ) {
return ( 0 ) ;
}
"
H A V E _ D E F _ M A K E _ U N I Q U E )
2016-08-07 09:32:53 +00:00
check_cxx_source_compiles (
"
#include <mutex>
s t a t i c s t d : : o n c e _ f l a g f l a g ;
i n t main ( ) {
s t d : : call_once ( flag, []( ) { r e t u r n ; } ) ;
return ( 0 ) ;
}
"
L Y X _ U S E _ S T D _ C A L L _ O N C E )
2018-01-24 15:19:34 +00:00
if ( ENCHANT_FOUND )
set ( CMAKE_REQUIRED_INCLUDES ${ ENCHANT_INCLUDE_DIR } )
set ( CMAKE_REQUIRED_LIBRARIES ${ ENCHANT_LIBRARY } )
# Check, whether enchant is version 2.x at least
check_cxx_source_compiles (
"
#include <enchant++.h>
e n c h a n t : : B r o k e r b r o k e r ;
i n t main ( ) {
return ( 0 ) ;
}
"
H A V E _ E N C H A N T 2 )
if ( HAVE_ENCHANT2 )
message ( STATUS "ENCHANT2 found" )
endif ( )
endif ( )
2014-12-21 16:23:56 +00:00
set ( USE_LLVM_LIBCPP )
2015-05-08 19:12:42 +00:00
set ( STD_STRING_USES_COW )
set ( USE_GLIBCXX_CXX11_ABI )
if ( lyx_cv_lib_stdcxx )
if ( NOT USE_GLIBCXX_CXX11_ABI )
set ( STD_STRING_USES_COW 1 )
endif ( )
else ( )
2014-12-21 16:23:56 +00:00
if ( lyx_cv_prog_clang )
# use libc++ provided by llvm instead of GNU libstdc++
set ( USE_LLVM_LIBCPP 1 )
endif ( )
endif ( )
2014-12-08 16:43:05 +00:00
2016-07-10 17:31:32 +00:00
set ( HAVE_QT5_X11_EXTRAS )
2021-03-22 15:19:10 +00:00
set ( HAVE_QT6_X11_EXTRAS )
if ( LYX_USE_QT MATCHES "QT5|QT6" )
if ( LYX_USE_QT MATCHES "QT5" )
set ( QtVal Qt5 )
else ( )
set ( QtVal Qt6 )
endif ( )
2022-09-17 12:14:41 +00:00
set ( CMAKE_REQUIRED_INCLUDES ${ ${QtVal } Core_INCLUDE_DIRS} )
2016-07-10 17:31:32 +00:00
set ( CMAKE_REQUIRED_FLAGS )
2021-03-22 15:19:10 +00:00
#message(STATUS "${QtVal}Core_INCLUDE_DIRS = ${${QtVal}Core_INCLUDE_DIRS}")
2017-02-22 23:18:52 +00:00
check_include_file_cxx ( QtGui/qtgui-config.h HAVE_QTGUI_CONFIG_H )
if ( HAVE_QTGUI_CONFIG_H )
2022-09-17 12:14:41 +00:00
set ( lyx_qt_config "QtGui/qtgui-config.h" )
2017-02-22 23:18:52 +00:00
else ( )
2022-09-17 12:14:41 +00:00
set ( lyx_qt_config "QtCore/qconfig.h" )
2017-02-22 23:18:52 +00:00
endif ( )
2018-02-10 10:21:08 +00:00
if ( WIN32 )
2019-06-24 10:56:51 +00:00
set ( QT_USES_X11 OFF CACHE BOOL "Win32 compiled without X11" )
2018-02-10 10:21:08 +00:00
# The try_run for minngw would not work here anyway
else ( )
check_cxx_source_runs (
"
2022-09-17 12:14:41 +00:00
#include <${lyx_qt_config}>
2018-02-10 10:21:08 +00:00
#include <string>
u s i n g n a m e s p a c e s t d ;
s t r i n g a ( QT_QPA_DEFAULT_PLATFORM_NAME ) ;
i n t main ( int argc, char **argv )
{
if ( a.compare(\ "xcb\" ) = = 0 )
return ( 0 ) ;
e l s e
r e t u r n 1 ;
}
"
Q T _ U S E S _ X 1 1 )
endif ( )
2016-07-10 17:31:32 +00:00
2021-03-22 15:19:10 +00:00
if ( ${ QtVal } X11Extras_FOUND )
get_target_property ( _x11extra_prop ${ QtVal } ::X11Extras IMPORTED_CONFIGURATIONS )
get_target_property ( _x11extra_link_libraries ${ QtVal } ::X11Extras IMPORTED_LOCATION_ ${ _x11extra_prop } )
2014-06-12 05:52:45 +00:00
set ( CMAKE_REQUIRED_LIBRARIES ${ _x11extra_link_libraries } )
2021-03-22 15:19:10 +00:00
set ( CMAKE_REQUIRED_INCLUDES ${ ${QtVal } X11Extras_INCLUDE_DIRS} )
set ( CMAKE_REQUIRED_FLAGS "${${QtVal}X11Extras_EXECUTABLE_COMPILE_FLAGS} -fPIC -DQT_NO_VERSION_TAGGING" )
2016-05-30 06:22:15 +00:00
#message(STATUS "CMAKE_REQUIRED_LIBRARIES = ${_x11extra_link_libraries}")
2021-03-22 15:19:10 +00:00
#message(STATUS "CMAKE_REQUIRED_INCLUDES = ${${QtVal}X11Extras_INCLUDE_DIRS}")
2016-05-30 06:22:15 +00:00
#message(STATUS "CMAKE_REQUIRED_FLAGS = ${CMAKE_REQUIRED_FLAGS}")
2014-06-12 05:52:45 +00:00
check_cxx_source_compiles (
"
#include <QtX11Extras/QX11Info>
i n t main ( )
{
b o o l i s X 1 1 = Q X 1 1 I n f o : : isPlatformX11 ( ) ;
}
"
2016-07-10 17:31:32 +00:00
Q T _ H A S _ X 1 1 _ E X T R A S )
2022-09-17 12:14:41 +00:00
string ( TOUPPER ${ QtVal } QTVAL )
set ( HAVE_ ${ QTVAL } _X11_EXTRAS ${ QT_HAS_X11_EXTRAS } )
set ( LYX_ ${ QTVAL } _X11_EXTRAS_LIBRARY ${ _x11extra_link_libraries } )
2014-06-12 05:52:45 +00:00
endif ( )
2021-03-22 15:19:10 +00:00
if ( ${ QtVal } WinExtras_FOUND )
get_target_property ( _winextra_prop ${ QtVal } ::WinExtras IMPORTED_CONFIGURATIONS )
2015-12-15 12:08:48 +00:00
string ( TOUPPER ${ CMAKE_BUILD_TYPE } BUILD_TYPE )
2021-03-22 15:19:10 +00:00
get_target_property ( _winextra_link_libraries ${ QtVal } ::WinExtras IMPORTED_LOCATION_ ${ BUILD_TYPE } )
2014-12-26 15:53:31 +00:00
set ( CMAKE_REQUIRED_LIBRARIES ${ _winextra_link_libraries } )
2021-03-22 15:19:10 +00:00
set ( CMAKE_REQUIRED_INCLUDES ${ ${QtVal } WinExtras_INCLUDE_DIRS} )
set ( CMAKE_REQUIRED_FLAGS ${ ${QtVal } WinExtras_EXECUTABLE_COMPILE_FLAGS} )
2014-12-26 15:53:31 +00:00
endif ( )
2014-06-12 05:52:45 +00:00
else ( )
message ( FATAL_ERROR "Check for QT_USES_X11: Not handled LYX_USE_QT (= ${LYX_USE_QT})" )
2014-05-25 11:50:18 +00:00
endif ( )