Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Commit b36b621

Browse files
committed
cmake: improve compile time
We can use precompiled headers to improve compile time significantly. However this uses more memory, so we have to add a hack to keep the CI builds working.
1 parent a497ce8 commit b36b621

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ cmake_minimum_required(VERSION 3.16)
22
project(winsdk)
33

44
file(GLOB sources "${CMAKE_CURRENT_SOURCE_DIR}/pywinrt/${CMAKE_PROJECT_NAME}/src/*.cpp")
5-
foreach(file ${sources})
6-
message(${file})
7-
endforeach()
5+
6+
file(GLOB headers RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
7+
"cppwinrt/*.h"
8+
"cppwinrt/impl/*.h"
9+
"pywinrt/winrt/src/*.h"
10+
)
811

912
set(CMAKE_CXX_STANDARD 17)
1013
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -20,10 +23,17 @@ find_package (Python3 ${PYTHON_BASE_VERSION} EXACT COMPONENTS Interpreter Develo
2023

2124
Python3_add_library (_winrt MODULE ${sources})
2225
set_target_properties(_winrt PROPERTIES LIBRARY_OUTPUT_NAME_DEBUG _winrt_d)
23-
target_precompile_headers(_winrt PRIVATE <winrt/base.h> [["pybase.h"]])
26+
target_precompile_headers(_winrt PRIVATE ${headers})
2427
target_include_directories(_winrt PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/cppwinrt" "${CMAKE_CURRENT_SOURCE_DIR}/pywinrt/${CMAKE_PROJECT_NAME}/src")
2528
target_link_libraries(_winrt PRIVATE onecore)
2629

30+
if($ENV{CI})
31+
# CI has limited resources (runs out of heap space), so we limit the number
32+
# of concurrent processes to combat this
33+
set_property(GLOBAL PROPERTY JOB_POOLS compile_job=2)
34+
set_property(TARGET _winrt PROPERTY JOB_POOL_COMPILE compile_job)
35+
endif()
36+
2737
string(REGEX REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
2838
# TODO: re-enable /GL and /LTCG when we get a bigger build machine
2939
# string(APPEND CMAKE_MODULE_LINKER_FLAGS " /LTCG:STATUS")

0 commit comments

Comments
 (0)