Open terrylyons opened 3 years ago
1> CMake Error at extern/CMakeLists.txt:16 (FetchContent_MakeAvailable):
1> Unknown CMake command "FetchContent_MakeAvailable".
I comment out add_subdirectory(extern)
and re-configured, no error occurred.
Please make sure your vcpkg is latest.
With version 18 of cmake there is no error in the cmake. I have built the binaries in windows and Linux successfully several times. Sadly It builds without vcpckg integration disabled and loops with it.
Terry
On 1 Mar 2021, at 06:52, Jack·Boos·Yu notifications@github.com wrote:
1> CMake Error at extern/CMakeLists.txt:16 (FetchContent_MakeAvailable): 1> Unknown CMake command "FetchContent_MakeAvailable".
I comment out add_subdirectory(extern) and re-configured, no error occurred.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/microsoft/vcpkg/issues/16454#issuecomment-787698845, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABQWN6ZGNIT5JN53VHV5OBLTBM2QRANCNFSM4YKOFO6A.
Confirmed with Visual Studio 2019.
@JackBoosY @ras0219-msft
This seems to be related to this message on the CMake mailing list.
I was able to make the wrapping of add_library
and add_executable
happen only once by surrounding each with an if block, and setting a global property.
if(NOT ${Z_VCPKG_ADD_EXECUTABLE_WRAPPED_ONCE})
function(add_executable)
...
endfunction()
set_property(GLOBAL PROPERTY Z_VCPKG_ADD_EXECUTABLE_WRAPPED_ONCE ON)
endif()
if(NOT ${Z_VCPKG_ADD_LIBRARY_WRAPPED_ONCE})
function(add_library)
...
endfunction()
set_property(GLOBAL PROPERTY Z_VCPKG_ADD_LIBRARY_WRAPPED_ONCE ON)
endif()
I'm still pretty green with CMake, but that worked for me.
EDIT:
I did a little more trial-and-error, and found this one-liner at the top the file is a workable workaround(for CMake version >= 3.10):
include_guard(GLOBAL)
The example uses a subproject. Basically this is valid CMake. Normal variables set in the subdir/subproject won't be visible to the parent scope.
What is unusual in the example project is that add_subdirectory
is called before the top-level project
command. A lot of things happen when CMake encounters the project
command. For example, CMake calls the toolchain file.
Taking this together, order matters: In the example, many variables aren't yet initialized when hitting project
in the subdir. And changes to these variables in subdir
won't be visible to the parent scope. That's why in your example, the top-level project
command triggers a second execution of the toolchain file, including the second redefinition of add_executable
. Which isn't supported by CMake.
So first I would advice to avoid add_subdirectory
before project
. There is no advantage from that, but there is the risk of redundant expensive project
steps.
Second, vcpkg needs to generally guard against redefining add_executable
or add_library
. There are multiple triggers:
project
before top-level project
include(...vcpkg.cmake)
in combination with -DCMAKE_TOOLCHAIN_FILE=...vcpkg.cmake
Is there a possibility to add a VCPKG_OVERRIDE_ADD_LIBRARY_NAME
in the same vein as VCPKG_OVERRIDE_FIND_PACKAGE_NAME
? I have a project that wraps add_library
to record packages used to generate find_dependency
calls in the generated <Package>Config.cmake
file, but this ends up not being usable when vcpkg also wraps add_library
. Apologies if this is the wrong place to ask about this!
I have a very simple cross-platform cmake C++ project and I am editing it in visual studio 2019. Creating the CMake cache works perfectly if I remove the vcpkg integration; but fails with a loop of 1000 times if I include the vcpkg integration. I downloaded the current version of vcpkg from GitHub to check that the issue had not been fixed.
I include zipped up the CMake code tree and the very simple code.
There is one CMake included external package simdjson which builds successfully.
quicktrack_tree.zip
googling vcpkg Infinite CMake recursion when compiling yields many other cases of this problem
with vcpkg integrate install: