Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use ccache for very quick recompiles if installed on build system #47

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

dksmiffs
Copy link
Contributor

Implements #46.

Copy link

codecov bot commented Jan 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 32.11%. Comparing base (a025929) to head (00ac86d).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #47   +/-   ##
=======================================
  Coverage   32.11%   32.11%           
=======================================
  Files         290      290           
  Lines       27470    27470           
  Branches     1125     1125           
=======================================
  Hits         8823     8823           
  Misses      18647    18647           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dksmiffs dksmiffs marked this pull request as ready for review January 18, 2025 00:31
@dksmiffs dksmiffs requested a review from karljj1 as a code owner January 18, 2025 00:31
CMakeLists.txt Outdated
Comment on lines 59 to 60
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_FOUND}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_FOUND}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use RULE_LAUNCH_COMPILE or RULE_LAUNCH_LINK for these. Since CMake 3.4, the right way to do this is to use the CMAKE_<LANG>_COMPILER_LAUNCHER variables instead. And ccache doesn't cache linker commands, so there's no need to use it as a launcher for the linker.

See updated explanation here: https://crascit.com/2016/04/09/using-ccache-with-cmake/#h-improved-functionality-from-cmake-3-4

@dksmiffs dksmiffs marked this pull request as draft January 18, 2025 03:37
@dksmiffs dksmiffs marked this pull request as ready for review January 18, 2025 04:08
CMakeLists.txt Outdated
Comment on lines 56 to 63
find_program(CCACHE_FOUND ccache)

if(CCACHE_FOUND AND ENABLE_CCACHE)
set(CMAKE_CXX_COMPILER_LAUNCHER ccache)
message(STATUS "Using ccache for faster recompilation")
else()
message(STATUS "ccache not used for compilation")
endif()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Minimize output on the configure log at the default log level. Only log abnormal or unexpected things at STATUS or higher.
  • The result of find_program() is the location of the program, not a boolean.
Suggested change
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND AND ENABLE_CCACHE)
set(CMAKE_CXX_COMPILER_LAUNCHER ccache)
message(STATUS "Using ccache for faster recompilation")
else()
message(STATUS "ccache not used for compilation")
endif()
if(ENABLE_CCACHE)
find_program(CCACHE_EXECUTABLE ccache)
if(CCACHE_EXECUTABLE)
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
if(CMAKE_VERSION VERSION_GREATER_EQUAL 15)
message(VERBOSE "Enabled using ccache")
endif()
else()
message(WARNING "Using ccache requested, but could not find ccache executable")
endif()
endif()

Copy link
Contributor Author

@dksmiffs dksmiffs Jan 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@craigscott-crascit I'm unclear about your suggestion in lines 60-62 above. Why is the VERBOSE message printed only for CMake version >= 3.15?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The VERBOSE keyword is only supported since CMake 3.15. The first line of the top level CMakeLists.txt in this project lists CMake 3.14 as its minimum supported version. Te if() I added was to handle the case where the developer is using CMake 3.14, to prevent making a call to message() that would treat VERBOSE as part of the message instead of as the message log level.

@dksmiffs dksmiffs marked this pull request as draft January 18, 2025 15:15
@dksmiffs dksmiffs marked this pull request as ready for review January 18, 2025 16:05
Copy link
Owner

@karljj1 karljj1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not been keeping up to date with the cmake changes so ill defer to others

@dksmiffs dksmiffs marked this pull request as draft January 20, 2025 13:24
@carlocorradini
Copy link
Collaborator

@dksmiffs
Thank you for the PR, but do we really need ccache?
KDIS is not a small project... but I don't believe it is so large that it requires faster compilation via ccache.
Do not mistake my viewpoint, but (personally), I do not believe there is a need to include ccache directly in the main CMakeLists.txt.
On the other hand, I would prefer (please let me know what you think) to include a standalone README.md (or documentation or BUILDING.md) that explains how to speed up compilation time using ccache.
Furthermore, AFAIK, even though ccache now supports Windows (i.e. MSVC), it cannot be automatically included in CMakeLists.txt but must be added via CMake arguments.
What are your thoughts?

@dksmiffs
Copy link
Contributor Author

dksmiffs commented Jan 20, 2025

@karljj1 understood. When I learned about ccache last year, I incorrectly thought it was part of the CMake ecosystem (like CTest), but it's a separate tool. Without ccache, KDIS recompiles are just too slow, in my opinion, which makes major refactoring work too cumbersome.

@carlocorradini no, I wouldn't argue you need ccache. I definitely prefer using it in my refactoring work so far on KDIS. I already set it up as optional, and I'd be happy to set it to OFF by default, if that's what you'd prefer. Sure thing on adding words in a README.md, I'd be happy to do that. Regarding your Windows concern - wouldn't defaulting ENABLE_CCACHE to OFF address that? KDIS developers wouldn't be forced to use it.

EDIT: No, I don't like my own suggestion above. Defaulting to OFF would imply that it's optional to turn it ON in Windows. If that doesn't work inside the CMakeLists.txt as you suggest, then mine would be a hacky solution. Yes, I have set up ccache to work via CMake arguments in the past. I like your suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants