2

It is any tool or possibility to convert a C++ CMake project into a C++ Visual Studio project with a .vcxproj file?

I need this because we want to offer CMake support at the project I'm working for, but we need to make this conversion first. I searched a lot and didn't find anything about this conversion, at least not yet.

Any opinion or suggestion is highly appreciated. Thank you!

Ionut Enache
  • 461
  • 8
  • 22
  • 1
    CMake generates `.vcxproj` files... Did you try to run CMake on your project to create the `.vcxproj` file? – Kevin Jul 19 '19 at 14:50
  • 1
    From a CMake file you can [generate a visual studio project](https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2016%202019.html), yes. – Botje Jul 19 '19 at 14:50

2 Answers2

3

This is what cmake does, generates projects for almost any IDE or build manager.

So for VS 2017 it can be used like this:

cd "<path where CMakeLists.txt is located>"
mkdir build
cd build
cmake -DCMAKE_CONFIGURATION_TYPES="Debug;Release" -DCMAKE_GENERATOR_PLATFORM=x64 -G "Visual Studio 15 2017" ..
cmake --open .
Marek R
  • 32,568
  • 6
  • 55
  • 140
1

CMake can natively generate VS solutions.

If you have visual studio installed CMake will use that as the default.

cd "<path where CMakeLists.txt is located>"

# Creates build folder if it doesn't already exist
# Assuming I only have VS2022 installed it will just use that by default
# If you want to be explicit you can use do `-G "Visual Studio 17 2022"`
cmake -B build/

# Open IDE (works for XCode/Visual Studio)
cmake --open build

Alternatively, Visual Studio also now natively reads CMake as well:

https://devblogs.microsoft.com/cppblog/whats-new-for-c-cross-platform-developers-in-visual-studio-2022/

So you can use Visual Studio as your editor, Ninja for building, and CMake to manage it. They have lots of great features for cross-platform development.