From the FetchContent docs:
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.
If a previous call to FetchContent_Declare
for the same name (in this case Catch2
) chose a different TAG
, the first one of those calls that sets TAG
will "win". Are there any other calls to FetchContent_Declare
for Catch2 anywhere in the configuration? Perhaps in one of your dependencies (if you have any)? If you don't want to search manually, you can use cmake --trace
and then grep
or jq
for FetchContent_Declare
calls.
This whole business is by design. From the same docs:
Projects should aim to declare the details of all dependencies they might use before they call FetchContent_MakeAvailable()
for any of them. This ensures that if any of the dependencies are also sub-dependencies of one or more of the others, the main project still controls the details that will be used (because it will declare them first before the dependencies get a chance to)
Once you find the thing that's taking precendence, just move things around in your CMakeLists.txt so that your call to FetchContent_Declare
goes first so it "wins".
If your call to FetchContent_Declare
for a given name is the only one for that name, then you shouldn't have this problem. Even if you change the commitish being referenced in the TAG
argument of your call, the next time your run configuration, CMake will update the checkout to that new commitish. And if you run build without reconfiguring, CMake is usually smart enough at knowing when it needs to reconfigure to do it automatically.