From c4ba542e7a10eb1bfcadd58f0d56a37270d3057b Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Date: Fri, 23 Dec 2022 20:08:16 -0300 Subject: [PATCH] build: switch from RULE_LAUNCH_COMPILE to CXX_COMPILER_LAUNCHER --- CMakeLists.txt | 2 +- build-support/3rd-party/colored-messages.cmake | 12 ++++++------ build-support/macros-and-definitions.cmake | 12 ++++++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a2dc9b75..e7fab72d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,7 +106,7 @@ if(${NS3_CCACHE}) find_program(CCACHE ccache) if(NOT ("${CCACHE}" STREQUAL "CCACHE-NOTFOUND")) message(STATUS "CCache is enabled.") - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE}) + set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE}) execute_process( COMMAND ${CCACHE} --set-config diff --git a/build-support/3rd-party/colored-messages.cmake b/build-support/3rd-party/colored-messages.cmake index 2bb00d273..16a19e2f6 100644 --- a/build-support/3rd-party/colored-messages.cmake +++ b/build-support/3rd-party/colored-messages.cmake @@ -71,25 +71,25 @@ if(${NS3_COLORED_OUTPUT} OR "$ENV{CLICOLOR}") # Replace the default message macro with a custom colored one function(message) list(GET ARGV 0 MessageType) + list(REMOVE_AT ARGV 0) + + # Transform list of arguments into a single line. + string(REPLACE ";" " " ARGV "${ARGV}") + if((${MessageType} STREQUAL FATAL_ERROR) OR (${MessageType} STREQUAL SEND_ERROR) ) - list(REMOVE_AT ARGV 0) _message(${MessageType} "${BoldRed}${ARGV}${ColourReset}") elseif(MessageType STREQUAL WARNING) - list(REMOVE_AT ARGV 0) _message(${MessageType} "${Yellow}${ARGV}${ColourReset}") elseif(MessageType STREQUAL AUTHOR_WARNING) - list(REMOVE_AT ARGV 0) _message(${MessageType} "${BoldCyan}${ARGV}${ColourReset}") elseif(MessageType STREQUAL HIGHLIGHTED_STATUS) # Custom message type - list(REMOVE_AT ARGV 0) _message(STATUS "${Yellow}${ARGV}${ColourReset}") elseif(MessageType STREQUAL STATUS) - list(REMOVE_AT ARGV 0) _message(${MessageType} "${ARGV}") else() - _message(${ARGV}) + _message(${MessageType} "${ARGV}") endif() endfunction() endif() diff --git a/build-support/macros-and-definitions.cmake b/build-support/macros-and-definitions.cmake index 6bfbac500..44c2c2af4 100644 --- a/build-support/macros-and-definitions.cmake +++ b/build-support/macros-and-definitions.cmake @@ -478,6 +478,18 @@ macro(process_options) if("${CLANG_TIDY}" STREQUAL "CLANG_TIDY-NOTFOUND") message(FATAL_ERROR "Clang-tidy was not found") else() + if((${CMAKE_VERSION} VERSION_LESS "3.12.0") AND ${NS3_CCACHE} + AND (NOT ("${CCACHE}" STREQUAL "CCACHE-NOTFOUND")) + ) + # CMake <3.12 puts CMAKE_CXX_COMPILER_LAUNCHER in the incorrect place + # and CCache ends up being unable to cache anything if calling + # clang-tidy https://gitlab.kitware.com/cmake/cmake/-/issues/18266 + message( + FATAL_ERROR + "The current CMake ${CMAKE_VERSION} won't ccache objects correctly when running with clang-tidy." + "Update CMake to at least version 3.12, or disable either ccache or clang-tidy to continue." + ) + endif() set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY}") endif() else()