Merge branch 'cmake-c++11-stl' of git://github.com/MaartenBent/wxWidgets
CMake: Improve STL checks, improve C++17/20 support. See https://github.com/wxWidgets/wxWidgets/pull/1782 Closes #18718.
This commit is contained in:
@@ -77,14 +77,7 @@ endmacro()
|
||||
function(wx_set_common_target_properties target_name)
|
||||
cmake_parse_arguments(wxCOMMON_TARGET_PROPS "DEFAULT_WARNINGS" "" "" ${ARGN})
|
||||
|
||||
if(DEFINED wxBUILD_CXX_STANDARD AND NOT wxBUILD_CXX_STANDARD STREQUAL COMPILER_DEFAULT)
|
||||
# TODO: implement for older CMake versions ?
|
||||
set_target_properties(${target_name} PROPERTIES CXX_STANDARD ${wxBUILD_CXX_STANDARD})
|
||||
if(
|
||||
APPLE AND
|
||||
CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.9 AND
|
||||
(wxBUILD_CXX_STANDARD EQUAL 11 OR wxBUILD_CXX_STANDARD EQUAL 14)
|
||||
)
|
||||
if(APPLE AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.9 AND wxHAS_CXX11)
|
||||
if(CMAKE_GENERATOR STREQUAL "Xcode")
|
||||
set_target_properties(${target_name} PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY libc++)
|
||||
else()
|
||||
@@ -92,7 +85,6 @@ function(wx_set_common_target_properties target_name)
|
||||
target_link_libraries(${target_name} PRIVATE "-stdlib=libc++")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
set_target_properties(${target_name} PROPERTIES
|
||||
LIBRARY_OUTPUT_DIRECTORY "${wxOUTPUT_DIR}${wxPLATFORM_LIB_DIR}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${wxOUTPUT_DIR}${wxPLATFORM_LIB_DIR}"
|
||||
|
@@ -8,6 +8,15 @@
|
||||
# Licence: wxWindows licence
|
||||
#############################################################################
|
||||
|
||||
if(DEFINED wxBUILD_CXX_STANDARD AND NOT wxBUILD_CXX_STANDARD STREQUAL COMPILER_DEFAULT)
|
||||
set(CMAKE_CXX_STANDARD ${wxBUILD_CXX_STANDARD})
|
||||
endif()
|
||||
if(NOT CMAKE_CXX_STANDARD EQUAL 98)
|
||||
set(wxHAS_CXX11 TRUE)
|
||||
else()
|
||||
set(wxHAS_CXX11 FALSE)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
# Determine MSVC runtime library flag
|
||||
set(MSVC_LIB_USE "/MD")
|
||||
|
@@ -36,15 +36,17 @@ endif()
|
||||
|
||||
if(MSVC)
|
||||
wx_option(wxBUILD_MSVC_MULTIPROC "Enable multi-processor compilation for MSVC")
|
||||
else()
|
||||
# Other compilers support setting the C++ standard, present it an option to the user
|
||||
endif()
|
||||
|
||||
if(NOT MSVC OR MSVC_VERSION GREATER 1800)
|
||||
# support setting the C++ standard, present it an option to the user
|
||||
if(DEFINED CMAKE_CXX_STANDARD)
|
||||
set(wxCXX_STANDARD_DEFAULT ${CMAKE_CXX_STANDARD})
|
||||
else()
|
||||
set(wxCXX_STANDARD_DEFAULT COMPILER_DEFAULT)
|
||||
endif()
|
||||
wx_option(wxBUILD_CXX_STANDARD "C++ standard used to build wxWidgets targets"
|
||||
${wxCXX_STANDARD_DEFAULT} STRINGS COMPILER_DEFAULT 98 11 14 17)
|
||||
${wxCXX_STANDARD_DEFAULT} STRINGS COMPILER_DEFAULT 98 11 14 17 20)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
|
@@ -213,7 +213,7 @@ wx_list_add_prefix(WIDGETS_RC_FILES icons/
|
||||
stattext.xpm text.xpm timepick.xpm toggle.xpm
|
||||
)
|
||||
wx_add_sample(widgets IMPORTANT ${SAMPLE_WIDGETS_SRC}
|
||||
DATA ${WIDGETS_RC_FILES} textctrl.cpp
|
||||
DATA ${WIDGETS_RC_FILES} textctrl.cpp ../image/toucan.png
|
||||
)
|
||||
wx_add_sample(wizard DEPENDS wxUSE_WIZARDDLG)
|
||||
wx_add_sample(wrapsizer)
|
||||
|
@@ -23,11 +23,7 @@ include(CheckTypeSize)
|
||||
include(CMakePushCheckState)
|
||||
include(TestBigEndian)
|
||||
|
||||
if(
|
||||
APPLE AND
|
||||
CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.9 AND
|
||||
(CMAKE_CXX_STANDARD EQUAL 11 OR CMAKE_CXX_STANDARD EQUAL 14)
|
||||
)
|
||||
if(APPLE AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.9 AND wxHAS_CXX11)
|
||||
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} "-stdlib=libc++")
|
||||
endif()
|
||||
|
||||
@@ -147,7 +143,7 @@ wx_check_c_source_compiles(
|
||||
stdio.h
|
||||
)
|
||||
#TODO: wxNO_VARIADIC_MACROS
|
||||
if(wxUSE_STL)
|
||||
if(wxUSE_STL AND NOT wxHAS_CXX11)
|
||||
wx_check_cxx_source_compiles("
|
||||
std::vector<int> moo;
|
||||
std::list<int> foo;
|
||||
@@ -172,6 +168,12 @@ if(wxUSE_STL)
|
||||
HAVE_STD_STRING_COMPARE
|
||||
string
|
||||
)
|
||||
|
||||
wx_check_cxx_source_compiles(
|
||||
"std::wstring s;"
|
||||
HAVE_STD_WSTRING
|
||||
string
|
||||
)
|
||||
endif()
|
||||
|
||||
# Check for availability of GCC's atomic operations builtins.
|
||||
@@ -588,13 +590,6 @@ check_include_file(w32api.h HAVE_W32API_H)
|
||||
check_include_file(wchar.h HAVE_WCHAR_H)
|
||||
check_include_file(wcstr.h HAVE_WCSTR_H)
|
||||
|
||||
|
||||
wx_check_cxx_source_compiles(
|
||||
"std::wstring s;"
|
||||
HAVE_STD_WSTRING
|
||||
string
|
||||
)
|
||||
|
||||
if(wxUSE_DATETIME)
|
||||
# check for timezone variable
|
||||
# doesn't exist under Darwin / Mac OS X which uses tm_gmtoff instead
|
||||
|
@@ -171,6 +171,9 @@ Currently the following symbols exist:
|
||||
wxBitmapToggleButton class is available in addition to wxToggleButton.}
|
||||
@itemdef{wxHAS_CONFIG_TEMPLATE_RW, Defined if the currently used compiler
|
||||
supports template Read() and Write() methods in wxConfig.}
|
||||
@itemdef{wxHAS_MEMBER_DEFAULT, Defined if the currently used compiler supports
|
||||
C++11 @c =default. @c wxMEMBER_DEFAULT is defined as this keyword in this
|
||||
case, and as nothing otherwise.}
|
||||
@itemdef{wxHAS_LARGE_FILES, Defined if wxFile supports files more than 4GB in
|
||||
size (notice that you must include @c wx/filefn.h before testing for this
|
||||
symbol).}
|
||||
|
@@ -38,9 +38,9 @@ public:
|
||||
wxAnimation();
|
||||
explicit wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY);
|
||||
|
||||
#if __cplusplus >= 201103
|
||||
wxAnimation(const wxAnimation&) = default;
|
||||
wxAnimation& operator=(const wxAnimation&) = default;
|
||||
#ifdef wxHAS_MEMBER_DEFAULT
|
||||
wxAnimation(const wxAnimation&) wxMEMBER_DEFAULT;
|
||||
wxAnimation& operator=(const wxAnimation&) wxMEMBER_DEFAULT;
|
||||
#endif
|
||||
|
||||
bool IsOk() const;
|
||||
|
@@ -285,6 +285,14 @@ typedef short int WXTYPE;
|
||||
#define wxOVERRIDE
|
||||
#endif /* HAVE_OVERRIDE */
|
||||
|
||||
/* same for defaulted member function keyword */
|
||||
#if __cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(14)
|
||||
#define wxHAS_MEMBER_DEFAULT
|
||||
#define wxMEMBER_DEFAULT = default
|
||||
#else
|
||||
#define wxMEMBER_DEFAULT
|
||||
#endif
|
||||
|
||||
/*
|
||||
Support for nullptr is available since MSVS 2010, even though it doesn't
|
||||
define __cplusplus as a C++11 compiler.
|
||||
@@ -2994,7 +3002,7 @@ typedef const void* WXWidget;
|
||||
/* macros to define a class without copy ctor nor assignment operator */
|
||||
/* --------------------------------------------------------------------------- */
|
||||
|
||||
#if defined(__cplusplus) && __cplusplus >= 201103L
|
||||
#if defined(__cplusplus) && (__cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(14))
|
||||
#define wxMEMBER_DELETE = delete
|
||||
#else
|
||||
#define wxMEMBER_DELETE
|
||||
|
@@ -66,11 +66,9 @@ public:
|
||||
|
||||
operator HSTRING() const { return m_hstring; };
|
||||
|
||||
static const TempStringRef Make(const wxString &str);
|
||||
TempStringRef(const wxString& str);
|
||||
|
||||
private:
|
||||
TempStringRef(const wxString &str);
|
||||
|
||||
HSTRING m_hstring;
|
||||
HSTRING_HEADER m_header;
|
||||
|
||||
|
@@ -267,8 +267,8 @@ public:
|
||||
wxUniCharRef& operator=(const wxUniCharRef& c)
|
||||
{ if (&c != this) *this = c.UniChar(); return *this; }
|
||||
|
||||
#if __cplusplus >= 201103
|
||||
wxUniCharRef(const wxUniCharRef&) = default;
|
||||
#ifdef wxHAS_MEMBER_DEFAULT
|
||||
wxUniCharRef(const wxUniCharRef&) wxMEMBER_DEFAULT;
|
||||
#endif
|
||||
|
||||
#define wxUNICHAR_REF_DEFINE_OPERATOR_EQUAL(type) \
|
||||
|
@@ -1070,9 +1070,9 @@ bool RegTreeCtrl::TreeNode::OnExpand()
|
||||
|
||||
case wxRegKey::Type_Dword:
|
||||
{
|
||||
long l;
|
||||
m_pKey->QueryValue(str, &l);
|
||||
strItem << l;
|
||||
long ldw;
|
||||
m_pKey->QueryValue(str, &ldw);
|
||||
strItem << ldw;
|
||||
}
|
||||
wxFALLTHROUGH;
|
||||
|
||||
|
@@ -59,7 +59,7 @@ wxArrayString::wxArrayString(size_t sz, const wxString* a)
|
||||
|
||||
#include "wx/arrstr.h"
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
#if __cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(14)
|
||||
|
||||
int wxArrayString::Index(const wxString& str, bool bCase, bool WXUNUSED(bFromEnd)) const
|
||||
{
|
||||
@@ -153,7 +153,7 @@ wxStringCompareLess<F> wxStringCompare(F f)
|
||||
void wxArrayString::Sort(CompareFunction function)
|
||||
{
|
||||
std::sort(begin(), end(),
|
||||
#if __cplusplus >= 201103L
|
||||
#if __cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(14)
|
||||
[function](const wxString& s1, const wxString& s2)
|
||||
{
|
||||
return function(s1, s2) < 0;
|
||||
@@ -185,7 +185,7 @@ int wxSortedArrayString::Index(const wxString& str,
|
||||
|
||||
wxSortedArrayString::const_iterator
|
||||
it = std::lower_bound(begin(), end(), str,
|
||||
#if __cplusplus >= 201103L
|
||||
#if __cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(14)
|
||||
[](const wxString& s1, const wxString& s2)
|
||||
{
|
||||
return s1 < s2;
|
||||
|
@@ -170,7 +170,7 @@ public:
|
||||
|
||||
HRESULT CreateToast(IXmlDocument *xml)
|
||||
{
|
||||
HRESULT hr = ms_toastMgr->CreateToastNotifierWithId(rt::TempStringRef::Make(ms_appId), &m_notifier);
|
||||
HRESULT hr = ms_toastMgr->CreateToastNotifierWithId(rt::TempStringRef(ms_appId), &m_notifier);
|
||||
if ( SUCCEEDED(hr) )
|
||||
{
|
||||
wxCOMPtr<IToastNotificationFactory> factory;
|
||||
@@ -215,7 +215,7 @@ public:
|
||||
if ( SUCCEEDED(hr) )
|
||||
{
|
||||
wxCOMPtr<IXmlNodeList> nodeList;
|
||||
hr = (*toastXml)->GetElementsByTagName(rt::TempStringRef::Make("text"), &nodeList);
|
||||
hr = (*toastXml)->GetElementsByTagName(rt::TempStringRef("text"), &nodeList);
|
||||
if ( SUCCEEDED(hr) )
|
||||
{
|
||||
hr = SetNodeListValueString(0, m_title, nodeList, *toastXml);
|
||||
@@ -244,7 +244,7 @@ public:
|
||||
{
|
||||
wxCOMPtr<IXmlText> inputText;
|
||||
|
||||
HRESULT hr = xml->CreateTextNode(rt::TempStringRef::Make(str), &inputText);
|
||||
HRESULT hr = xml->CreateTextNode(rt::TempStringRef(str), &inputText);
|
||||
if ( SUCCEEDED(hr) )
|
||||
{
|
||||
wxCOMPtr<IXmlNode> inputTextNode;
|
||||
|
@@ -166,15 +166,14 @@ int RTCore::ms_isAvailable = -1;
|
||||
// wxWinRT::TempStringRef
|
||||
//
|
||||
|
||||
const TempStringRef TempStringRef::Make(const wxString &str)
|
||||
{
|
||||
return TempStringRef(str);
|
||||
}
|
||||
|
||||
TempStringRef::TempStringRef(const wxString &str)
|
||||
: m_hstring(NULL), m_header()
|
||||
{
|
||||
if ( !RTCore::IsAvailable() )
|
||||
{
|
||||
wxLogDebug("Can not create string reference without WinRT");
|
||||
return;
|
||||
}
|
||||
|
||||
// This creates a fast-pass string which must not be deleted using WindowsDeleteString
|
||||
HRESULT hr = RTCore::Get().WindowsCreateStringReference(
|
||||
@@ -221,7 +220,7 @@ bool GetActivationFactory(const wxString& activatableClassId, REFIID iid, void *
|
||||
if ( !RTCore::IsAvailable() )
|
||||
return false;
|
||||
|
||||
HRESULT hr = RTCore::Get().RoGetActivationFactory(TempStringRef::Make(activatableClassId), iid, factory);
|
||||
HRESULT hr = RTCore::Get().RoGetActivationFactory(TempStringRef(activatableClassId), iid, factory);
|
||||
if ( FAILED(hr) )
|
||||
{
|
||||
wxLogDebug("RoGetActivationFactory failed %.8x", hr);
|
||||
|
@@ -135,7 +135,11 @@ static void TestAssertHandler(const wxString& file,
|
||||
// so we'd just die without any useful information -- abort instead.
|
||||
abortReason << assertMessage << "in a worker thread.";
|
||||
}
|
||||
#if __cplusplus >= 201703L || wxCHECK_VISUALC_VERSION(14)
|
||||
else if ( uncaught_exceptions() )
|
||||
#else
|
||||
else if ( uncaught_exception() )
|
||||
#endif
|
||||
{
|
||||
// Throwing while already handling an exception would result in
|
||||
// terminate() being called and we wouldn't get any useful information
|
||||
|
Reference in New Issue
Block a user