CMake: Use target_precompile_headers when available
Keep using cotire for CMake versions older than 3.16, or when user specifies wxBUILD_PRECOMP=COTIRE. The scintilla headers need to be specified for target_precompile_headers to work. Enable it when the target has at least 2 source files (same as cotire does).
This commit is contained in:
parent
614d58bf38
commit
f4367b3fee
4 changed files with 20 additions and 22 deletions
|
|
@ -15,7 +15,9 @@ if(CMAKE_GENERATOR STREQUAL "Xcode")
|
|||
# include Obj-C files when using precompiled headers with Xcode
|
||||
set(COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS "" CACHE STRING "wxWidgets override of cotire exclude")
|
||||
endif()
|
||||
include(cotire) # For precompiled header handling
|
||||
if((wxBUILD_PRECOMP STREQUAL "ON" AND CMAKE_VERSION VERSION_LESS "3.16") OR (wxBUILD_PRECOMP STREQUAL "COTIRE"))
|
||||
include(cotire) # For precompiled header handling
|
||||
endif()
|
||||
include(CMakePrintHelpers)
|
||||
|
||||
# Use the MSVC/makefile naming convention, or the configure naming convention,
|
||||
|
|
@ -436,16 +438,22 @@ macro(wx_add_library name)
|
|||
endif()
|
||||
endmacro()
|
||||
|
||||
# Enable cotire for target, use optional second argument for prec. header
|
||||
macro(wx_target_enable_precomp target_name)
|
||||
# Enable precompiled headers for target
|
||||
macro(wx_target_enable_precomp target_name prec_header)
|
||||
if(wxBUILD_PRECOMP)
|
||||
target_compile_definitions(${target_name} PRIVATE WX_PRECOMP)
|
||||
if(${ARGC} GREATER 1 AND NOT ${ARGV1} STREQUAL "")
|
||||
set_target_properties(${target_name} PROPERTIES
|
||||
COTIRE_CXX_PREFIX_HEADER_INIT ${ARGV1})
|
||||
if(CMAKE_VERSION VERSION_LESS "3.16" OR wxBUILD_PRECOMP STREQUAL "COTIRE")
|
||||
set_target_properties(${target_name} PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT ${prec_header})
|
||||
set_target_properties(${target_name} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
|
||||
cotire(${target_name})
|
||||
else()
|
||||
get_target_property(target_source_files ${target_name} SOURCES)
|
||||
list(FILTER target_source_files INCLUDE REGEX ".*(.cpp|.cxx)$")
|
||||
list(LENGTH target_source_files target_source_count)
|
||||
if(target_source_count GREATER_EQUAL 2)
|
||||
target_precompile_headers(${target_name} PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${prec_header}>")
|
||||
endif()
|
||||
endif()
|
||||
set_target_properties(${target_name} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
|
||||
cotire(${target_name})
|
||||
elseif(MSVC)
|
||||
target_compile_definitions(${target_name} PRIVATE NOPCH)
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -582,7 +582,7 @@ if(DEFINED wxBUILD_PRECOMP_PREV AND NOT wxBUILD_PRECOMP STREQUAL wxBUILD_PRECOMP
|
|||
endif()
|
||||
set(wxBUILD_PRECOMP_PREV ${wxBUILD_PRECOMP} CACHE INTERNAL "")
|
||||
|
||||
if(wxBUILD_PRECOMP)
|
||||
if((wxBUILD_PRECOMP STREQUAL "ON" AND CMAKE_VERSION VERSION_LESS "3.16") OR (wxBUILD_PRECOMP STREQUAL "COTIRE"))
|
||||
if(DEFINED CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED)
|
||||
set(try_flags "-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED=${CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED}")
|
||||
endif()
|
||||
|
|
@ -614,4 +614,4 @@ if(wxBUILD_PRECOMP)
|
|||
message(WARNING "precompiled header (PCH) test failed, it will be turned off")
|
||||
wx_option_force_value(wxBUILD_PRECOMP OFF)
|
||||
endif()
|
||||
endif(wxBUILD_PRECOMP)
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -171,17 +171,7 @@ target_compile_definitions(wxscintilla PRIVATE
|
|||
LINK_LEXERS
|
||||
)
|
||||
|
||||
if(wxBUILD_PRECOMP)
|
||||
# The auto-generated header causes undefined members and identifiers in the
|
||||
# standard c++ headers when using clang.
|
||||
# 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}" MATCHES "Clang")
|
||||
set(wxSCINTILLA_PREC_HEADER "${wxSOURCE_DIR}/src/stc/scintilla/include/Scintilla.h")
|
||||
endif()
|
||||
wx_target_enable_precomp(wxscintilla ${wxSCINTILLA_PREC_HEADER})
|
||||
endif()
|
||||
|
||||
wx_target_enable_precomp(wxscintilla "${wxSOURCE_DIR}/src/stc/scintilla/include/Scintilla.h")
|
||||
wx_add_library(wxstc ${STC_FILES})
|
||||
wx_lib_include_directories(wxstc
|
||||
${wxSOURCE_DIR}/src/stc/scintilla/include
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ wx_option(wxBUILD_TESTS "Build console tests (CONSOLE_ONLY) or ALL" OFF
|
|||
STRINGS CONSOLE_ONLY ALL OFF)
|
||||
wx_option(wxBUILD_DEMOS "Build demos" OFF)
|
||||
wx_option(wxBUILD_BENCHMARKS "Build benchmarks" OFF)
|
||||
wx_option(wxBUILD_PRECOMP "Use precompiled headers")
|
||||
wx_option(wxBUILD_PRECOMP "Use precompiled headers" ON STRINGS ON OFF COTIRE)
|
||||
mark_as_advanced(wxBUILD_PRECOMP)
|
||||
wx_option(wxBUILD_INSTALL "Create install/uninstall target for wxWidgets")
|
||||
wx_option(wxBUILD_COMPATIBILITY
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue