This does not work for me when I use Visual Studio 2022. However, when I use cmake from the command line, then it works. So apparently, the cmake in Visual Studio does things a little bit differently.
My hope is vanishing that I can get this to work in Visual Studio, but can you have a look to see if there’s something that I can change, so that it works in Visual Studio too? I’ll try to show in detail what I have and what the error is.
This is the top part of the top level CMakeLists.txt of amp-hal-st, the project that tries to use a repository to obtain the toolchain from:
cmake_minimum_required(VERSION 3.24)
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(HALST_STANDALONE On)
endif()
if (HALST_STANDALONE)
include(FetchContent)
FetchContent_Declare(
emil
GIT_REPOSITORY https://github.com/philips-software/embeddedinfralib.git
GIT_TAG modern-cmake
)
message("Before FetchContent_MakeAvailable")
FetchContent_MakeAvailable(emil)
message("After FetchContent_MakeAvailable")
endif()
This is a configurePreset from CMakePresets.json, which I selected in Visual Studio 2022. Its toolchainFile points into the soon-to-be downloaded repository that holds the toolchain file:
{
"name": "stm32wb55cg",
"displayName": "stm32wb55cg",
"description": "Build for stm32wb55cg",
"inherits": "stm32",
"toolchainFile": "${sourceDir}/build/stm32wb55cg/_deps/emil-src/cmake/toolchain-arm-gcc-m4-fpv4-sp-d16.cmake",
When I try to configure with that preset I run into this error:
1> Working directory: C:/DEV/Metronome/amp-hal-st/build/stm32wb55cg
1> [CMake] Before FetchContent_MakeAvailable
1> [CMake] CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/CMakeDetermineSystem.cmake:130 (message):
1> [CMake] Could not find toolchain file:
1> [CMake] C:/DEV/Metronome/amp-hal-st/build/stm32wb55cg/_deps/emil-src/cmake/toolchain-arm-gcc-m4-fpv4-sp-d16.cmake
1> [CMake] Call Stack (most recent call first):
1> [CMake] CMakeLists.txt:10 (project)
1> [CMake] CMake Error: CMake was unable to find a build program corresponding to "Ninja Multi-Config". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
1> [CMake] -- Configuring incomplete, errors occurred!
1> [CMake]
1> [CMake] CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FetchContent.cmake:1589 (message):
1> [CMake] CMake step for emil failed: 1
1> [CMake] Call Stack (most recent call first):
1> [CMake] C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FetchContent.cmake:1741:EVAL:2 (__FetchContent_directPopulate)
1> [CMake] C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FetchContent.cmake:1741 (cmake_language)
1> [CMake] C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FetchContent.cmake:1955 (FetchContent_Populate)
1> [CMake] CMakeLists.txt:18 (FetchContent_MakeAvailable)
1> [CMake] -- Configuring incomplete, errors occurred!
There are two errors here. First, it says that it cannot find the toolchain file. Second, it says that it is unable to find a build a build program for Ninja. However, that seems to be just follow-up damage; if I remove the generator in the configurePreset, then that second error disappears but the first error about the missing toolchain file remains.
After producing these errors, the amp-hal-st/build/stm32wb55cg directory looks like this:
.cmake
<more files>
_deps
emil-subbuild
CMakeFiles
<more files>
CMakeCache.txt
CMakeLists.txt
CMakeFiles
<more files>
_deps/emil-subbuild/CMakeLists.txt contains the offending “project(emil-populate NONE)” call:
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
cmake_minimum_required(VERSION 3.24.202208181-MSVC_2)
# We name the project and the target for the ExternalProject_Add() call
# to something that will highlight to the user what we are working on if
# something goes wrong and an error message is produced.
project(emil-populate NONE)
That is what the error points to: line 10 of that file contains a “project” call, the toolchain file is necessary, that toolchain file is not yet present at _deps/emil-src/cmake because it hasn’t been downloaded yet, and then the configuration fails. The display of the message “Before FetchContent_MakeAvailable” and the absence of the message “After FetchContent_MakeAvailable” show that this error occurs during the FetchContent_MakeAvailable call itself.
Is there anything that I can configure so that Visual Studio is able to FetchContent the repo with the toolchain?
Edit:
Apparently as a new user I’m limited to only three posts in a subject, and I’ve only got a small note to add:
Thank you very much for your response, I’ve got it now working!
The workaround is completely acceptable for me.