Bug 242945 - devel/cmake: bad interaction with non-default compilers: cmake loses ccache
Summary: devel/cmake: bad interaction with non-default compilers: cmake loses ccache
Status: New
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Ports Framework (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-kde (Team)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-28 16:59 UTC by Matthias Andree
Modified: 2020-03-16 22:31 UTC (History)
4 users (show)

See Also:
mandree: maintainer-feedback? (kde)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Andree freebsd_committer 2019-12-28 16:59:40 UTC
Greetings,

our ccache rigging is incomplete and fails if a port uses cmake to build and also a non-default compiler, such as a versioned cc/c++, or USE_GCC, or thereabouts.

In that situation, cmake derives an absolute path (of the compiler) and loses the ccache wrapper.

My current workaround, in, for instance, graphics/rawtherapee/Makefile, is:

.if "${WITH_CCACHE_BUILD}" == "yes" && !defined(NO_CCACHE)
CMAKE_ARGS+=    -DCMAKE_C_COMPILER_LAUNCHER=${CCACHE_BIN} \
                -DCMAKE_CXX_COMPILER_LAUNCHER=${CCACHE_BIN}
.endif

It would be good if either devel/cmake, or Mk/Uses/cmake.mk, or Mk/bsd.ccache.mk would avoid the need of spilling this to all medium- to heaviweight ports.
Comment 1 Gleb Popov freebsd_committer 2020-03-16 03:24:22 UTC
(In reply to Matthias Andree from comment #0)
Can you please give an example port and steps to reproduce?
Comment 2 Matthias Andree freebsd_committer 2020-03-16 22:29:02 UTC
I have implemented a workaround in graphics/rawtherapee.  IN 

Main contributor appears to be the combination of a cmake port that also sets USE_GCC, and a poudriere rig that enables CCACHE.

To reproduce, I propose:

1. in graphics/rawtherapee, remove this block from Makefile:
.if "${WITH_CCACHE_BUILD}" == "yes" && !defined(NO_CCACHE)
CMAKE_ARGS+=    -DCMAKE_C_COMPILER_LAUNCHER=${CCACHE_BIN} \
                -DCMAKE_CXX_COMPILER_LAUNCHER=${CCACHE_BIN}
.endif

2a. install and 
2b. configure poudriere. Here, in ${PREFIX}/etc/poudriere.conf, enable CCACHE_DIR (for instance, CCACHE_DIR=/usr/obj/ccache)

3. Try to build the port and observe.

You'll see this in configure:
...
===>   rawtherapee-5.8_1 depends on shared library: libjpeg.so - found (/usr/local/lib/libjpeg.so)
===>  Configuring for rawtherapee-5.8_1
===>  Performing out-of-source build
/bin/mkdir -p /usr/ports.svn/graphics/rawtherapee/work/.build
-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
-- Check for working C compiler: /usr/local/bin/gcc9
-- Check for working C compiler: /usr/local/bin/gcc9 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/local/bin/g++9
-- Check for working CXX compiler: /usr/local/bin/g++9 -- works
-- Detecting CXX compiler ABI info
...
[2/257] /usr/local/bin/g++9  -DAUTO_GDK_FLUSH=0 -DMYFILE_MMAP -DNDEBUG -DRT_FFTW3F_OMP -DSTRICT_MUTEX=1 -DTRACE_MYRWMUTEX=0 -D_DNDEBUG -Irtengine -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include/glibmm-2.4 -I/usr/local/lib/glibmm-2.4/include -I/usr/local/include/sigc++-2.0 -I/usr/local/lib/sigc++-2.0/include -I/usr/local/include/gtkmm-3.0 -I/usr/local/lib/gtkmm-3.0/include -I/usr/local/include/atkmm-1.6 -I/usr/local/include/atk-1.0 -I/usr/local/include/giomm-2.4 -I/usr/local/lib/giomm-2.4/include -I/usr/local/include/pangomm-1.4 -I/usr/local/lib/pangomm-1.4/include -I/usr/local/include/cairomm-1.0 -I/usr/local/lib/cairomm-1.0/include -I/usr/local/include/cairo -I/usr/local/include/pixman-1 -I/usr/local/include/freetype2 -I/usr/local/include/libdrm -I/usr/local/include/libpng16 -I/usr/local/include/pango-1.0 -I/usr/local/include/fribidi -I/usr/local/include/harfbuzz -I/usr/local/include/gtk-3.0 -I/usr/local/include/gdk-pixbuf-2.0 -I/usr/local/include/gio-unix-2.0 -I/usr/local/include/libepoll-shim -I/usr/local/lib/libffi-3.2.1/include -I/usr/local/include/at-spi2-atk/2.0 -I/usr/local/include/at-spi-2.0 -I/usr/local/include/dbus-1.0 -I/usr/local/lib/dbus-1.0/include -I/usr/local/include/gtk-3.0/unix-print -I/usr/local/include/gdkmm-3.0 -I/usr/local/lib/gdkmm-3.0/include -I/usr/local/include/libiptcdata -I/usr/local/include/lensfun -I/usr/local/include/librsvg-2.0 -O2 -pipe  -I/usr/local/include -fPIC -flto=16 -O3 -funroll-loops -msse2 -fstack-protector-strong -Wl,-rpath=/usr/local/lib/gcc9  -nostdinc++ -isystem /usr/include/c++/v1 -Wl,-rpath=/usr/local/lib/gcc9 -isystem /usr/local/include -std=c++11 -march=native -Werror=unused-label -Werror=delete-incomplete -Wall -Wuninitialized -Wcast-qual -Wno-deprecated-declarations -Wno-unused-result -fopenmp -Werror=unknown-pragmas -O2 -pipe  -I/usr/local/include -fPIC -flto=16 -O3 -funroll-loops -msse2 -fstack-protector-strong -Wl,-rpath=/usr/local/lib/gcc9  -nostdinc++ -isystem /usr/include/c++/v1 -Wl,-rpath=/usr/local/lib/gcc9 -isystem /usr/local/include   -ftree-vectorize -MD -MT rtengine/CMakeFiles/rtengine.dir/fast_demo.cc.o -MF rtengine/CMakeFiles/rtengine.dir/fast_demo.cc.o.d -o rtengine/CMakeFiles/rtengine.dir/fast_demo.cc.o -c /usr/ports.svn/graphics/rawtherapee/work/rawtherapee-5.8/rtengine/fast_demo.cc

NOTE that the cmake configure phase obtains GCC's absolute path.

NOTE the compilation time, retry, and compile again to see that the compilation time is more or less the same.

4. Now (a) comment out USE_GCC from Makefile, (b)  change the USES= line from compiler:gcc-c++11-lib to compiler:c++11-lib, and (c) change _LTO_FLAGS= to read _LTO_FLAGS=-flto=thin if your cc is clang.
(Note that you won't obtain a fully working rawtherapee executable that way.), and make clean ; make |& less

You'll see this instead. Observe it has picked c++ from the path, invoking ccache.

===>  Configuring for rawtherapee-5.8_1
===>  Performing out-of-source build
/bin/mkdir -p /usr/ports.svn/graphics/rawtherapee/work/.build
-- The C compiler identification is Clang 8.0.1
-- The CXX compiler identification is Clang 8.0.1
-- Check for working C compiler: /usr/local/libexec/ccache/cc
...
[2/284] /usr/local/libexec/ccache/c++  -DAUTO_GDK_FLUSH=0 -DMYFILE_MMAP -DNDEBUG -DRT_FFTW3F_OMP -DSTRICT_MUTEX=1 -DTRACE_MYRWMUTEX=0 -D_DNDEBUG -Irtexif -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include/glibmm-2.4 -I/usr/local/lib/glibmm-2.4/include -I/usr/local/include/sigc++-2.0 -I/usr/local/lib/sigc++-2.0/include -I/usr/local/include/gtk-3.0 -I/usr/local/include/pango-1.0 -I/usr/local/include/fribidi -I/usr/local/include/cairo -I/usr/local/include/pixman-1 -I/usr/local/include/freetype2 -I/usr/local/include/libdrm -I/usr/local/include/libpng16 -I/usr/local/include/harfbuzz -I/usr/local/include/gdk-pixbuf-2.0 -I/usr/local/include/gio-unix-2.0 -I/usr/local/include/libepoll-shim -I/usr/local/lib/libffi-3.2.1/include -I/usr/local/include/atk-1.0 -I/usr/local/include/at-spi2-atk/2.0 -I/usr/local/include/at-spi-2.0 -I/usr/local/include/dbus-1.0 -I/usr/local/lib/dbus-1.0/include -I/usr/local/include/gtkmm-3.0 -I/usr/local/lib/gtkmm-3.0/include -I/usr/local/include/atkmm-1.6 -I/usr/local/include/giomm-2.4 -I/usr/local/lib/giomm-2.4/include -I/usr/local/include/pangomm-1.4 -I/usr/local/lib/pangomm-1.4/include -I/usr/local/include/cairomm-1.0 -I/usr/local/lib/cairomm-1.0/include -I/usr/local/include/gtk-3.0/unix-print -I/usr/local/include/gdkmm-3.0 -I/usr/local/lib/gdkmm-3.0/include -O2 -pipe -I/usr/local/include -fPIC -flto=thin -O3 -funroll-loops -msse2 -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing  -isystem /usr/local/include -std=c++11 -march=native -Werror=unused-label -Werror=delete-incomplete -Wall -Wuninitialized -Wcast-qual -Wno-deprecated-declarations -Wno-unused-result -fopenmp=libomp -Werror=unknown-pragmas -O2 -pipe -I/usr/local/include -fPIC -flto=thin -O3 -funroll-loops -msse2 -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing  -isystem /usr/local/include    -fPIC -MD -MT rtexif/CMakeFiles/rtexif.dir/panasonicattribs.cc.o -MF rtexif/CMakeFiles/rtexif.dir/panasonicattribs.cc.o.d -o rtexif/CMakeFiles/rtexif.dir/panasonicattribs.cc.o -c /usr/ports.svn/graphics/rawtherapee/work/rawtherapee-5.8/rtexif/panasonicattribs.cc

Observe you'll get /usr/local/libexec/ccache/c++. Let it build, then make clean and re-build and see that the second build goes much faster.
Comment 3 Matthias Andree freebsd_committer 2020-03-16 22:31:33 UTC
Whoops. I was posting a half-edit, sorry for that. Disregard (1) the stray IN in my comment, and (2) poudriere hints. No need to bother with poudriere, instead you can just install ccache and then add WITH_CCACHE_BUILD=yes to make.conf:

echo 'WITH_CCACHE_BUILD=yes' >>/etc/make.conf


(my workaround given above in 1. applies to direct builds as well as poudriere.)