Fixes for clang under MSW and support in CMake build system.

See https://github.com/wxWidgets/wxWidgets/pull/887
This commit is contained in:
Vadim Zeitlin
2018-08-18 15:17:48 +02:00
10 changed files with 54 additions and 37 deletions

View File

@@ -28,9 +28,9 @@ Files
* Every function should contain a short description of it's parameters as * Every function should contain a short description of it's parameters as
a comment before the function/macro a comment before the function/macro
* install.cmake * install.cmake
* Handles defintions for the `install` and `uninstall` target * Handles definitions for the `install` and `uninstall` target
* init.cmake * 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 generation of setup.h and configuration files
* main.cmake * main.cmake
* Includes all other cmake files * Includes all other cmake files
@@ -60,7 +60,7 @@ _.cmake_ files.
* Defines build targets for demos via `wx_add_demo()` * Defines build targets for demos via `wx_add_demo()`
* lib * lib
* Defines build targets for all libraries and bundle third party libraries * 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 `wx_add_library()` to define the library target
* Bundled third party library without upstream CMake support are defined in * Bundled third party library without upstream CMake support are defined in
a _.cmake_ file using `wx_add_builtin_library()` to define static library 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 * Includes the [cotire module][4] used to for precompiled header generation
* samples * samples
* Defines build targets for all samples via `wx_add_sample()` * Defines build targets for all samples via `wx_add_sample()`
* Defintions for trivial samples are included in _CMakeLists.txt_ more * Definitions for trivial samples are included in _CMakeLists.txt_ more
complex samples might have a seperate .cmake file complex samples might have a separate .cmake file
* tests * tests
* Defines build targets for all tests * Defines build targets for all tests
* utils * utils

View File

@@ -8,7 +8,7 @@
############################################################################# #############################################################################
include(CMakeDependentOption) include(CMakeDependentOption)
include(CMakeParseArguments) # For compatiblity with CMake < 3.4 include(CMakeParseArguments) # For compatibility with CMake < 3.4
include(ExternalProject) include(ExternalProject)
if(CMAKE_GENERATOR STREQUAL "Xcode") if(CMAKE_GENERATOR STREQUAL "Xcode")
# wxWidgets does not use the unity features of cotire so we can # wxWidgets does not use the unity features of cotire so we can
@@ -314,25 +314,30 @@ macro(wx_add_library name)
endif() endif()
endmacro() 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) macro(wx_target_enable_precomp target_name)
if(wxBUILD_PRECOMP) target_compile_definitions(${target_name} PRIVATE WX_PRECOMP)
if(APPLE AND ${target_name} STREQUAL "wxscintilla") if(NOT ${ARGV1} STREQUAL "")
# TODO: workaround/fix cotire issue with wxscintilla when using Xcode set_target_properties(${target_name} PROPERTIES
else() COTIRE_CXX_PREFIX_HEADER_INIT ${ARGV1})
set_target_properties(${target_name} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
cotire(${target_name})
endif()
endif() endif()
set_target_properties(${target_name} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
cotire(${target_name})
endmacro() endmacro()
# Enable precompiled headers for tests # Enable precompiled headers for tests
macro(wx_test_enable_precomp target_name) macro(wx_test_enable_precomp target_name)
if(wxBUILD_PRECOMP) if(wxBUILD_PRECOMP)
target_compile_definitions(${target_name} PRIVATE WX_PRECOMP) wx_target_enable_precomp(${target_name} "${wxSOURCE_DIR}/tests/testprec.h")
set_target_properties(${target_name} PROPERTIES elseif(MSVC)
COTIRE_CXX_PREFIX_HEADER_INIT "${wxSOURCE_DIR}/tests/testprec.h") target_compile_definitions(${target_name} PRIVATE NOPCH)
wx_target_enable_precomp(${target_name}) endif()
endmacro()
# Enable precompiled headers for samples
macro(wx_sample_enable_precomp target_name)
if(wxBUILD_PRECOMP)
wx_target_enable_precomp(${target_name} "${wxSOURCE_DIR}/include/wx/wxprec.h")
elseif(MSVC) elseif(MSVC)
target_compile_definitions(${target_name} PRIVATE NOPCH) target_compile_definitions(${target_name} PRIVATE NOPCH)
endif() endif()
@@ -343,10 +348,7 @@ macro(wx_finalize_lib target_name)
set(wxLIB_TARGETS ${wxLIB_TARGETS} PARENT_SCOPE) set(wxLIB_TARGETS ${wxLIB_TARGETS} PARENT_SCOPE)
if(wxBUILD_PRECOMP) if(wxBUILD_PRECOMP)
if(TARGET ${target_name}) if(TARGET ${target_name})
target_compile_definitions(${target_name} PRIVATE WX_PRECOMP) wx_target_enable_precomp(${target_name} "${wxSOURCE_DIR}/include/wx/wxprec.h")
set_target_properties(${target_name} PROPERTIES
COTIRE_CXX_PREFIX_HEADER_INIT "${wxSOURCE_DIR}/include/wx/wxprec.h")
wx_target_enable_precomp(${target_name})
endif() endif()
elseif(MSVC) elseif(MSVC)
wx_lib_compile_definitions(${target_name} PRIVATE NOPCH) wx_lib_compile_definitions(${target_name} PRIVATE NOPCH)
@@ -544,7 +546,7 @@ endfunction()
# IMPORTANT does not require wxBUILD_SAMPLES=ALL # IMPORTANT does not require wxBUILD_SAMPLES=ALL
# RES followed by WIN32 .rc files # 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_SUBDIR subdirectory in the samples/ folder to use as base
# wxSAMPLE_FOLDER IDE sub folder to be used for the samples # wxSAMPLE_FOLDER IDE sub folder to be used for the samples
function(wx_add_sample name) function(wx_add_sample name)
@@ -629,8 +631,6 @@ function(wx_add_sample name)
if(SAMPLE_DEFINITIONS) if(SAMPLE_DEFINITIONS)
target_compile_definitions(${target_name} PRIVATE ${SAMPLE_DEFINITIONS}) target_compile_definitions(${target_name} PRIVATE ${SAMPLE_DEFINITIONS})
endif() endif()
# Disable precompile headers for samples
target_compile_definitions(${target_name} PRIVATE NOPCH)
if(SAMPLE_DATA) if(SAMPLE_DATA)
# TODO: handle data files differently for OS X bundles # TODO: handle data files differently for OS X bundles
# Copy data files to output directory # Copy data files to output directory
@@ -667,6 +667,7 @@ function(wx_add_sample name)
wx_string_append(folder "/${SAMPLE_FOLDER}") wx_string_append(folder "/${SAMPLE_FOLDER}")
endif() endif()
wx_set_common_target_properties(${target_name}) wx_set_common_target_properties(${target_name})
wx_sample_enable_precomp(${target_name})
set_target_properties(${target_name} PROPERTIES set_target_properties(${target_name} PROPERTIES
FOLDER ${folder} FOLDER ${folder}
) )

View File

@@ -51,10 +51,12 @@ set(wxARCH_SUFFIX)
# TODO: include compiler version in wxCOMPILER_PREFIX ? # TODO: include compiler version in wxCOMPILER_PREFIX ?
if(WIN32) if(WIN32)
if(MSVC) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(wxCOMPILER_PREFIX "vc") set(wxCOMPILER_PREFIX "vc")
elseif(CMAKE_COMPILER_IS_GNUCXX) elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(wxCOMPILER_PREFIX "gcc") set(wxCOMPILER_PREFIX "gcc")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(wxCOMPILER_PREFIX "clang")
else() else()
message(FATAL_ERROR "Unknown WIN32 compiler type") message(FATAL_ERROR "Unknown WIN32 compiler type")
endif() endif()
@@ -74,7 +76,7 @@ if(MSVC OR MINGW)
endif() endif()
if(MSVC) 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}") set(wxPLATFORM_LIB_DIR "$<1:/>${wxCOMPILER_PREFIX}${wxARCH_SUFFIX}_${lib_suffix}")
else() else()
set(wxPLATFORM_LIB_DIR "/${wxCOMPILER_PREFIX}${wxARCH_SUFFIX}_${lib_suffix}") set(wxPLATFORM_LIB_DIR "/${wxCOMPILER_PREFIX}${wxARCH_SUFFIX}_${lib_suffix}")

View File

@@ -164,7 +164,17 @@ target_compile_definitions(wxscintilla PUBLIC
NO_CXX11_REGEX NO_CXX11_REGEX
__WX__ __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_add_library(stc ${STC_FILES})
wx_lib_include_directories(stc PRIVATE wx_lib_include_directories(stc PRIVATE

View File

@@ -403,7 +403,6 @@ if(WIN32)
set(wxUSE_WINRT_DEFAULT OFF) set(wxUSE_WINRT_DEFAULT OFF)
endif() endif()
wx_option(wxUSE_WINRT "enable WinRT support" ${wxUSE_WINRT_DEFAULT}) wx_option(wxUSE_WINRT "enable WinRT support" ${wxUSE_WINRT_DEFAULT})
endif() endif()
# this one is not really MSW-specific but it exists mainly to be turned off # this one is not really MSW-specific but it exists mainly to be turned off

View File

@@ -258,7 +258,7 @@ if(WIN32)
if(MSVC) if(MSVC)
wx_add_sample(flash) wx_add_sample(flash)
endif() 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(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(nativdlg nativdlg.cpp nativdlg.h resource.h RES nativdlg.rc)
wx_add_sample(oleauto DEPENDS wxUSE_OLE) wx_add_sample(oleauto DEPENDS wxUSE_OLE)

View File

@@ -310,7 +310,7 @@ if(NOT WIN32)
statfs(\"/\", &fs);" statfs(\"/\", &fs);"
HAVE_STATFS_DECL) HAVE_STATFS_DECL)
else() else()
# TODO: implment statvfs checks # TODO: implement statvfs checks
if(HAVE_STATVFS) if(HAVE_STATVFS)
set(WX_STATFS_T statvfs_t) set(WX_STATFS_T statvfs_t)
endif() endif()

View File

@@ -15,10 +15,10 @@
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/progdlg.h" #include "wx/progdlg.h"
#include "wx/stdpaths.h"
#include "wx/wx.h" #include "wx/wx.h"
#endif #endif
#include "wx/stdpaths.h"
#include "wx/taskbarbutton.h" #include "wx/taskbarbutton.h"
enum enum

View File

@@ -73,12 +73,15 @@ struct IShellItem : public IUnknown
#endif // #ifndef __IShellItem_INTERFACE_DEFINED__ #endif // #ifndef __IShellItem_INTERFACE_DEFINED__
#if defined(__VISUALC__) || !defined(__IShellItem_INTERFACE_DEFINED__)
// Define this GUID in any case, even when __IShellItem_INTERFACE_DEFINED__ is // 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, // 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 // 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. // clang complains about multiple definitions, so only define it unconditionally
// when using a Visual C compiler.
DEFINE_GUID(IID_IShellItem, DEFINE_GUID(IID_IShellItem,
0x43826D1E, 0xE718, 0x42EE, 0xBC, 0x55, 0xA1, 0xE2, 0x61, 0xC3, 0x7B, 0xFE); 0x43826D1E, 0xE718, 0x42EE, 0xBC, 0x55, 0xA1, 0xE2, 0x61, 0xC3, 0x7B, 0xFE);
#endif
struct IShellItemFilter; struct IShellItemFilter;
struct IFileDialogEvents; struct IFileDialogEvents;

View File

@@ -1530,7 +1530,9 @@ void wxAMMediaBackend::Move(int WXUNUSED(x), int WXUNUSED(y),
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void wxAMMediaEvtHandler::OnActiveX(wxActiveXEvent& event) 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<unsigned long>(event.GetDispatchId()))
{ {
case 0x00000001: // statechange in IActiveMovie case 0x00000001: // statechange in IActiveMovie
case 0x00000bc4: // playstatechange in IMediaPlayer case 0x00000bc4: // playstatechange in IMediaPlayer