Skip to content

Commit eea4397

Browse files
committed
Merge pull request opencv#19332 from alalek:xcode_ccache
2 parents a122a53 + 8215380 commit eea4397

File tree

5 files changed

+54
-8
lines changed

5 files changed

+54
-8
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ OCV_OPTION(INSTALL_TESTS "Install accuracy and performance test binar
477477

478478
# OpenCV build options
479479
# ===================================================
480-
OCV_OPTION(ENABLE_CCACHE "Use ccache" (UNIX AND NOT IOS AND (CMAKE_GENERATOR MATCHES "Makefile" OR CMAKE_GENERATOR MATCHES "Ninja")) )
480+
OCV_OPTION(ENABLE_CCACHE "Use ccache" (UNIX AND (CMAKE_GENERATOR MATCHES "Makefile" OR CMAKE_GENERATOR MATCHES "Ninja" OR CMAKE_GENERATOR MATCHES "Xcode")) )
481481
OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers" MSVC IF (MSVC OR (NOT IOS AND NOT CMAKE_CROSSCOMPILING) ) )
482482
OCV_OPTION(ENABLE_SOLUTION_FOLDERS "Solution folder in Visual Studio or in other IDEs" (MSVC_IDE OR CMAKE_GENERATOR MATCHES Xcode) )
483483
OCV_OPTION(ENABLE_PROFILING "Enable profiling in the GCC compiler (Add flags: -g -pg)" OFF IF CV_GCC )

cmake/OpenCVCompilerOptions.cmake

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,27 @@ function(access_CMAKE_COMPILER_IS_CCACHE)
88
endif()
99
endfunction()
1010
variable_watch(CMAKE_COMPILER_IS_CCACHE access_CMAKE_COMPILER_IS_CCACHE)
11-
if(ENABLE_CCACHE AND NOT OPENCV_COMPILER_IS_CCACHE AND NOT CMAKE_GENERATOR MATCHES "Xcode")
11+
if(ENABLE_CCACHE AND NOT OPENCV_COMPILER_IS_CCACHE)
1212
# This works fine with Unix Makefiles and Ninja generators
1313
find_host_program(CCACHE_PROGRAM ccache)
1414
if(CCACHE_PROGRAM)
1515
message(STATUS "Looking for ccache - found (${CCACHE_PROGRAM})")
1616
get_property(__OLD_RULE_LAUNCH_COMPILE GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
17-
if(__OLD_RULE_LAUNCH_COMPILE)
17+
if(CMAKE_GENERATOR MATCHES "Xcode")
18+
configure_file("${CMAKE_CURRENT_LIST_DIR}/templates/xcode-launch-c.in" "${CMAKE_BINARY_DIR}/xcode-launch-c")
19+
configure_file("${CMAKE_CURRENT_LIST_DIR}/templates/xcode-launch-cxx.in" "${CMAKE_BINARY_DIR}/xcode-launch-cxx")
20+
execute_process(COMMAND chmod a+rx
21+
"${CMAKE_BINARY_DIR}/xcode-launch-c"
22+
"${CMAKE_BINARY_DIR}/xcode-launch-cxx"
23+
)
24+
# Xcode project attributes
25+
set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_BINARY_DIR}/xcode-launch-c")
26+
set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_BINARY_DIR}/xcode-launch-cxx")
27+
set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/xcode-launch-c")
28+
set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/xcode-launch-cxx")
29+
set(OPENCV_COMPILER_IS_CCACHE 1)
30+
message(STATUS "ccache: enable support through Xcode project properties")
31+
elseif(__OLD_RULE_LAUNCH_COMPILE)
1832
message(STATUS "Can't replace CMake compiler launcher")
1933
else()
2034
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")

cmake/templates/xcode-launch-c.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
# https://crascit.com/2016/04/09/using-ccache-with-cmake/
3+
4+
# Xcode generator doesn't include the compiler as the
5+
# first argument, Ninja and Makefiles do. Handle both cases.
6+
if [[ "$1" = "${CMAKE_C_COMPILER}" ]] ; then
7+
shift
8+
fi
9+
10+
export CCACHE_CPP2=true
11+
exec "${CCACHE_PROGRAM}" "${CMAKE_C_COMPILER}" "$@"

cmake/templates/xcode-launch-cxx.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
# https://crascit.com/2016/04/09/using-ccache-with-cmake/
3+
4+
# Xcode generator doesn't include the compiler as the
5+
# first argument, Ninja and Makefiles do. Handle both cases.
6+
if [[ "$1" = "${CMAKE_CXX_COMPILER}" ]] ; then
7+
shift
8+
fi
9+
10+
export CCACHE_CPP2=true
11+
exec "${CCACHE_PROGRAM}" "${CMAKE_CXX_COMPILER}" "$@"

platforms/ios/cmake/Toolchains/common-ios-toolchain.cmake

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,20 @@ set(CMAKE_CXX_COMPILER_ABI ELF)
160160
set(CMAKE_CXX_COMPILER_WORKS TRUE)
161161
set(CMAKE_C_COMPILER_WORKS TRUE)
162162

163-
# Search for programs in the build host directories
164-
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
165-
# for libraries and headers in the target directories
166-
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
167-
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
163+
if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY)
164+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
165+
endif()
166+
167+
if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE)
168+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
169+
endif()
170+
171+
if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE)
172+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
173+
endif()
174+
175+
if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM)
176+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
177+
endif()
168178

169179
toolchain_save_config(IOS_ARCH IPHONEOS_DEPLOYMENT_TARGET)

0 commit comments

Comments
 (0)