Refactor cmake ccache support and support MSVC.

Don't disable ccache for msys+ninja anymore, since the mingw ccache
works now and there is no reason to use the msys ccache anymore.

Use RULE_LAUNCH_COMPILE only on cmake versions < 3.4.0, because this
currently breaks resource compilation with visual studio and the windows
native ccache from chocolatey, this needs to be fixed in ccache.

On cmake 3.4.0 and greater, set the variables
CMAKE_<LANG>_COMPILER_LAUNCHER instead. This has the effect of using
ccache for C, C++ and nasm, but not for the resource file, avoiding the
problem with visual studio, which has a more recent cmake. This must be
done before the project() call.

TODO: Currently the Visual Studio build with ccache from chocolatey
works correctly, ccache is being invoked from ninja, but no cache files
are being created. This is being followed up with the chocolatey package
maintainer and upstream if necessary. The resource compiler issue also
needs to be fixed upstream.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2020-07-30 22:27:21 +00:00
parent 2fe1c5711b
commit 299362b3cf
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
1 changed files with 19 additions and 12 deletions

View File

@ -46,6 +46,25 @@ if(VCPKG_TARGET_TRIPLET MATCHES -static OR CMAKE_TOOLCHAIN_FILE MATCHES "mxe|-st
set(VBAM_STATIC_DEFAULT ON)
endif()
# Use ccache if available and not already enabled on the command line.
# This has to be done before the project() call.
if(NOT (CMAKE_CXX_COMPILER_LAUNCHER OR CMAKE_CXX_COMPILER MATCHES ccache))
find_program(CCACHE_EXECUTABLE ccache)
if(CCACHE_EXECUTABLE)
message(STATUS "Enabling ccache")
if(CMAKE_VERSION VERSION_LESS 3.4.0)
# FIXME: This method currently breaks for native ccache on windows
# with the visual studio resource compiler.
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_EXECUTABLE})
else()
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE} CACHE STRING "C compiler launcher" FORCE)
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE} CACHE STRING "C++ compiler launcher" FORCE)
set(CMAKE_ASM_NASM_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE} CACHE STRING "nasm assembler launcher" FORCE)
endif()
endif()
endif()
project(VBA-M C CXX)
cmake_minimum_required(VERSION 2.8.12)
@ -92,18 +111,6 @@ if(VBAM_STATIC)
endif()
endif()
# use ccache if available, and not already enabled on the command line
# but not with ninja and msys ccache on msys2
if(NOT (WIN32 AND NOT "$ENV{MSYSTEM_PREFIX}" STREQUAL "" AND CMAKE_GENERATOR STREQUAL Ninja))
if(NOT CMAKE_CXX_COMPILER_LAUNCHER AND NOT CMAKE_C_COMPILER_LAUNCHER)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
endif()
endif()
set(SSP_DEFAULT OFF)
option(ENABLE_SSP "Enable gcc stack protector support" ${SSP_DEFAULT})