ladislas
ladislas

Reputation: 3070

CMake + ccache: RULE_LAUNCH_COMPILE or CMAKE_<LANG>_COMPILER_LAUNCHER

When using ccache with CMake, there seems to be two ways to setup the project.

The first one is with RULE_LAUNCH_COMPILE

find_program(CCACHE "ccache")
if(CCACHE)
    set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE}")
endif()

The second one is with CMAKE_<LANG>_COMPILER_LAUNCHER:

find_program(CCACHE "ccache")
if(CCACHE)
    set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
    set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
endif(CCACHE)

Which one is considered best practice? :)

Thanks for your help.

Upvotes: 9

Views: 4491

Answers (1)

fdk1342
fdk1342

Reputation: 3564

The first one will use the launcher for all languages in the build. The second one will use the same launcher for C and CXX but not for other languages. The two methods are slightly different as the second one would allow for a different launcher for different languages. The second method allows for finer control and may be preferred. There are also environment variables and directory and target properties for control which items use a launcher.

https://crascit.com/2016/04/09/using-ccache-with-cmake/

Upvotes: 9

Related Questions