Browse Source

Merge pull request #2997 from Alexander-Wilms/fix-ios-pch

Enable ccache for iOS and MSVC builds
Nordsoft91 2 years ago
parent
commit
aed2e360ba

+ 1 - 8
.github/workflows/github.yml

@@ -103,7 +103,7 @@ jobs:
             test: 0
             pack: 1
             extension: ipa
-            preset: ios-release-conan
+            preset: ios-release-conan-ccache
             conan_profile: ios-arm64
             conan_options: --options with_apple_system_libs=True
           - platform: msvc
@@ -159,7 +159,6 @@ jobs:
         VCMI_BUILD_PLATFORM: x64
 
     - name: ccache
-      if: startsWith(matrix.preset, 'ios') != true
       uses: hendrikmuhs/[email protected]
       with:
           key: ${{ matrix.preset }}
@@ -203,15 +202,9 @@ jobs:
         PULL_REQUEST: ${{ github.event.pull_request.number }}
 
     - name: CMake Preset with ccache
-      if: startsWith(matrix.preset, 'ios') != true
       run: |
         cmake -DCMAKE_CXX_COMPILER_LAUNCHER=ccache --preset ${{ matrix.preset }}
 
-    - name: CMake Preset without ccache
-      if: startsWith(matrix.preset, 'ios')
-      run: |
-        cmake --preset ${{ matrix.preset }}
-
     - name: Build Preset
       run: |
         cmake --build --preset ${{matrix.preset}}

+ 41 - 0
CMakeLists.txt

@@ -79,6 +79,30 @@ if(NOT APPLE_IOS AND NOT ANDROID)
 	option(ENABLE_MONOLITHIC_INSTALL "Install everything in single directory on Linux and Mac" OFF)
 endif()
 
+# On Linux, use -DCMAKE_CXX_COMPILER_LAUNCHER=ccache instead.
+# The XCode and MSVC builds each require some more configuration, which is enabled by the following option:
+if(MSVC OR (CMAKE_GENERATOR STREQUAL "Xcode"))
+  option(ENABLE_CCACHE "Speed up recompilation by caching previous compilations" ON)
+endif()
+
+if(ENABLE_CCACHE AND (CMAKE_GENERATOR STREQUAL "Xcode"))
+	find_program(CCACHE ccache REQUIRED)
+	if(CCACHE)
+		# https://stackoverflow.com/a/36515503/2278742
+		# Set up wrapper scripts
+		configure_file(xcode/launch-c.in   xcode/launch-c)
+		configure_file(xcode/launch-cxx.in xcode/launch-cxx)
+		execute_process(COMMAND chmod a+rx
+												"${CMAKE_BINARY_DIR}/xcode/launch-c"
+												"${CMAKE_BINARY_DIR}/xcode/launch-cxx")
+		# Set Xcode project attributes to route compilation through our scripts
+		set(CMAKE_XCODE_ATTRIBUTE_CC         	"${CMAKE_BINARY_DIR}/xcode/launch-c")
+		set(CMAKE_XCODE_ATTRIBUTE_CXX        	"${CMAKE_BINARY_DIR}/xcode/launch-cxx")
+		set(CMAKE_XCODE_ATTRIBUTE_LD         	"${CMAKE_BINARY_DIR}/xcode/launch-c")
+		set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS 	"${CMAKE_BINARY_DIR}/xcode/launch-cxx")
+	endif()
+endif()
+
 # Allow to pass package name from Travis CI
 set(PACKAGE_NAME_SUFFIX "" CACHE STRING "Suffix for CPack package name")
 set(PACKAGE_FILE_NAME "" CACHE STRING "Override for CPack package filename")
@@ -237,6 +261,23 @@ if(MINGW OR MSVC)
 	set(CMAKE_SHARED_LIBRARY_PREFIX "")
 
 	if(MSVC)
+		if(ENABLE_CCACHE)
+			# https://github.com/ccache/ccache/discussions/1154#discussioncomment-3611387
+			find_program(CCACHE ccache REQUIRED)
+			if (CCACHE)
+				file(COPY_FILE
+					${CCACHE} ${CMAKE_BINARY_DIR}/cl.exe
+					ONLY_IF_DIFFERENT)
+
+				set(CMAKE_VS_GLOBALS
+					"CLToolExe=cl.exe"
+					"CLToolPath=${CMAKE_BINARY_DIR}"
+					"TrackFileAccess=false"
+					"UseMultiToolTask=true"
+				)
+			endif()
+		endif()
+
 		add_definitions(-DBOOST_ALL_NO_LIB)
 		add_definitions(-DBOOST_ALL_DYN_LINK)
 		set(Boost_USE_STATIC_LIBS OFF)

+ 14 - 1
CMakePresets.json

@@ -84,7 +84,6 @@
             "cacheVariables": {
                 "CMAKE_BUILD_TYPE": "Debug",
                 "ENABLE_LUA" : "ON",
-                "ENABLE_PCH" : "OFF",
                 "CMAKE_C_COMPILER": "/usr/bin/gcc",
                 "CMAKE_CXX_COMPILER": "/usr/bin/g++"
             }
@@ -223,6 +222,15 @@
                 "ENABLE_PCH" : "ON"
             }
         },
+        {
+            "name": "ios-release-conan-ccache",
+            "displayName": "iOS+Conan release using ccache",
+            "description": "VCMI iOS release using Conan and ccache",
+            "inherits": "ios-release-conan",
+            "cacheVariables": {
+                "ENABLE_PCH" : "OFF"
+            }
+        },
         {
             "name": "ios-release-legacy",
             "displayName": "iOS release using legacy dependencies",
@@ -331,6 +339,11 @@
                 "CODE_SIGNING_ALLOWED_FOR_APPS=NO"
             ]
         },
+        {
+            "name": "ios-release-conan-ccache",
+            "configurePreset": "ios-release-conan-ccache",
+            "inherits": "ios-release-conan"
+        },
         {
             "name": "ios-release-legacy",
             "configurePreset": "ios-release-legacy",

+ 1 - 0
client/CFocusableHelper.cpp

@@ -9,6 +9,7 @@
  */
 #include "CFocusableHelper.h"
 #include "../Global.h"
+#include "StdInc.h"
 #include "widgets/TextControls.h"
 
 void removeFocusFromActiveInput()

+ 1 - 0
client/ios/startSDL.mm

@@ -8,6 +8,7 @@
  *
  */
 #import "startSDL.h"
+#include "StdInc.h"
 #import "GameChatKeyboardHandler.h"
 
 #include "../Global.h"

+ 1 - 0
client/ios/utils.mm

@@ -8,6 +8,7 @@
  *
  */
 
+#include "StdInc.h"
 #include "utils.h"
 
 #import <UIKit/UIKit.h>

+ 3 - 0
xcode/launch-c.in

@@ -0,0 +1,3 @@
+#!/bin/sh
+export CCACHE_CPP2=true
+ccache clang "$@"

+ 3 - 0
xcode/launch-cxx.in

@@ -0,0 +1,3 @@
+#!/bin/sh
+export CCACHE_CPP2=true
+ccache clang++ "$@"