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.
This commit is contained in:
Maarten Bent 2018-08-17 19:49:38 +02:00
parent 41d6bc579a
commit 61500907ee
2 changed files with 21 additions and 21 deletions

View File

@ -314,25 +314,21 @@ 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})
endif()
set_target_properties(${target_name} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE) set_target_properties(${target_name} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
cotire(${target_name}) cotire(${target_name})
endif()
endif()
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
COTIRE_CXX_PREFIX_HEADER_INIT "${wxSOURCE_DIR}/tests/testprec.h")
wx_target_enable_precomp(${target_name})
elseif(MSVC) elseif(MSVC)
target_compile_definitions(${target_name} PRIVATE NOPCH) target_compile_definitions(${target_name} PRIVATE NOPCH)
endif() endif()
@ -341,10 +337,7 @@ endmacro()
# Enable precompiled headers for samples # Enable precompiled headers for samples
macro(wx_sample_enable_precomp target_name) macro(wx_sample_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}/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})
elseif(MSVC) elseif(MSVC)
target_compile_definitions(${target_name} PRIVATE NOPCH) target_compile_definitions(${target_name} PRIVATE NOPCH)
endif() endif()
@ -355,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)

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