Skip to content

Commit a3bfa6f

Browse files
committed
cmake: ccache
1 parent af8e6b0 commit a3bfa6f

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ OCV_OPTION(INSTALL_TESTS "Install accuracy and performance test binar
217217

218218
# OpenCV build options
219219
# ===================================================
220+
OCV_OPTION(ENABLE_CCACHE "Use ccache" (UNIX AND NOT IOS AND (CMAKE_GENERATOR MATCHES "Makefile" OR CMAKE_GENERATOR MATCHES "Ninja")) )
220221
OCV_OPTION(ENABLE_DYNAMIC_CUDA "Enabled dynamic CUDA linkage" ON IF ANDROID )
221222
OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers" ON IF (NOT IOS) )
222223
OCV_OPTION(ENABLE_SOLUTION_FOLDERS "Solution folder in Visual Studio or in other IDEs" (MSVC_IDE OR CMAKE_GENERATOR MATCHES Xcode) IF (CMAKE_VERSION VERSION_GREATER "2.8.0") )
@@ -731,6 +732,7 @@ else()
731732
status(" Linker flags (Release):" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_RELEASE})
732733
status(" Linker flags (Debug):" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_DEBUG})
733734
endif()
735+
status(" ccache:" CMAKE_COMPILER_IS_CCACHE THEN YES ELSE NO)
734736
status(" Precompiled headers:" PCHSupport_FOUND AND ENABLE_PRECOMPILED_HEADERS THEN YES ELSE NO)
735737

736738
# ========================== OpenCV modules ==========================

cmake/OpenCVCompilerOptions.cmake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
if(ENABLE_CCACHE AND NOT CMAKE_COMPILER_IS_CCACHE)
2+
# This works fine with Unix Makefiles and Ninja generators
3+
find_host_program(CCACHE_PROGRAM ccache)
4+
if(CCACHE_PROGRAM)
5+
message(STATUS "Looking for ccache - found (${CCACHE_PROGRAM})")
6+
get_property(__OLD_RULE_LAUNCH_COMPILE GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
7+
if(__OLD_RULE_LAUNCH_COMPILE)
8+
message(STATUS "Can't replace CMake compiler launcher")
9+
else()
10+
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
11+
# NOTE: Actually this check doesn't work as expected.
12+
# "RULE_LAUNCH_COMPILE" is ignored by CMake during try_compile() step.
13+
# ocv_check_compiler_flag(CXX "" IS_CCACHE_WORKS)
14+
set(IS_CCACHE_WORKS 1)
15+
if(IS_CCACHE_WORKS)
16+
set(CMAKE_COMPILER_IS_CCACHE 1)
17+
else()
18+
message(STATUS "Unable to compile program with enabled ccache, reverting...")
19+
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${__OLD_RULE_LAUNCH_COMPILE}")
20+
endif()
21+
else()
22+
message(STATUS "Looking for ccache - not found")
23+
endif()
24+
endif()
25+
endif()
26+
27+
if((CMAKE_COMPILER_IS_CLANGCXX OR CMAKE_COMPILER_IS_CLANGCC OR CMAKE_COMPILER_IS_CCACHE) AND NOT CMAKE_GENERATOR MATCHES "Xcode")
28+
set(ENABLE_PRECOMPILED_HEADERS OFF CACHE BOOL "" FORCE)
29+
endif()
30+
131
if(MINGW OR (X86 AND UNIX AND NOT APPLE))
232
# mingw compiler is known to produce unstable SSE code with -O3 hence we are trying to use -O2 instead
333
if(CMAKE_COMPILER_IS_GNUCXX)
@@ -111,6 +141,10 @@ if(CMAKE_COMPILER_IS_GNUCXX)
111141
add_extra_compiler_option(-pthread)
112142
endif()
113143

144+
if(CMAKE_COMPILER_IS_CLANGCXX)
145+
add_extra_compiler_option(-Qunused-arguments)
146+
endif()
147+
114148
if(OPENCV_WARNINGS_ARE_ERRORS)
115149
add_extra_compiler_option(-Werror)
116150
endif()

cmake/OpenCVDetectCXXCompiler.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
1414
set(CMAKE_COMPILER_IS_CLANGCC 1)
1515
endif()
1616

17-
if((CMAKE_COMPILER_IS_CLANGCXX OR CMAKE_COMPILER_IS_CLANGCC) AND NOT CMAKE_GENERATOR MATCHES "Xcode")
18-
set(ENABLE_PRECOMPILED_HEADERS OFF CACHE BOOL "" FORCE)
19-
endif()
20-
2117
# ----------------------------------------------------------------------------
2218
# Detect Intel ICC compiler -- for -fPIC in 3rdparty ( UNIX ONLY ):
2319
# see include/opencv/cxtypes.h file for related ICC & CV_ICC defines.

0 commit comments

Comments
 (0)