Ionut Enache
Ionut Enache

Reputation: 521

Convert CMake.txt to .vcxproj file C++ Visual Studio project

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!

Upvotes: 2

Views: 5169

Answers (2)

user15308163
user15308163

Reputation:

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.

Upvotes: 1

Marek R
Marek R

Reputation: 38112

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 .

Upvotes: 4

Related Questions