Conan+CMake: how to display actual compilation commands?

As part of the conanfile.py, add the following:

    def generate(self):
        toolchain = CMakeToolchain(self)
        toolchain.variables['CMAKE_VERBOSE_MAKEFILE'] = 'ON'
        toolchain.generate()
        CMakeDeps(self).generate()

Build output without CMAKE_VERBOSE_MAKEFILE:
[ 78%] Building CXX object cpp/test/unit/CMakeFiles/IntegrationTest.cpp.o

Build output with CMAKE_VERBOSE_MAKEFILE:
[ 78%] Building CXX object cpp/test/unit/CMakeFiles/csf_api_unit_tests.dir/src/IntegrationTest.cpp.o
cd /opt/app-root/.conan/data/{stuff} && /usr/bin/clang++ --gcc-toolchain=/opt/app-root/.conan/data/gcc/7.5.0/... DBOOST_ALL_DYN_LINK -DCARES_STATICLIB -DCURL_STATICLIB=1 -DFMT_HEADER_ONLY=1 -DSPDLOG_FMT_EXTERNAL -I {more stuff} cpp/test/unit/src/IntegrationTest.cpp

Recording this for posterity, since this is totally not obvious.
To my readers: if you don’t know what the hell it is about, consider yourself lucky, these are the dirty internals of a build system for C++.

Leave a Reply

Your email address will not be published. Required fields are marked *