mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 06:26:29 +08:00
cmake: support ccache with Xcode generator
This commit is contained in:
parent
68fb8dd873
commit
8215380336
@ -477,7 +477,7 @@ OCV_OPTION(INSTALL_TESTS "Install accuracy and performance test binar
|
|||||||
|
|
||||||
# OpenCV build options
|
# OpenCV build options
|
||||||
# ===================================================
|
# ===================================================
|
||||||
OCV_OPTION(ENABLE_CCACHE "Use ccache" (UNIX AND NOT IOS AND (CMAKE_GENERATOR MATCHES "Makefile" OR CMAKE_GENERATOR MATCHES "Ninja")) )
|
OCV_OPTION(ENABLE_CCACHE "Use ccache" (UNIX AND (CMAKE_GENERATOR MATCHES "Makefile" OR CMAKE_GENERATOR MATCHES "Ninja" OR CMAKE_GENERATOR MATCHES "Xcode")) )
|
||||||
OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers" MSVC IF (MSVC OR (NOT IOS AND NOT CMAKE_CROSSCOMPILING) ) )
|
OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers" MSVC IF (MSVC OR (NOT IOS AND NOT CMAKE_CROSSCOMPILING) ) )
|
||||||
OCV_OPTION(ENABLE_SOLUTION_FOLDERS "Solution folder in Visual Studio or in other IDEs" (MSVC_IDE OR CMAKE_GENERATOR MATCHES Xcode) )
|
OCV_OPTION(ENABLE_SOLUTION_FOLDERS "Solution folder in Visual Studio or in other IDEs" (MSVC_IDE OR CMAKE_GENERATOR MATCHES Xcode) )
|
||||||
OCV_OPTION(ENABLE_PROFILING "Enable profiling in the GCC compiler (Add flags: -g -pg)" OFF IF CV_GCC )
|
OCV_OPTION(ENABLE_PROFILING "Enable profiling in the GCC compiler (Add flags: -g -pg)" OFF IF CV_GCC )
|
||||||
|
@ -8,13 +8,27 @@ function(access_CMAKE_COMPILER_IS_CCACHE)
|
|||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
variable_watch(CMAKE_COMPILER_IS_CCACHE access_CMAKE_COMPILER_IS_CCACHE)
|
variable_watch(CMAKE_COMPILER_IS_CCACHE access_CMAKE_COMPILER_IS_CCACHE)
|
||||||
if(ENABLE_CCACHE AND NOT OPENCV_COMPILER_IS_CCACHE AND NOT CMAKE_GENERATOR MATCHES "Xcode")
|
if(ENABLE_CCACHE AND NOT OPENCV_COMPILER_IS_CCACHE)
|
||||||
# This works fine with Unix Makefiles and Ninja generators
|
# This works fine with Unix Makefiles and Ninja generators
|
||||||
find_host_program(CCACHE_PROGRAM ccache)
|
find_host_program(CCACHE_PROGRAM ccache)
|
||||||
if(CCACHE_PROGRAM)
|
if(CCACHE_PROGRAM)
|
||||||
message(STATUS "Looking for ccache - found (${CCACHE_PROGRAM})")
|
message(STATUS "Looking for ccache - found (${CCACHE_PROGRAM})")
|
||||||
get_property(__OLD_RULE_LAUNCH_COMPILE GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
|
get_property(__OLD_RULE_LAUNCH_COMPILE GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
|
||||||
if(__OLD_RULE_LAUNCH_COMPILE)
|
if(CMAKE_GENERATOR MATCHES "Xcode")
|
||||||
|
configure_file("${CMAKE_CURRENT_LIST_DIR}/templates/xcode-launch-c.in" "${CMAKE_BINARY_DIR}/xcode-launch-c")
|
||||||
|
configure_file("${CMAKE_CURRENT_LIST_DIR}/templates/xcode-launch-cxx.in" "${CMAKE_BINARY_DIR}/xcode-launch-cxx")
|
||||||
|
execute_process(COMMAND chmod a+rx
|
||||||
|
"${CMAKE_BINARY_DIR}/xcode-launch-c"
|
||||||
|
"${CMAKE_BINARY_DIR}/xcode-launch-cxx"
|
||||||
|
)
|
||||||
|
# Xcode project attributes
|
||||||
|
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")
|
||||||
|
set(OPENCV_COMPILER_IS_CCACHE 1)
|
||||||
|
message(STATUS "ccache: enable support through Xcode project properties")
|
||||||
|
elseif(__OLD_RULE_LAUNCH_COMPILE)
|
||||||
message(STATUS "Can't replace CMake compiler launcher")
|
message(STATUS "Can't replace CMake compiler launcher")
|
||||||
else()
|
else()
|
||||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
|
||||||
|
11
cmake/templates/xcode-launch-c.in
Normal file
11
cmake/templates/xcode-launch-c.in
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# https://crascit.com/2016/04/09/using-ccache-with-cmake/
|
||||||
|
|
||||||
|
# Xcode generator doesn't include the compiler as the
|
||||||
|
# first argument, Ninja and Makefiles do. Handle both cases.
|
||||||
|
if [[ "$1" = "${CMAKE_C_COMPILER}" ]] ; then
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
export CCACHE_CPP2=true
|
||||||
|
exec "${CCACHE_PROGRAM}" "${CMAKE_C_COMPILER}" "$@"
|
11
cmake/templates/xcode-launch-cxx.in
Normal file
11
cmake/templates/xcode-launch-cxx.in
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# https://crascit.com/2016/04/09/using-ccache-with-cmake/
|
||||||
|
|
||||||
|
# Xcode generator doesn't include the compiler as the
|
||||||
|
# first argument, Ninja and Makefiles do. Handle both cases.
|
||||||
|
if [[ "$1" = "${CMAKE_CXX_COMPILER}" ]] ; then
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
export CCACHE_CPP2=true
|
||||||
|
exec "${CCACHE_PROGRAM}" "${CMAKE_CXX_COMPILER}" "$@"
|
@ -160,10 +160,20 @@ set(CMAKE_CXX_COMPILER_ABI ELF)
|
|||||||
set(CMAKE_CXX_COMPILER_WORKS TRUE)
|
set(CMAKE_CXX_COMPILER_WORKS TRUE)
|
||||||
set(CMAKE_C_COMPILER_WORKS TRUE)
|
set(CMAKE_C_COMPILER_WORKS TRUE)
|
||||||
|
|
||||||
# Search for programs in the build host directories
|
if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY)
|
||||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||||
# for libraries and headers in the target directories
|
endif()
|
||||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
|
||||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||||
|
endif()
|
||||||
|
|
||||||
toolchain_save_config(IOS_ARCH IPHONEOS_DEPLOYMENT_TARGET)
|
toolchain_save_config(IOS_ARCH IPHONEOS_DEPLOYMENT_TARGET)
|
||||||
|
Loading…
Reference in New Issue
Block a user