Skip to content

chausner/vcxproj2cmake

Repository files navigation

vcxproj2cmake

Logo

GitHub release (latest by date) Code coverage license

vcxproj2cmake is a tool designed to convert Microsoft Visual C++ project files (.vcxproj) to equivalent CMake files (CMakeLists.txt).

Features

  • Accepts either a list of .vcxproj project files or Visual Studio solution files (.sln/.slnx) as input.

  • Supports console, Win32, Dynamic-Link Library (DLL), and Static Library project types. Includes detection of header-only libraries.

  • Leverages CMake generator expressions for property values that are specific to certain build configurations (Debug, Release, Win32, x64).

  • Supports the following file types: C sources/headers, C++ sources/headers, C++ modules, .manifest, MASM, .rc, .natvis.

  • The following MSBuild project properties are converted to their CMake equivalents:

    AdditionalDependencies AdditionalIncludeDirectories AdditionalLibraryDirectories AdditionalOptions AllProjectIncludesArePublic BasicRuntimeChecks CharacterSet DisableSpecificWarnings ExternalWarningLevel IncludePath LanguageStandard LanguageStandard_C LibraryPath LinkLibraryDependencies ModuleDefinitionFile OpenMPSupport PrecompiledHeaderFile PreprocessorDefinitions PublicIncludeDirectories RuntimeLibrary SubSystem TargetName TreatAngleIncludeAsExternal TreatLinkerWarningAsErrors TreatSpecificWarningsAsErrors TreatWarningAsError UseOfMfc WarningLevel

  • For projects referencing Qt 5 or 6 via Qt/MsBuild, a corresponding find_package(Qt... REQUIRED COMPONENTS ...) command is generated and AUTOMOC/AUTOUIC/AUTORCC are enabled.

  • For projects referencing Conan packages via the MSBuildDeps generator, corresponding find_package commands are generated, intended to be used with the CMakeDeps generator.

Usage

Download the latest release from the releases page and unzip it to a directory of your choice.

Basic Usage

Single Project

To convert a single .vcxproj file with no dependency to other projects, run:

.\vcxproj2cmake --projects MyProject.vcxproj

This will generate a CMakeLists.txt file in the same directory as the .vcxproj file.

Multiple Projects

If the project has dependencies on other projects, or you want to convert multiple projects at once, specify the paths to all .vcxproj files:

.\vcxproj2cmake --projects MyProject1.vcxproj MyProject2.vcxproj

This will generate a CMakeLists.txt file for each specified project in their respective directories.

Solution File

If you have a Visual Studio solution file (.sln or .slnx), you can convert all projects in the solution by running:

.\vcxproj2cmake --solution MySolution.sln

This will generate a CMakeLists.txt file for each project next to the .vcxproj file, as well as a top-level CMakeLists.txt file in the same directory as the solution file.

Advanced Options

Option(s) Description
--include-headers Includes header files in the list of CMake target sources set via target_sources, allowing IDEs to display them as part of the project.
--enable-standalone-project-builds Adds extra CMake commands to generated project CMakeLists.txt files so the projects can be configured independently of the top‑level solution.
--qt-version Specifies the Qt version used by any project that depends on Qt.
--portable Wraps MSVC‑specific CMake settings in generator expressions so they are ignored when using non‑MSVC compilers.
--indent-style / --indent-size Customizes indentation style and size in generated CMake files.
--dry-run Prints generated CMake files to the console instead of writing them to disk.

For more information, run with the --help argument.

Example

Click to expand

The repository contains a small demo solution under ExampleSolution. It consists of a static library project MathLib and an application project App that depends on the library. The solution references both projects and the application has a project reference to MathLib.

The top-level solution looks like this:

<Solution>
  <Configurations>
    <Platform Name="Win32" />
  </Configurations>
  <Project Path="App/App.vcxproj" Id="d4f63c17-b31b-4b33-b304-593051868748" />
  <Project Path="MathLib/MathLib.vcxproj" Id="620c346a-996a-4c2b-8485-4a872433008b" />
</Solution>

MathLib.vcxproj includes a header and source file. It also demonstrates configuration-specific options:

<ItemGroup>
  <ClInclude Include="include\MathLib.h" />
  <ClCompile Include="MathLib.cpp" />
</ItemGroup>
<ItemDefinitionGroup>
  <ClCompile>
    <AdditionalIncludeDirectories>include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
  </ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
  <ClCompile>
    <PreprocessorDefinitions>DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    <LanguageStandard>stdcpp17</LanguageStandard>
  </ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
  <ClCompile>
    <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    <LanguageStandard>stdcpp17</LanguageStandard>
  </ClCompile>
</ItemDefinitionGroup>

App.vcxproj references the library project, adds its include directory and sets similar configuration-specific defines and compiler options:

<ItemDefinitionGroup>
  <ClCompile>
    <AdditionalIncludeDirectories>..\MathLib\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
  </ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
  <ClCompile>
    <PreprocessorDefinitions>MATHLIB;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    <LanguageStandard>stdcpp17</LanguageStandard>
    <WarningLevel>Level4</WarningLevel>
  </ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
  <ClCompile>
    <PreprocessorDefinitions>MATHLIB;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    <AdditionalOptions>/O2 %(AdditionalOptions)</AdditionalOptions>
    <LanguageStandard>stdcpp17</LanguageStandard>
  </ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
  <ProjectReference Include="..\MathLib\MathLib.vcxproj" />
</ItemGroup>

Running the converter on the solution generates three CMakeLists.txt files:

> .\vcxproj2cmake --solution ..\ExampleSolution\ExampleSolution.slnx
[ExampleSolution.slnx] Parsing ..\ExampleSolution\ExampleSolution.slnx
[App.vcxproj] Parsing ..\ExampleSolution\App\App.vcxproj
[MathLib.vcxproj] Parsing ..\ExampleSolution\MathLib\MathLib.vcxproj
[App.vcxproj] Processing project ..\ExampleSolution\App\App.vcxproj
[MathLib.vcxproj] Processing project ..\ExampleSolution\MathLib\MathLib.vcxproj
[App.vcxproj] Generating ..\ExampleSolution\App\CMakeLists.txt
[MathLib.vcxproj] Generating ..\ExampleSolution\MathLib\CMakeLists.txt
[ExampleSolution.slnx] Generating ..\ExampleSolution\CMakeLists.txt

ExampleSolution/MathLib/CMakeLists.txt:

cmake_minimum_required(VERSION 4.0)
project(MathLib LANGUAGES CXX)

add_library(MathLib STATIC)

target_sources(MathLib
    PRIVATE
        MathLib.cpp
)

target_compile_features(MathLib
    PRIVATE
        cxx_std_17
)

target_include_directories(MathLib
    PRIVATE
        "${CMAKE_CURRENT_SOURCE_DIR}/include"
)

target_compile_definitions(MathLib
    PRIVATE
        "$<$<CONFIG:Debug>:DEBUG>"
        "$<$<CONFIG:Release>:NDEBUG>"
)

ExampleSolution/App/CMakeLists.txt:

cmake_minimum_required(VERSION 4.0)
project(App LANGUAGES CXX)

add_executable(App)

target_sources(App
    PRIVATE
        main.cpp
)

target_compile_features(App
    PRIVATE
        cxx_std_17
)

target_include_directories(App
    PRIVATE
        "${CMAKE_CURRENT_SOURCE_DIR}/../MathLib/include"
)

target_compile_definitions(App
    PRIVATE
        MATHLIB
        "$<$<CONFIG:Debug>:DEBUG>"
        "$<$<CONFIG:Release>:NDEBUG>"
)

target_link_libraries(App
    PRIVATE
        MathLib
)

target_compile_options(App
    PRIVATE
        "$<$<CONFIG:Debug>:/W4>"
        "$<$<CONFIG:Release>:/O2>"
)

ExampleSolution/CMakeLists.txt:

cmake_minimum_required(VERSION 4.0)
project(ExampleSolution)

add_subdirectory(MathLib)
add_subdirectory(App)

Limitations

  • vcxproj2cmake expects project configurations and build platforms to be named Debug/Release and Win32/x86/x64/ARM32/ARM64, respectively. Configurations and platforms with other names are ignored by default. If you would like to add support for your custom configurations/platforms, extend Config.Configs in Config.cs.
  • MSBuild properties whose value depends on the build configuration or platform are only supported if the value depends solely on the configuration or platform, but not both. E.g. preprocessor definitions like _DEBUG or WIN32 are supported. They are converted to CMake generator expressions like $<$<CONFIG:Debug>:_DEBUG> or $<$<STREQUAL:${CMAKE_CXX_COMPILER_ARCHITECTURE_ID},x86>:WIN32>. A definition that is specific to a certain combination of configuration and platform, is not supported and skipped with a warning.
  • MSBuild properties defined in imported .props or .targets files are not considered.
  • Many advanced compiler and linker options are not supported and silently ignored. Only a limited set of commonly-used properties is converted, as listed in the Features section.

Note

Due to the complexity of MSBuild, the conversion works best for projects of low-to-medium complexity. The generated CMake files may require manual adjustments, especially for larger projects with complex configurations or custom build steps. Still, it can be a useful starting point for migrating projects to CMake and can save a lot of time compared to writing the CMake files from scratch.

Contributing

Contributions of any kind (e.g. bug fixes, improvements or new features) are gladly accepted!

About

Tool to convert Microsoft Visual C++ projects and solutions to CMake

Topics

Resources

License

Stars

20 stars

Watchers

2 watching

Forks

Contributors

Languages