From 61500907ee815944f029dd86639b3aa08c11dff7 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Fri, 17 Aug 2018 19:49:38 +0200 Subject: [PATCH] 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