clang makes recompile everithing at each build in cmake

Viewed 170

Here is a small c++ code, adapted from the tutorial Step 1 of CMake :

// tutorial.cxx
#include <iostream>

int main(int argc, char* argv[])
{
  std::cout << "Hello World" << std::endl;
  return 0;
}
# CMakeLists.txt
cmake_minimum_required(VERSION 3.10)

# set the project name
project(Tutorial)

# add the executable
add_executable(Tutorial tutorial.cxx)

I used the extension of vscode CmakeTools, and I noticed that every time I build the project, it recompiles everything, even if nothing was changed. After some investigations, I found that the configuration of the project is made by vscode using this command :

/usr/local/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/bin/clang-10 -DCMAKE_CXX_COMPILER:FILEPATH=/bin/clang++-10 -H/home/user/Bureau/projet/step1 -B/home/user/Bureau/projet/step1/build -G "Unix Makefiles"

(and if I configure by hand in the terminal with this command, it has the same behavior).

I noticed that if I configure the build directory without the option -DCMAKE_CXX_COMPILER:FILEPATH=/bin/clang++-10, there is no problem afterwards: if a make if nothing has been charged in source, it doesn't recompile.

I have actually 2 questions :

  1. Why does the option CMAKE_CXX_COMPILER:FILEPATH induces such a behavior?
  2. How to configure vscode so it doesn't use this option anymore?

EDIT :

I tried to configure the project with another compiler (in the list, vscode proposes Clang10, GCC 8.4.0 and GCC 9.3.0). With Clang all is recompiled at each time, but this is not the case if I take GCC.

This answers my second question: use another compiler. But still, I wonder why does Clang recompile everything ?

0 Answers
Related