From abc9125720ad3ece3d68daf260a5bee15fed0717 Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Sat, 27 Oct 2018 15:24:24 +0200 Subject: [PATCH] Improve ccache implementation Renamed the launch-c* scripts to make clear that they are supporting infrastructure for ccache, so maintainers know what the script is for without having to read it. Moved them into the admin directory, which contains other development-time resources. This also means that these scripts are no longer in the top-level directory of the unpacked tarball, where they might confuse users. ccache will still work for builds from the tarball, however. Eliminated temporary helper variables that didn't add value to how we use configure_file(). Renamed GMX_CACHE_.*_COMPILER variables to use CCACHE rather than CACHE, for consistency. This change would have broken build trees that used to work with ccache, because the wrapper scripts may not be regenerated because the old GMX_CACHE_* variables are defined. But changing to GMX_CCACHE_* has the side effect of fixing this because the new variables will be undefined in such build trees. Change-Id: I3b449251ee06adc8023ac1a58cb98a7b0be9bba5 --- launch-c.in => admin/ccache-wrapper-c.in | 4 +-- launch-cxx.in => admin/ccache-wrapper-cxx.in | 4 +-- cmake/gmxCcache.cmake | 40 +++++++++++++--------------- 3 files changed, 22 insertions(+), 26 deletions(-) rename launch-c.in => admin/ccache-wrapper-c.in (66%) rename launch-cxx.in => admin/ccache-wrapper-cxx.in (66%) diff --git a/launch-c.in b/admin/ccache-wrapper-c.in similarity index 66% rename from launch-c.in rename to admin/ccache-wrapper-c.in index 097a24b584..7cc68e9d66 100644 --- a/launch-c.in +++ b/admin/ccache-wrapper-c.in @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Set up compiler wrapper to make it easier to use ccache. +# Set up compiler wrapper used for ccache. # # Xcode generator doesn't include the compiler as the # first argument, Ninja and Makefiles do. Handle both cases. @@ -8,4 +8,4 @@ shift fi export CCACHE_CPP2=true -exec "${_c_launcher}" "${CMAKE_C_COMPILER}" "$@" +exec "${CCACHE_PROGRAM}" "${CMAKE_C_COMPILER}" "$@" diff --git a/launch-cxx.in b/admin/ccache-wrapper-cxx.in similarity index 66% rename from launch-cxx.in rename to admin/ccache-wrapper-cxx.in index ec1581147c..33308b9a13 100644 --- a/launch-cxx.in +++ b/admin/ccache-wrapper-cxx.in @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Set up compiler wrapper to make it easier to use ccache. +# Set up compiler wrapper used for ccache. # # Xcode generator doesn't include the compiler as the # first argument, Ninja and Makefiles do. Handle both cases. @@ -8,4 +8,4 @@ shift fi export CCACHE_CPP2=true -exec "${_cxx_launcher}" "${CMAKE_CXX_COMPILER}" "$@" +exec "${CCACHE_PROGRAM}" "${CMAKE_CXX_COMPILER}" "$@" diff --git a/cmake/gmxCcache.cmake b/cmake/gmxCcache.cmake index 7ffe32ae07..a4af1aba13 100644 --- a/cmake/gmxCcache.cmake +++ b/cmake/gmxCcache.cmake @@ -43,17 +43,15 @@ find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) # Check whether C compiler wrapper has been set up. - if(NOT DEFINED GMX_CACHE_C_COMPILER) + if(NOT DEFINED GMX_CCACHE_C_COMPILER) # Determine whether we have a cacheable compiler. set(_cacheable OFF) if (CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "AppleClang" OR CMAKE_C_COMPILER_ID MATCHES "Clang") message(STATUS "Setting up ccache wrapper for ${CMAKE_C_COMPILER_ID} C compiler ${CMAKE_C_COMPILER}") - set(_c_launcher "${CCACHE_PROGRAM}") - configure_file(launch-c.in ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/launch-c) - unset(_c_launcher) - file(COPY ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/launch-c + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/admin/ccache-wrapper-c.in ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ccache-wrapper-c) + file(COPY ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ccache-wrapper-c DESTINATION ${CMAKE_BINARY_DIR} FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE @@ -62,34 +60,32 @@ if(CCACHE_PROGRAM) else() message(STATUS "Disabling ccache set up. Not confirmed to work with compiler ID ${CMAKE_C_COMPILER_ID}.") endif() # GNU C compiler - set(GMX_CACHE_C_COMPILER ${_cacheable} CACHE INTERNAL "Whether the C compiler will be wrapped for caching.") + set(GMX_CCACHE_C_COMPILER ${_cacheable} CACHE INTERNAL "Whether the C compiler will be wrapped for caching.") unset(_cacheable) endif() # defined # Check whether we should use the wrapper. If so, set CMAKE variables. - if(GMX_CACHE_C_COMPILER) + if(GMX_CCACHE_C_COMPILER) if(CMAKE_GENERATOR STREQUAL "Xcode") # Set Xcode project attributes to route compilation and linking # through our scripts - set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_BINARY_DIR}/launch-c") - set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/launch-c") + set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_BINARY_DIR}/ccache-wrapper-c") + set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/ccache-wrapper-c") else() # Support Unix Makefiles and Ninja - set(CMAKE_C_COMPILER_LAUNCHER "${CMAKE_BINARY_DIR}/launch-c") + set(CMAKE_C_COMPILER_LAUNCHER "${CMAKE_BINARY_DIR}/ccache-wrapper-c") endif() - endif(GMX_CACHE_C_COMPILER) + endif() # Check whether CXX compiler wrapper has been set up - if(NOT DEFINED GMX_CACHE_CXX_COMPILER) + if(NOT DEFINED GMX_CCACHE_CXX_COMPILER) # Determine whether we have a cacheable compiler. set(_cacheable OFF) if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "AppleClang" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") message(STATUS "Setting up ccache wrapper for ${CMAKE_CXX_COMPILER_ID} CXX compiler ${CMAKE_CXX_COMPILER}") - set(_cxx_launcher "${CCACHE_PROGRAM}") - configure_file(launch-cxx.in ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/launch-cxx) - unset(_cxx_launcher) - file(COPY ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/launch-cxx + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/admin/ccache-wrapper-cxx.in ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ccache-wrapper-cxx) + file(COPY ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ccache-wrapper-cxx DESTINATION ${CMAKE_BINARY_DIR} FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE @@ -98,19 +94,19 @@ if(CCACHE_PROGRAM) else() message(STATUS "Skipping ccache set up. Not confirmed to work with compiler ID ${CMAKE_CXX_COMPILER_ID}.") endif() # GNU C++ compiler - set(GMX_CACHE_CXX_COMPILER ${_cacheable} CACHE INTERNAL "Whether the C++ compiler will be wrapped for caching.") + set(GMX_CCACHE_CXX_COMPILER ${_cacheable} CACHE INTERNAL "Whether the C++ compiler will be wrapped for caching.") unset(_cacheable) endif() # defined # Check whether we should use the wrapper. If so, set CMAKE variables. - if(GMX_CACHE_CXX_COMPILER) + if(GMX_CCACHE_CXX_COMPILER) if(CMAKE_GENERATOR STREQUAL "Xcode") # Set Xcode project attributes to route compilation and linking # through our scripts - set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_BINARY_DIR}/launch-cxx") - set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/launch-cxx") + set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_BINARY_DIR}/ccache-wrapper-cxx") + set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/ccache-wrapper-cxx") else() # Support Unix Makefiles and Ninja - set(CMAKE_CXX_COMPILER_LAUNCHER "${CMAKE_BINARY_DIR}/launch-cxx") + set(CMAKE_CXX_COMPILER_LAUNCHER "${CMAKE_BINARY_DIR}/ccache-wrapper-cxx") endif() - endif(GMX_CACHE_CXX_COMPILER) + endif() endif(CCACHE_PROGRAM) # ccache program -- 2.11.4.GIT