FetchContent in CMake 3.20+ does not seem to honor cmake_minimum_required(...) settings
I am running into a pretty elaborate error in one of our builds. So I don't have a stripped-down reproducer at the moment.
In order to build one of our projects, we (can) build an external project in it, using FetchContent. That external project uses try_compile, and check_cxx_source_compiles extensively to figure out how it should build itself.
But what I see is that even though that external project requires a minimum of CMake 3.10 to build, CMP0067 still "triggers" during the configuration of the project.
~/software/cmake/3.21.3/x86_64-ubuntu2004-gcc9-opt/bin/cmake -DCMAKE_BUILD_TYPE=Release -DALGEBRA_PLUGIN_INCLUDE_VECMEM=TRUE -DALGEBRA_PLUGIN_SETUP_VECMEM=TRUE -DALGEBRA_PLUGIN_USE_SYSTEM_VECMEM=FALSE -DCMAKE_POLICY_WARNING_CMP0067=TRUE ../algebra-plugins/ ... -- Performing Test VECMEM_HAVE_PMR_MEMORY_RESOURCE CMake Warning (dev) at /home/krasznaa/software/cmake/3.21.3/x86_64-ubuntu2004-gcc9-opt/share/cmake-3.21/Modules/Internal/CheckSourceCompiles.cmake:92 (try_compile): Policy CMP0067 is not set: Honor language standard in try_compile() source-file signature. Run "cmake --help-policy CMP0067" for policy details. Use the cmake_policy command to set the policy and suppress this warning. For compatibility with older versions of CMake, try_compile is not honoring language standard variables in the test project: CMAKE_CXX_STANDARD Call Stack (most recent call first): /home/krasznaa/software/cmake/3.21.3/x86_64-ubuntu2004-gcc9-opt/share/cmake-3.21/Modules/CheckCXXSourceCompiles.cmake:76 (cmake_check_source_compiles) /data/ssd-1tb/projects/algebra-plugins/build/_deps/vecmem-src/core/CMakeLists.txt:95 (check_cxx_source_compiles) This warning is for project developers. Use -Wno-dev to suppress it. -- Performing Test VECMEM_HAVE_PMR_MEMORY_RESOURCE - Failed
With CMake 3.16 I do not observe this issue.
I tried to play around with very explicitly requiring minimum CMake versions in different parts of the code, and even setting CMP0067 explicitly in different places. But to no avail. I continue to get this problem. As if CMake would become unaware of any CMake version requirements while parsing that particular configuration file.
Unfortunately this completely prevents us from building our code the way that we would like, as the "external" project can just not be configured correctly as part of the "higher level" project. (And using an older version of CMake to avoid this issue is not really viable.) So any insight/help would be much appreciated.