-
Notifications
You must be signed in to change notification settings - Fork 47
[Foxy] - colcon build C++ with Visual Studio 2022 - change CMake version #440
Description
We are setting up ROS2 in our labs, with Visual Studio 2022 already installed. I try to build Cpp examples with colcon, however, it seems like the version of Cmake that is provided along with Foxy does not yet know the VS2022, so the build fails. I know that according to the official docs, only VS up to 2019 are supported, however in our case it would be beneficial to avoid installing another VS.
ROS2 Foxy was installed from binaries with Chocolately according to: https://ms-iot.github.io/ROSOnWindows/GettingStarted/SetupRos2.html
Could please suggest any option (colcon argument or env variable) to change the Cmake.exe path during the colcon build?
My steps:
The initial error pointed me to the C:\opt\ros\foxy\x64\Lib\site-packages\colcon_cmake\task\cmake\build.py script:
…
--- stderr: cpp_pubsub
Traceback (most recent call last):
File "c:\opt\ros\foxy\x64\lib\site-packages\colcon_core\executor\__init__.py", line 91, in __call__
rc = await self.task(*args, **kwargs)
File "c:\opt\ros\foxy\x64\lib\site-packages\colcon_core\task\__init__.py", line 93, in __call__
return await task_method(*args, **kwargs)
File "c:\opt\ros\foxy\x64\lib\site-packages\colcon_ros\task\ament_cmake\build.py", line 59, in build
rc = await extension.build(
File "c:\opt\ros\foxy\x64\lib\site-packages\colcon_cmake\task\cmake\build.py", line 87, in build
rc = await self._reconfigure(args, env)
File "c:\opt\ros\foxy\x64\lib\site-packages\colcon_cmake\task\cmake\build.py", line 163, in _reconfigure
raise RuntimeError(
RuntimeError: Unknown / unsupported VS version '17.0'
…
Which was easily "fixed" by appending '17.0': 'Visual Studio 17 2022' to the dictionary:
supported_vsv = {
'17.0': 'Visual Studio 17 2022',
'16.0': 'Visual Studio 16 2019',
'15.0': 'Visual Studio 15 2017',
'14.0': 'Visual Studio 14 2015',
}
A new attempt to build now suggests that the Cmake provided with the Foxy does not recognize the VS 2022 C++ compiler:
…
--- stderr: cpp_pubsub
CMake Error: Could not create named generator Visual Studio 17 2022
Generators
Visual Studio 16 2019 = Generates Visual Studio 2019 project files.
Use -A option to specify architecture.
Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 9 2008 [arch] = Generates Visual Studio 2008 project files.
Optional [arch] can be "Win64" or "IA64".
Borland Makefiles = Generates Borland makefiles.
…
By checking the version C:\opt\ros\foxy\x64\Scripts\cmake.exe --version I could see that the default vesion of CMake is 3.18.2. I hoped, that by installing a newer version of Cmake (3.23.3) and by prepending the PATH env var with its corresponding path (C:\Program Files\CMake\bin) would be sufficient to force Colcon to utilize the different version of Cmake. But it wasn't :) .
Could please suggest any option (colcon argument or env variable) to change the Cmake.exe path during the colcon build?