Search code examples
gitcmakegit-tagfetchcontent

Why is a FetchContent using a different TAG than the one I specified? How can I resolve this?


I am trying to use a certain library with FetchContent:

FetchContent_Declare(
    Catch2
    GIT_REPOSITORY https://github.com/catchorg/Catch2.git
    GIT_TAG        3f0283de7a9c43200033da996ff9093be3ac84dc
    GIT_PROGRESS   TRUE
    GIT_SHALLOW    FALSE
)
FetchContent_MakeAvailable(Catch2)

According to practice I am specifying a particular tag. However when I look at the files that cmake downloads, the tag is 7cf2f88e50f0d1de324489c31db0314188423b6d instead, and it is older (Feb 14 2023).

If I manually got to _deps/catch2-src and do git checkout 3f0283de7a9c43200033da996ff9093be3ac84dc, I get the correct version (Jun 21 2023).

What is wrong with the FetchContent block above? Why would CMake download the incorrect or older version of the library?


Solution

  • My top suspect is

    The FetchContent_Declare() function records the options that describe how to populate the specified content. If such details have already been recorded earlier in this project (regardless of where in the project hierarchy), this and all later calls for the same content are ignored.