FetchContent and CMAKE_GENERATOR_INSTANCE don't mix
I have two VS installations:
- BuildTools-only install with MSVC and Intel C++ compilers
- Community Edition with MSVC and GPGPU extensions installed (I needed this install because neither Intel oneAPI, nor AMD HIP SDK install PlatformToolset for BuildTools installations of VS)
I am trying to use these GPGPU extensions alongside CMake (for eg. cmake -G "Visual Studio 172022" -T HIP_clang -D CMAKE_GENERATOR_INSTANCE="C:\Kellekek\Microsoft\VisualStudio\2022\Community" -D CMAKE_MSVC_DEBUG_INFORMATION_FORMAT="" ...
). This mostly gets the job done, but as soon as I try to use FetchContent
, it fails inside the subbuild during download. A very simple project file such as:
cmake_minimum_required(VERSION 3.18)
cmake_policy(VERSION 3.18...3.25)
project(CMakeBug2
LANGUAGES CXX)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG e2239ee6043f73722e7aa812a459f54a28552929 # release-1.11.0)
FetchContent_MakeAvailable(googletest)
add_executable(${PROJECT_NAME} Main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE gtest)
Breaks with the following message:
-- The CXX compiler identification is Clang 16.0.0 with MSVC-like command-line
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Kellekek/Microsoft/VisualStudio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:10 (project):
Failed to run MSBuild command:
C:/Kellekek/Microsoft/VisualStudio/2022/BuildTools/MSBuild/Current/Bin/amd64/MSBuild.exe
to get the value of VCTargetsPath:
MSBuild version 17.4.1+9a89d02ff for .NET Framework
Build started 2023. 02. 09. 17:15:28.
Project "C:\Users\mate\Source\CMakeBug2\.vscode\build\msbuild-clang-rocm\_deps\googletest-subbuild\CMakeFiles\3.25.1\VCTargetsPath.vcxproj" on node 1 (default targets).
C:\Kellekek\Microsoft\VisualStudio\2022\BuildTools\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(442,5): error MSB8020: The build tools for HIP_clang (Platform Toolset = 'HIP_clang') cannot be found. To build using the HIP_clang build tools, please install HIP_clang build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\Users\mate\Source\CMakeBug2\.vscode\build\msbuild-clang-rocm\_deps\googletest-subbuild\CMakeFiles\3.25.1\VCTargetsPath.vcxproj]
Done Building Project "C:\Users\mate\Source\CMakeBug2\.vscode\build\msbuild-clang-rocm\_deps\googletest-subbuild\CMakeFiles\3.25.1\VCTargetsPath.vcxproj" (default targets) -- FAILED.
Build FAILED.
"C:\Users\mate\Source\CMakeBug2\.vscode\build\msbuild-clang-rocm\_deps\googletest-subbuild\CMakeFiles\3.25.1\VCTargetsPath.vcxproj" (default target) (1) ->
(PrepareForBuild target) ->
C:\Kellekek\Microsoft\VisualStudio\2022\BuildTools\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(442,5): error MSB8020: The build tools for HIP_clang (Platform Toolset = 'HIP_clang') cannot be found. To build using the HIP_clang build tools, please install HIP_clang build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\Users\mate\Source\CMakeBug2\.vscode\build\msbuild-clang-rocm\_deps\googletest-subbuild\CMakeFiles\3.25.1\VCTargetsPath.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.16
Exit code: 1
-- Configuring incomplete, errors occurred!
See also "C:/Users/mate/Source/CMakeBug2/.vscode/build/msbuild-clang-rocm/_deps/googletest-subbuild/CMakeFiles/CMakeOutput.log".
CMake Error at C:/Kellekek/Kitware/CMake/3.25.1/share/cmake-3.25/Modules/FetchContent.cmake:1604 (message):
CMake step for googletest failed: 1
Call Stack (most recent call first):
C:/Kellekek/Kitware/CMake/3.25.1/share/cmake-3.25/Modules/FetchContent.cmake:1756:EVAL:2 (__FetchContent_directPopulate)
C:/Kellekek/Kitware/CMake/3.25.1/share/cmake-3.25/Modules/FetchContent.cmake:1756 (cmake_language)
C:/Kellekek/Kitware/CMake/3.25.1/share/cmake-3.25/Modules/FetchContent.cmake:1970 (FetchContent_Populate)
CMakeLists.txt:18 (FetchContent_MakeAvailable)
-- Configuring incomplete, errors occurred!
See also "C:/Users/mate/Source/CMakeBug2/.vscode/build/msbuild-clang-rocm/CMakeFiles/CMakeOutput.log".
Notice how CMAKE_GENERATOR_INSTANCE
is set to C:\Kellekek\Microsoft\VisualStudio\2022\Community
and that's where the compiler gets picked up when the project()
command is encountered, but when it's trying to download Google Test, it's using MSBuild from C:/Kellekek/Microsoft/VisualStudio/2022/BuildTools
, but that VS instance doesn't have this toolset installed. The trace gives a hint at where things go south. I added
if(CMAKE_GENERATOR_INSTANCE)
list(APPEND subCMakeOpts "-DCMAKE_GENERATOR_INSTANCE:STRING=${CMAKE_GENERATOR_INSTANCE}")
endif()
to FetchContent.cmake
and that seems to solve this issue of the wrong instance being picked in FetchContent.