all: optimize build

This commit is contained in:
outfoxxed 2024-11-05 04:15:17 -08:00
parent 1168879d6d
commit 7ffce72b31
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
51 changed files with 1526 additions and 1277 deletions

85
cmake/pch.cmake Normal file
View file

@ -0,0 +1,85 @@
# pch breaks clang-tidy..... somehow
if (NOT NO_PCH)
file(GENERATE
OUTPUT ${CMAKE_BINARY_DIR}/pchstub.cpp
CONTENT "// intentionally empty"
)
endif()
function (qs_pch target)
if (NO_PCH)
return()
endif()
cmake_parse_arguments(PARSE_ARGV 1 arg "" "SET" "")
if ("${arg_SET}" STREQUAL "")
set(arg_SET "common")
endif()
target_precompile_headers(${target} REUSE_FROM "qs-pchset-${arg_SET}")
endfunction()
function (qs_module_pch target)
qs_pch(${target} ${ARGN})
qs_pch("${target}plugin" SET plugin)
qs_pch("${target}plugin_init" SET plugin)
endfunction()
function (qs_add_pchset SETNAME)
if (NO_PCH)
return()
endif()
cmake_parse_arguments(PARSE_ARGV 1 arg "" "" "HEADERS;DEPENDENCIES")
set(LIBNAME "qs-pchset-${SETNAME}")
add_library(${LIBNAME} ${CMAKE_BINARY_DIR}/pchstub.cpp)
target_link_libraries(${LIBNAME} ${arg_DEPENDENCIES})
target_precompile_headers(${LIBNAME} PUBLIC ${arg_HEADERS})
endfunction()
set(COMMON_PCH_SET
<chrono>
<memory>
<vector>
<qdebug.h>
<qobject.h>
<qmetatype.h>
<qstring.h>
<qchar.h>
<qlist.h>
<qabstractitemmodel.h>
)
qs_add_pchset(common
DEPENDENCIES Qt::Quick
HEADERS ${COMMON_PCH_SET}
)
qs_add_pchset(large
DEPENDENCIES Qt::Quick
HEADERS
${COMMON_PCH_SET}
<qiodevice.h>
<qevent.h>
<qcoreapplication.h>
<qqmlengine.h>
<qquickitem.h>
<qquickwindow.h>
<qcolor.h>
<qdir.h>
<qtimer.h>
<qabstractitemmodel.h>
)
# including qplugin.h directly will cause required symbols to disappear
qs_add_pchset(plugin
DEPENDENCIES Qt::Qml
HEADERS
<qobject.h>
<qjsonobject.h>
<qpointer.h>
)

20
cmake/util.cmake Normal file
View file

@ -0,0 +1,20 @@
function (qs_append_qmldir target text)
get_property(qmldir_content TARGET ${target} PROPERTY _qt_internal_qmldir_content)
if ("${qmldir_content}" STREQUAL "")
message(WARNING "qs_append_qmldir depends on private Qt cmake code, which has broken.")
return()
endif()
set_property(TARGET ${target} APPEND_STRING PROPERTY _qt_internal_qmldir_content ${text})
endfunction()
# DEPENDENCIES introduces a cmake dependency which we don't need with static modules.
# This greatly improves comp speed by not introducing those dependencies.
function (qs_add_module_deps_light target)
foreach (dep IN LISTS ARGN)
string(APPEND qmldir_extra "depends ${dep}\n")
endforeach()
qs_append_qmldir(${target} "${qmldir_extra}")
endfunction()