FetchContent dependency is constantly rebuilt when symlink is used for compiler path
Hi, first of all, I'm not 100% sure that this is CMake bug but the behavior is pretty weird and I think that this is the best place to understand what's going on. Here's my setup:
Ubuntu 20.04
CMake 3.22.1
Clang 13.0.1
CMakeLists.txt:
cmake_minimum_required(VERSION 3.11)
project(fetch_build_test VERSION 1.0 LANGUAGES CXX)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG "release-1.11.0"
)
FetchContent_MakeAvailable(googletest)
add_executable(fetch_build_test main.cpp)
main.cpp:
int main(){
return 0;
}
The problem is when I use /bin/clang-13
as my compiler path, each cmake --build
triggers build of googletest
. When compiler path is /usr/bin/clang-13
, googletest
is built only once. If you wonder why I use /bin/clang-13
which is a symlink, I don't do this on purpose. I use VSCode + CMake extension, it scans for compilers and for some reason it uses /bin/clang-13
instead of /usr/bin/clang-13
. Anyway, it doesn't look wrong and I'm surprised to see this behavior.
I also provide my terminal logs.
Good case with /usr/bin/clang-13
:
$ cmake -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/clang-13 -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/clang++-13 ..
-- The CXX compiler identification is Clang 13.0.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++-13 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The C compiler identification is Clang 13.0.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang-13 - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found Python: /usr/bin/python3.8 (found version "3.8.10") found components: Interpreter
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/...
$ cmake --build .
[ 10%] Building CXX object CMakeFiles/fetch_build_test.dir/main.cpp.o
[ 20%] Linking CXX executable fetch_build_test
[ 20%] Built target fetch_build_test
[ 30%] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 40%] Linking CXX static library ../../../lib/libgtest.a
[ 40%] Built target gtest
[ 50%] Building CXX object _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o
[ 60%] Linking CXX static library ../../../lib/libgmock.a
[ 60%] Built target gmock
[ 70%] Building CXX object _deps/googletest-build/googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.o
[ 80%] Linking CXX static library ../../../lib/libgmock_main.a
[ 80%] Built target gmock_main
[ 90%] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[100%] Linking CXX static library ../../../lib/libgtest_main.a
[100%] Built target gtest_main
$ cmake --build .
Consolidate compiler generated dependencies of target fetch_build_test
[ 20%] Built target fetch_build_test
Consolidate compiler generated dependencies of target gtest
[ 40%] Built target gtest
Consolidate compiler generated dependencies of target gmock
[ 60%] Built target gmock
Consolidate compiler generated dependencies of target gmock_main
[ 80%] Built target gmock_main
Consolidate compiler generated dependencies of target gtest_main
[100%] Built target gtest_main
Bad case with /bin/clang-13
:
$ cmake -DCMAKE_C_COMPILER:FILEPATH=/bin/clang-13 -DCMAKE_CXX_COMPILER:FILEPATH=/bin/clang++-13 ..
-- The CXX compiler identification is Clang 13.0.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /bin/clang++-13 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The C compiler identification is Clang 13.0.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /bin/clang-13 - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found Python: /usr/bin/python3.8 (found version "3.8.10") found components: Interpreter
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/...
$ cmake --build .
[ 10%] Building CXX object CMakeFiles/fetch_build_test.dir/main.cpp.o
[ 20%] Linking CXX executable fetch_build_test
[ 20%] Built target fetch_build_test
[ 30%] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 40%] Linking CXX static library ../../../lib/libgtest.a
[ 40%] Built target gtest
[ 50%] Building CXX object _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o
[ 60%] Linking CXX static library ../../../lib/libgmock.a
[ 60%] Built target gmock
[ 70%] Building CXX object _deps/googletest-build/googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.o
[ 80%] Linking CXX static library ../../../lib/libgmock_main.a
[ 80%] Built target gmock_main
[ 90%] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[100%] Linking CXX static library ../../../lib/libgtest_main.a
[100%] Built target gtest_main
$ cmake --build .
Consolidate compiler generated dependencies of target fetch_build_test
[ 20%] Built target fetch_build_test
Consolidate compiler generated dependencies of target gtest
[ 30%] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 40%] Linking CXX static library ../../../lib/libgtest.a
[ 40%] Built target gtest
Consolidate compiler generated dependencies of target gmock
[ 50%] Building CXX object _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o
[ 60%] Linking CXX static library ../../../lib/libgmock.a
[ 60%] Built target gmock
Consolidate compiler generated dependencies of target gmock_main
[ 70%] Building CXX object _deps/googletest-build/googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.o
[ 80%] Linking CXX static library ../../../lib/libgmock_main.a
[ 80%] Built target gmock_main
Consolidate compiler generated dependencies of target gtest_main
[ 90%] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[100%] Linking CXX static library ../../../lib/libgtest_main.a
[100%] Built target gtest_main