Skip to content

Commit

Permalink
refactor compiler cache setting
Browse files Browse the repository at this point in the history
for covering the case of ccache and clcache
  • Loading branch information
vigsterkr committed Mar 7, 2018
1 parent d0a9253 commit 4194b99
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
41 changes: 30 additions & 11 deletions CMakeLists.txt
Expand Up @@ -64,19 +64,38 @@ IF(NOT ("${BUILD_TYPE_UC}" STREQUAL "DISTRIBUTION"))
SET(CMAKE_CXX_FLAGS "")
ENDIF(NOT ("${BUILD_TYPE_UC}" STREQUAL "DISTRIBUTION"))

# CCACHE
OPTION(ENABLE_CCACHE "Enable ccache for compilation" ON)
FIND_PACKAGE(CCache)
if(CCACHE_FOUND AND ENABLE_CCACHE)
SET(CCACHE "ccache" CACHE STRING "ccache")
SET(CMAKE_C_COMPILER_ARG1 ${CMAKE_C_COMPILER})
SET(CMAKE_C_COMPILER ${CCACHE})
SET(CMAKE_CXX_COMPILER_ARG1 ${CMAKE_CXX_COMPILER})
SET(CMAKE_CXX_COMPILER ${CCACHE})
SET(CMAKE_C_FLAGS "${CCACHE_FLAGS} ${CMAKE_C_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CCACHE_FLAGS} ${CMAKE_CXX_FLAGS}")
# compilation cache
if (("${CMAKE_GENERATOR}" STREQUAL "Unix Makefiles") OR
("${CMAKE_GENERATOR}" STREQUAL "NMake Makefiles") OR
("${CMAKE_GENERATOR}" STREQUAL "Ninja"))
OPTION(ENABLE_COMPILER_CACHE "Enable cache for compilation" ON)
endif()

if (ENABLE_COMPILER_CACHE)
if (MSVC)
find_program(CLCACHE_FOUND clcache)
if (CLCACHE_FOUND)
set(COMPILER_CACHE_EXECUTABLE CLCACHE_FOUND)
endif ()
else()
FIND_PACKAGE(CCache)
if (CCACHE_FOUND)
SET(COMPILER_CACHE_EXECUTABLE "ccache")
SET(CMAKE_C_FLAGS "${CCACHE_FLAGS} ${CMAKE_C_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CCACHE_FLAGS} ${CMAKE_CXX_FLAGS}")
endif()
endif()

if (COMPILER_CACHE_EXECUTABLE)
foreach(LANG C CXX)
if(NOT DEFINED CMAKE_${LANG}_COMPILER_LAUNCHER AND NOT CMAKE_${LANG}_COMPILER MATCHES ".*/${COMPILER_CACHE_EXECUTABLE}$")
message(STATUS "Enabling ${COMPILER_CACHE_EXECUTABLE} for ${LANG}")
set(CMAKE_${LANG}_COMPILER_LAUNCHER ${COMPILER_CACHE_EXECUTABLE} CACHE STRING "")
endif()
endforeach()
endif()
endif ()

################# VARIABLES #####################
SET(INCLUDES "")

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -7,7 +7,7 @@ cache:
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
VSVER: Visual Studio 14 2015 Win64
GENERATOR: Ninja
PYTHON: "3.6"
APPVEYOR_SAVE_CACHE_ON_ERROR: true

Expand Down
8 changes: 6 additions & 2 deletions scripts/appveyor-setup.bat
Expand Up @@ -16,8 +16,12 @@ conda info -a
@rem Use clcache for faster builds
pip install -q git+https://github.com/frerich/clcache.git
clcache -s
set CC=clcache
set CXX=clcache
set CLCACHE_SERVER=1
set CLCACHE_HARDLINK=1
powershell.exe -Command "Start-Process clcache-server"

conda create -n shogun -q -y python=%PYTHON% ^
setuptools numpy scipy eigen rxcpp ^
cmake snappy zlib ctags ply ninja

call activate shogun
9 changes: 2 additions & 7 deletions scripts/msvc-build.bat
@@ -1,17 +1,12 @@
@echo on

conda create -n shogun -q -y python=%PYTHON% ^
setuptools numpy scipy eigen rxcpp ^
cmake snappy zlib ctags ply
call activate shogun

mkdir %APPVEYOR_BUILD_FOLDER%\build
pushd %APPVEYOR_BUILD_FOLDER%\build

cmake -G "%VSVER%" ^
cmake -G "%GENERATOR%" ^
-DCMAKE_BUILD_TYPE=%CONFIGURATION% ^
-DCMAKE_INSTALL_PREFIX=%CONDA_PREFIX%\Library ^
-DBUILD_META_EXAMPLES=OFF ^
-DENABLE_TESTING=ON .. || exit /B

cmake --build . --target install --config %CONFIGURATION% -- /maxcpucount:2 || exit /B
cmake --build . --target install --config %CONFIGURATION% -- -j2 || exit /B

0 comments on commit 4194b99

Please sign in to comment.