From fd81223a2f878757158b5266c362da71d43abee5 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Thu, 16 Aug 2018 20:08:56 +0200 Subject: [PATCH 1/7] Fix c++11-narrowing error when using clang on Windows Case value 0xfffffd9f results in the following error: error: case value evaluates to 4294966687, which cannot be narrowed to type 'DISPID' (aka 'long') [-Wc++11-narrowing] --- src/msw/mediactrl_am.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/msw/mediactrl_am.cpp b/src/msw/mediactrl_am.cpp index 1b8c9e6bd7..5379eda8af 100644 --- a/src/msw/mediactrl_am.cpp +++ b/src/msw/mediactrl_am.cpp @@ -1530,7 +1530,9 @@ void wxAMMediaBackend::Move(int WXUNUSED(x), int WXUNUSED(y), //--------------------------------------------------------------------------- void wxAMMediaEvtHandler::OnActiveX(wxActiveXEvent& event) { - switch(event.GetDispatchId()) + // cast to unsigned long to fix narrowing error with case 0xfffffd9f + // when using clang + switch (static_cast(event.GetDispatchId())) { case 0x00000001: // statechange in IActiveMovie case 0x00000bc4: // playstatechange in IMediaPlayer From 8d72f3c5f493ddbda71a0066398644c876e09727 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Thu, 16 Aug 2018 20:11:12 +0200 Subject: [PATCH 2/7] Fix multiple definition error when using clang on Windows --- src/msw/dirdlg.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/msw/dirdlg.cpp b/src/msw/dirdlg.cpp index 84557d7c95..b0b9ed84d9 100644 --- a/src/msw/dirdlg.cpp +++ b/src/msw/dirdlg.cpp @@ -73,12 +73,15 @@ struct IShellItem : public IUnknown #endif // #ifndef __IShellItem_INTERFACE_DEFINED__ +#if defined(__VISUALC__) || !defined(__IShellItem_INTERFACE_DEFINED__) // Define this GUID in any case, even when __IShellItem_INTERFACE_DEFINED__ is // defined in the headers we might still not have it in the actual uuid.lib, -// this happens with at least VC7 used with its original (i.e. not updated) SDK -// and there is no harm in defining the GUID unconditionally. +// this happens with at least VC7 used with its original (i.e. not updated) SDK. +// clang complains about multiple definitions, so only define it unconditionally +// when using a Visual C compiler. DEFINE_GUID(IID_IShellItem, 0x43826D1E, 0xE718, 0x42EE, 0xBC, 0x55, 0xA1, 0xE2, 0x61, 0xC3, 0x7B, 0xFE); +#endif struct IShellItemFilter; struct IFileDialogEvents; From ceda6f6815dbb9910b52fe783db687567a5cad5a Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Thu, 16 Aug 2018 20:12:44 +0200 Subject: [PATCH 3/7] Support clang compiler on Windows when using CMake --- build/cmake/init.cmake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake index fac86758b6..06cd01906b 100644 --- a/build/cmake/init.cmake +++ b/build/cmake/init.cmake @@ -51,10 +51,12 @@ set(wxARCH_SUFFIX) # TODO: include compiler version in wxCOMPILER_PREFIX ? if(WIN32) - if(MSVC) + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") set(wxCOMPILER_PREFIX "vc") - elseif(CMAKE_COMPILER_IS_GNUCXX) + elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(wxCOMPILER_PREFIX "gcc") + elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set(wxCOMPILER_PREFIX "clang") else() message(FATAL_ERROR "Unknown WIN32 compiler type") endif() From 41d6bc579a1ef1004469a0f9abc18c258121bb7d Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Thu, 16 Aug 2018 20:21:52 +0200 Subject: [PATCH 4/7] Enable precompiled headers for samples --- build/cmake/functions.cmake | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/build/cmake/functions.cmake b/build/cmake/functions.cmake index 84fe6e3f7d..748871d32f 100644 --- a/build/cmake/functions.cmake +++ b/build/cmake/functions.cmake @@ -338,6 +338,18 @@ macro(wx_test_enable_precomp target_name) endif() endmacro() +# Enable precompiled headers for samples +macro(wx_sample_enable_precomp target_name) + if(wxBUILD_PRECOMP) + target_compile_definitions(${target_name} PRIVATE WX_PRECOMP) + set_target_properties(${target_name} PROPERTIES + COTIRE_CXX_PREFIX_HEADER_INIT "${wxSOURCE_DIR}/include/wx/wxprec.h") + wx_target_enable_precomp(${target_name}) + elseif(MSVC) + target_compile_definitions(${target_name} PRIVATE NOPCH) + endif() +endmacro() + # Enable precompiled headers for wx libraries macro(wx_finalize_lib target_name) set(wxLIB_TARGETS ${wxLIB_TARGETS} PARENT_SCOPE) @@ -629,8 +641,6 @@ function(wx_add_sample name) if(SAMPLE_DEFINITIONS) target_compile_definitions(${target_name} PRIVATE ${SAMPLE_DEFINITIONS}) endif() - # Disable precompile headers for samples - target_compile_definitions(${target_name} PRIVATE NOPCH) if(SAMPLE_DATA) # TODO: handle data files differently for OS X bundles # Copy data files to output directory @@ -667,6 +677,7 @@ function(wx_add_sample name) wx_string_append(folder "/${SAMPLE_FOLDER}") endif() wx_set_common_target_properties(${target_name}) + wx_sample_enable_precomp(${target_name}) set_target_properties(${target_name} PROPERTIES FOLDER ${folder} ) From 61500907ee815944f029dd86639b3aa08c11dff7 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Fri, 17 Aug 2018 19:49:38 +0200 Subject: [PATCH 5/7] CMake: Improve precompiled headers for wxscintilla The auto-generated header causes undefined members and identifiers in the standard c++ headers when using clang on macOS or Windows. Do not disable precompiled headers entirely but use the main Scintilla header as prefix header so there is at least a small speedup. --- build/cmake/functions.cmake | 30 ++++++++++-------------------- build/cmake/lib/stc/CMakeLists.txt | 12 +++++++++++- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/build/cmake/functions.cmake b/build/cmake/functions.cmake index 748871d32f..31812bd59d 100644 --- a/build/cmake/functions.cmake +++ b/build/cmake/functions.cmake @@ -314,25 +314,21 @@ macro(wx_add_library name) endif() endmacro() -# Enable cotire for target if precompiled headers are enabled +# Enable cotire for target, use optional second argument for prec. header macro(wx_target_enable_precomp target_name) - if(wxBUILD_PRECOMP) - if(APPLE AND ${target_name} STREQUAL "wxscintilla") - # TODO: workaround/fix cotire issue with wxscintilla when using Xcode - else() - set_target_properties(${target_name} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE) - cotire(${target_name}) - endif() + target_compile_definitions(${target_name} PRIVATE WX_PRECOMP) + if(NOT ${ARGV1} STREQUAL "") + set_target_properties(${target_name} PROPERTIES + COTIRE_CXX_PREFIX_HEADER_INIT ${ARGV1}) endif() + set_target_properties(${target_name} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE) + cotire(${target_name}) endmacro() # Enable precompiled headers for tests macro(wx_test_enable_precomp target_name) if(wxBUILD_PRECOMP) - target_compile_definitions(${target_name} PRIVATE WX_PRECOMP) - set_target_properties(${target_name} PROPERTIES - COTIRE_CXX_PREFIX_HEADER_INIT "${wxSOURCE_DIR}/tests/testprec.h") - wx_target_enable_precomp(${target_name}) + wx_target_enable_precomp(${target_name} "${wxSOURCE_DIR}/tests/testprec.h") elseif(MSVC) target_compile_definitions(${target_name} PRIVATE NOPCH) endif() @@ -341,10 +337,7 @@ endmacro() # Enable precompiled headers for samples macro(wx_sample_enable_precomp target_name) if(wxBUILD_PRECOMP) - target_compile_definitions(${target_name} PRIVATE WX_PRECOMP) - set_target_properties(${target_name} PROPERTIES - COTIRE_CXX_PREFIX_HEADER_INIT "${wxSOURCE_DIR}/include/wx/wxprec.h") - wx_target_enable_precomp(${target_name}) + wx_target_enable_precomp(${target_name} "${wxSOURCE_DIR}/include/wx/wxprec.h") elseif(MSVC) target_compile_definitions(${target_name} PRIVATE NOPCH) endif() @@ -355,10 +348,7 @@ macro(wx_finalize_lib target_name) set(wxLIB_TARGETS ${wxLIB_TARGETS} PARENT_SCOPE) if(wxBUILD_PRECOMP) if(TARGET ${target_name}) - target_compile_definitions(${target_name} PRIVATE WX_PRECOMP) - set_target_properties(${target_name} PROPERTIES - COTIRE_CXX_PREFIX_HEADER_INIT "${wxSOURCE_DIR}/include/wx/wxprec.h") - wx_target_enable_precomp(${target_name}) + wx_target_enable_precomp(${target_name} "${wxSOURCE_DIR}/include/wx/wxprec.h") endif() elseif(MSVC) wx_lib_compile_definitions(${target_name} PRIVATE NOPCH) diff --git a/build/cmake/lib/stc/CMakeLists.txt b/build/cmake/lib/stc/CMakeLists.txt index 55e3eafdf6..27af21bb79 100644 --- a/build/cmake/lib/stc/CMakeLists.txt +++ b/build/cmake/lib/stc/CMakeLists.txt @@ -164,7 +164,17 @@ target_compile_definitions(wxscintilla PUBLIC NO_CXX11_REGEX __WX__ ) -wx_target_enable_precomp(wxscintilla) + +if(wxBUILD_PRECOMP) + # The auto-generated header causes undefined members and identifiers in the + # standard c++ headers when using clang on macOS or Windows. + # Do not disable precompiled headers entirely but use the main Scintilla + # header as prefix header so there is at least a small speedup. + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND (APPLE OR WIN32)) + set(wxSCINTILLA_PREC_HEADER "${wxSOURCE_DIR}/src/stc/scintilla/include/Scintilla.h") + endif() + wx_target_enable_precomp(wxscintilla ${wxSCINTILLA_PREC_HEADER}) +endif() wx_add_library(stc ${STC_FILES}) wx_lib_include_directories(stc PRIVATE From 0bf459de92c6a3cb6f3302bff4f9360210c8b552 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Fri, 17 Aug 2018 19:15:08 +0200 Subject: [PATCH 6/7] Fix typos and whitespace in CMake files. --- build/cmake/README.md | 10 +++++----- build/cmake/functions.cmake | 4 ++-- build/cmake/init.cmake | 2 +- build/cmake/options.cmake | 1 - build/cmake/samples/CMakeLists.txt | 4 ++-- build/cmake/setup.cmake | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/build/cmake/README.md b/build/cmake/README.md index 708b78a434..82e13a28c6 100644 --- a/build/cmake/README.md +++ b/build/cmake/README.md @@ -28,9 +28,9 @@ Files * Every function should contain a short description of it's parameters as a comment before the function/macro * install.cmake - * Handles defintions for the `install` and `uninstall` target + * Handles definitions for the `install` and `uninstall` target * init.cmake - * Intializes various variables used during the build process and for + * Initializes various variables used during the build process and for generation of setup.h and configuration files * main.cmake * Includes all other cmake files @@ -60,7 +60,7 @@ _.cmake_ files. * Defines build targets for demos via `wx_add_demo()` * lib * Defines build targets for all libraries and bundle third party libraries - * Each library is contained in a seperate directory and uses + * Each library is contained in a separate directory and uses `wx_add_library()` to define the library target * Bundled third party library without upstream CMake support are defined in a _.cmake_ file using `wx_add_builtin_library()` to define static library @@ -70,8 +70,8 @@ _.cmake_ files. * Includes the [cotire module][4] used to for precompiled header generation * samples * Defines build targets for all samples via `wx_add_sample()` - * Defintions for trivial samples are included in _CMakeLists.txt_ more - complex samples might have a seperate .cmake file + * Definitions for trivial samples are included in _CMakeLists.txt_ more + complex samples might have a separate .cmake file * tests * Defines build targets for all tests * utils diff --git a/build/cmake/functions.cmake b/build/cmake/functions.cmake index 31812bd59d..8d4dc94511 100644 --- a/build/cmake/functions.cmake +++ b/build/cmake/functions.cmake @@ -8,7 +8,7 @@ ############################################################################# include(CMakeDependentOption) -include(CMakeParseArguments) # For compatiblity with CMake < 3.4 +include(CMakeParseArguments) # For compatibility with CMake < 3.4 include(ExternalProject) if(CMAKE_GENERATOR STREQUAL "Xcode") # wxWidgets does not use the unity features of cotire so we can @@ -546,7 +546,7 @@ endfunction() # IMPORTANT does not require wxBUILD_SAMPLES=ALL # RES followed by WIN32 .rc files # -# Additinally the following variables may be set before calling wx_add_sample: +# Additionally the following variables may be set before calling wx_add_sample: # wxSAMPLE_SUBDIR subdirectory in the samples/ folder to use as base # wxSAMPLE_FOLDER IDE sub folder to be used for the samples function(wx_add_sample name) diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake index 06cd01906b..4c93866c8f 100644 --- a/build/cmake/init.cmake +++ b/build/cmake/init.cmake @@ -76,7 +76,7 @@ if(MSVC OR MINGW) endif() if(MSVC) - # Include generator expression to supress default Debug/Release pair + # Include generator expression to suppress default Debug/Release pair set(wxPLATFORM_LIB_DIR "$<1:/>${wxCOMPILER_PREFIX}${wxARCH_SUFFIX}_${lib_suffix}") else() set(wxPLATFORM_LIB_DIR "/${wxCOMPILER_PREFIX}${wxARCH_SUFFIX}_${lib_suffix}") diff --git a/build/cmake/options.cmake b/build/cmake/options.cmake index 4a3d18a533..48b2ddf70a 100644 --- a/build/cmake/options.cmake +++ b/build/cmake/options.cmake @@ -403,7 +403,6 @@ if(WIN32) set(wxUSE_WINRT_DEFAULT OFF) endif() wx_option(wxUSE_WINRT "enable WinRT support" ${wxUSE_WINRT_DEFAULT}) - endif() # this one is not really MSW-specific but it exists mainly to be turned off diff --git a/build/cmake/samples/CMakeLists.txt b/build/cmake/samples/CMakeLists.txt index b59b698f63..27822b3b5f 100644 --- a/build/cmake/samples/CMakeLists.txt +++ b/build/cmake/samples/CMakeLists.txt @@ -199,7 +199,7 @@ wx_list_add_prefix(WIDGETS_RC_FILES icons/ slider.xpm spinbtn.xpm statbmp.xpm statbox.xpm stattext.xpm text.xpm timepick.xpm toggle.xpm ) -wx_add_sample(widgets IMPORTANT ${SAMPLE_WIDGETS_SRC} +wx_add_sample(widgets IMPORTANT ${SAMPLE_WIDGETS_SRC} DATA ${WIDGETS_RC_FILES} textctrl.cpp LIBRARIES adv ) @@ -258,7 +258,7 @@ if(WIN32) if(MSVC) wx_add_sample(flash) endif() - #TODO: renable when sample is fixed + #TODO: reenable when sample is fixed #wx_add_sample(mfc mfctest.cpp mfctest.h resource.h stdafx.h RES mfctest.rc) wx_add_sample(nativdlg nativdlg.cpp nativdlg.h resource.h RES nativdlg.rc) wx_add_sample(oleauto DEPENDS wxUSE_OLE) diff --git a/build/cmake/setup.cmake b/build/cmake/setup.cmake index 700d41e0f5..46092b0797 100644 --- a/build/cmake/setup.cmake +++ b/build/cmake/setup.cmake @@ -310,7 +310,7 @@ if(NOT WIN32) statfs(\"/\", &fs);" HAVE_STATFS_DECL) else() - # TODO: implment statvfs checks + # TODO: implement statvfs checks if(HAVE_STATVFS) set(WX_STATFS_T statvfs_t) endif() From ef7d203bf44303b16051ff8f1e3e9bce46803049 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Fri, 17 Aug 2018 19:54:52 +0200 Subject: [PATCH 7/7] Fix building taskbarbutton sample with precompiled headers --- samples/taskbarbutton/taskbarbutton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/taskbarbutton/taskbarbutton.cpp b/samples/taskbarbutton/taskbarbutton.cpp index 16241b5a93..f386832cf9 100644 --- a/samples/taskbarbutton/taskbarbutton.cpp +++ b/samples/taskbarbutton/taskbarbutton.cpp @@ -15,10 +15,10 @@ #ifndef WX_PRECOMP #include "wx/progdlg.h" - #include "wx/stdpaths.h" #include "wx/wx.h" #endif +#include "wx/stdpaths.h" #include "wx/taskbarbutton.h" enum