Skip to content

Commit 7157fad

Browse files
Setup precompiled header for all platforms (#20510)
* Update CMakeLists.txt * Update CMakeLists.txt * Update CMakeLists.txt
1 parent f888277 commit 7157fad

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

cocos/CMakeLists.txt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,10 @@ if(XCODE OR VS)
148148
cocos_mark_code_files("cocos2d")
149149
endif()
150150

151-
if(WINDOWS)
152-
# precompiled header. Compilation time speedup ~4x.
153-
target_sources(cocos2d PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/precheader.cpp")
154-
set_target_properties(cocos2d PROPERTIES COMPILE_FLAGS "/Yuprecheader.h /FIprecheader.h")
155-
set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/precheader.cpp" PROPERTIES COMPILE_FLAGS "/Ycprecheader.h")
156-
# compile c as c++. needed for precompiled header
157-
set_source_files_properties(${COCOS_SPINE_SRC} base/ccFPSImages.c PROPERTIES LANGUAGE CXX)
151+
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
152+
message("CMake 3.16 target_precompile_headers")
153+
target_precompile_headers(cocos2d PRIVATE
154+
"$<$<COMPILE_LANGUAGE:CXX>:cocos2d.h>")
158155
endif()
159156

160157
#if(XCODE)

tests/cpp-tests/CMakeLists.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,8 @@ if(LINUX OR WINDOWS)
425425
cocos_copy_target_res(${APP_NAME} LINK_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER})
426426
endif()
427427

428-
if(WINDOWS)
429-
# precompiled header. Compilation time speedup ~4x.
430-
target_sources(${APP_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/Classes/precheader.cpp")
431-
set_target_properties(${APP_NAME} PROPERTIES COMPILE_FLAGS "/Yuprecheader.h /FIprecheader.h")
432-
set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/Classes/precheader.cpp" PROPERTIES COMPILE_FLAGS "/Ycprecheader.h")
433-
endif()
428+
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
429+
message("CMake 3.16 target_precompile_headers")
430+
target_precompile_headers(${APP_NAME} PRIVATE
431+
"$<$<COMPILE_LANGUAGE:CXX>:precheader.h>")
432+
endif()

0 commit comments

Comments
 (0)