2

I have observed the below detailed behaviour when compiling a C++ program with 2 different CMake versions:

  • 3.10.2 (installed from default APT repository for Ubuntu 18.04); and
  • 3.16.5 (installed together with CLion).

In the project the /usr/local/include folder is added to the include path (as a system include directory if it matters), through the ODB package:

include_directories(SYSTEM ${ODB_INCLUDE_DIRS})

Where ${ODB_INCLUDE_DIRS} is /usr/local/include for me.

When I use the CMake version 3.10.2 (from APT repository), the /usr/local/include directory is added to the include path correctly.

When I use the CMake version 3.16.5 (installed with CLion), the /usr/local/include directory is not added to the include path at all.

I could easily verify this difference by running make VERBOSE=1 and examining the compilation commands. This difference raised a compilation error for the project and I would be interested why do I experience this discrepancy between the mentioned 2 CMake versions? Was some default configuration changed between them?


I have created a MWE:

cmake_minimum_required(VERSION 3.4.3)
project(mwe)
include_directories(SYSTEM /usr/local/include)
add_executable(mwe main.cpp)

Where main.cpp is just a classic Hello World application.

Here are the interesting compilation commands (below I attach the complete logs):

  • with CMake 3.10.2 (/usr/local/include added correctly):
/usr/bin/c++   -isystem /usr/local/include   -o CMakeFiles/mwe.dir/main.cpp.o -c /home/mate/Temp/mwe/main.cpp
  • with CMake 3.16.5 (/usr/local/include missing):
/usr/bin/c++     -o CMakeFiles/mwe.dir/main.cpp.o -c /home/mate/Temp/mwe/main.cpp

Running CMake 3.10.2:

>> cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- 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/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mate/Temp/mwe/build_3-10-2

>> make VERBOSE=1
/usr/bin/cmake -H/home/mate/Temp/mwe -B/home/mate/Temp/mwe/build_3-10-2 --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/mate/Temp/mwe/build_3-10-2/CMakeFiles /home/mate/Temp/mwe/build_3-10-2/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/mate/Temp/mwe/build_3-10-2'
make -f CMakeFiles/mwe.dir/build.make CMakeFiles/mwe.dir/depend
make[2]: Entering directory '/home/mate/Temp/mwe/build_3-10-2'
cd /home/mate/Temp/mwe/build_3-10-2 && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/mate/Temp/mwe /home/mate/Temp/mwe /home/mate/Temp/mwe/build_3-10-2 /home/mate/Temp/mwe/build_3-10-2 /home/mate/Temp/mwe/build_3-10-2/CMakeFiles/mwe.dir/DependInfo.cmake --color=
Dependee "/home/mate/Temp/mwe/build_3-10-2/CMakeFiles/mwe.dir/DependInfo.cmake" is newer than depender "/home/mate/Temp/mwe/build_3-10-2/CMakeFiles/mwe.dir/depend.internal".
Dependee "/home/mate/Temp/mwe/build_3-10-2/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/mate/Temp/mwe/build_3-10-2/CMakeFiles/mwe.dir/depend.internal".
Scanning dependencies of target mwe
make[2]: Leaving directory '/home/mate/Temp/mwe/build_3-10-2'
make -f CMakeFiles/mwe.dir/build.make CMakeFiles/mwe.dir/build
make[2]: Entering directory '/home/mate/Temp/mwe/build_3-10-2'
[ 50%] Building CXX object CMakeFiles/mwe.dir/main.cpp.o
/usr/bin/c++   -isystem /usr/local/include   -o CMakeFiles/mwe.dir/main.cpp.o -c /home/mate/Temp/mwe/main.cpp
[100%] Linking CXX executable mwe
/usr/bin/cmake -E cmake_link_script CMakeFiles/mwe.dir/link.txt --verbose=1
/usr/bin/c++     CMakeFiles/mwe.dir/main.cpp.o  -o mwe 
make[2]: Leaving directory '/home/mate/Temp/mwe/build_3-10-2'
[100%] Built target mwe
make[1]: Leaving directory '/home/mate/Temp/mwe/build_3-10-2'
/usr/bin/cmake -E cmake_progress_start /home/mate/Temp/mwe/build_3-10-2/CMakeFiles 0

Running CMake 3.16.5:

>> /opt/CLion/bin/cmake/linux/bin/cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- 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/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mate/Temp/mwe/build_3-16-5

>> make VERBOSE=1
/opt/CLion/bin/cmake/linux/bin/cmake -S/home/mate/Temp/mwe -B/home/mate/Temp/mwe/build_3-16-5 --check-build-system CMakeFiles/Makefile.cmake 0
/opt/CLion/bin/cmake/linux/bin/cmake -E cmake_progress_start /home/mate/Temp/mwe/build_3-16-5/CMakeFiles /home/mate/Temp/mwe/build_3-16-5/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/mate/Temp/mwe/build_3-16-5'
make -f CMakeFiles/mwe.dir/build.make CMakeFiles/mwe.dir/depend
make[2]: Entering directory '/home/mate/Temp/mwe/build_3-16-5'
cd /home/mate/Temp/mwe/build_3-16-5 && /opt/CLion/bin/cmake/linux/bin/cmake -E cmake_depends "Unix Makefiles" /home/mate/Temp/mwe /home/mate/Temp/mwe /home/mate/Temp/mwe/build_3-16-5 /home/mate/Temp/mwe/build_3-16-5 /home/mate/Temp/mwe/build_3-16-5/CMakeFiles/mwe.dir/DependInfo.cmake --color=
Dependee "/home/mate/Temp/mwe/build_3-16-5/CMakeFiles/mwe.dir/DependInfo.cmake" is newer than depender "/home/mate/Temp/mwe/build_3-16-5/CMakeFiles/mwe.dir/depend.internal".
Dependee "/home/mate/Temp/mwe/build_3-16-5/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/mate/Temp/mwe/build_3-16-5/CMakeFiles/mwe.dir/depend.internal".
Scanning dependencies of target mwe
make[2]: Leaving directory '/home/mate/Temp/mwe/build_3-16-5'
make -f CMakeFiles/mwe.dir/build.make CMakeFiles/mwe.dir/build
make[2]: Entering directory '/home/mate/Temp/mwe/build_3-16-5'
[ 50%] Building CXX object CMakeFiles/mwe.dir/main.cpp.o
/usr/bin/c++     -o CMakeFiles/mwe.dir/main.cpp.o -c /home/mate/Temp/mwe/main.cpp
[100%] Linking CXX executable mwe
/opt/CLion/bin/cmake/linux/bin/cmake -E cmake_link_script CMakeFiles/mwe.dir/link.txt --verbose=1
/usr/bin/c++     CMakeFiles/mwe.dir/main.cpp.o  -o mwe 
make[2]: Leaving directory '/home/mate/Temp/mwe/build_3-16-5'
[100%] Built target mwe
make[1]: Leaving directory '/home/mate/Temp/mwe/build_3-16-5'
/opt/CLion/bin/cmake/linux/bin/cmake -E cmake_progress_start /home/mate/Temp/mwe/build_3-16-5/CMakeFiles 0
mcserep
  • 3,231
  • 21
  • 36
  • As far as I remember, CMake may omit include directory if it detect the compiler itself uses it as default. The reasoning about that is related with `#include_next <...>`. – Tsyvarev Sep 24 '20 at 08:38
  • Is that mentioned in the reference anywhere? I could not find anything about omitting a given include directory. And if it works like that, it is kind of strange, because if the `/usr/local/include` is omitted, different files get included (from other include directories given), hence the compilation failure in the project. – mcserep Sep 24 '20 at 08:53
  • "because if the /usr/local/include is omitted, different files get included ... hence the compilation failure in the project." - Attempt to redefine headers contained in the compiler's default include directory looks strange at least. As for reasoning to omit including directory which is already included by the compiler, it is similar to that question: https://stackoverflow.com/questions/37218953/isystem-on-a-system-include-directory-causes-errors. – Tsyvarev Sep 24 '20 at 09:05
  • "Attempt to redefine headers contained in the compiler's default include directory looks strange at least." - I simply have multiple installations of 3rd party dependency of the project (LLVM). The proper path is given to CMake with the `LLVM_DIR` variable, and `find_package` locates it correctly. However with CMake 3.10.2 the `/usr/local/include` is added to the include path because of the ODB dependency, therefore the wrong version of the LLVM headers are included. On CMake 3.16.5 this is not an issue. Now I see the problem and can find a workaround; the disturbing part is the inconsistency. – mcserep Sep 24 '20 at 11:03

0 Answers0