Vcxproj2cmake
Tool to convert Microsoft Visual C++ projects and solutions to CMake
Install / Use
/learn @chausner/Vcxproj2cmakeREADME
vcxproj2cmake
<p align="center"><img src="vcxproj2cmake.webp" alt="Logo" width="200" /></p>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
.vcxprojproject 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).
-
The following MSBuild project properties are taken into account and converted to their CMake equivalents:
AdditionalDependenciesAdditionalIncludeDirectoriesAdditionalLibraryDirectoriesAdditionalOptionsAllProjectIncludesArePublicCharacterSetDisableSpecificWarningsExternalWarningLevelIncludePathLanguageStandardLanguageStandard_CLibraryPathLinkLibraryDependenciesModuleDefinitionFileOpenMPSupportPrecompiledHeaderFilePreprocessorDefinitionsPublicIncludeDirectoriesRuntimeLibrarySubSystemTargetNameTreatAngleIncludeAsExternalTreatSpecificWarningsAsErrorsTreatWarningAsErrorUseOfMfcWarningLevel -
For projects referencing Qt 5 or 6 via Qt/MsBuild, a corresponding
find_package(Qt... REQUIRED COMPONENTS ...)command is generated andAUTOMOC/AUTOUIC/AUTORCCare enabled. -
For projects referencing Conan packages via the
MSBuildDepsgenerator, correspondingfind_packagecommands are generated, intended to be used with theCMakeDepsgenerator.
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.
Customizing Output
- Specify the
--include-headersoption to include header files in the list of CMake target sources set viatarget_sourcescommand. This allows IDEs to recognize header files as part of the project and e.g. show them in the project tree. - Specify the
--enable-standalone-project-buildsoption to include additional CMake commands in the generated projectCMakeLists.txtfiles to allow configuring the projects directly instead of as part of the top-level solutionCMakeLists.txt. - If any of your projects use Qt, you must specify the
--qt-versionoption to indicate the Qt version (5 or 6) used in the project. - Use options
--indent-styleand--indent-sizeto customize the indentation in the generated CMake files. - Specify the
--dry-runoption to have the generated CMake files printed to the console without writing them to disk.
Example
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:
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MathLib", "MathLib\MathLib.vcxproj", "{4D944B1C-9EBF-4086-AE57-25DDEBF92F0D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App", "App\App.vcxproj", "{07DC28F8-AB37-42B2-A0C4-82D4766A9166}"
ProjectSection(ProjectDependencies) = postProject
{4D944B1C-9EBF-4086-AE57-25DDEBF92F0D} = {4D944B1C-9EBF-4086-AE57-25DDEBF92F0D}
EndProjectSection
EndProject
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.sln
[ExampleSolution.sln] Parsing ..\ExampleSolution\ExampleSolution.sln
[MathLib.vcxproj] Parsing ..\ExampleSolution\MathLib\MathLib.vcxproj
[App.vcxproj] Parsing ..\ExampleSolution\App\App.vcxproj
[MathLib.vcxproj] Processing project ..\ExampleSolution\MathLib\MathLib.vcxproj
[App.vcxproj] Processing project ..\ExampleSolution\App\App.vcxproj
[MathLib.vcxproj] Generating ..\ExampleSolution\MathLib\CMakeLists.txt
[App.vcxproj] Generating ..\ExampleSolution\App\CMakeLists.txt
[ExampleSolution.sln] Generating ..\ExampleSolution\CMakeLists.txt
ExampleSolution/MathLib/CMakeLists.txt:
cmake_minimum_required(VERSION 3.24)
project(MathLib LANGUAGES CXX)
add_library(MathLib STATIC)
target_sources(MathLib
PRIVATE
MathLib.cpp
)
target_compile_features(MathLib
PUBLIC
cxx_std_17
)
target_include_directories(MathLib
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)
target_compile_definitions(MathLib
PUBLIC
$<$<CONFIG:Debug>:DEBUG>
$<$<CONFIG:Release>:NDEBUG>
)
ExampleSolution/App/CMakeLists.txt:
cmake_minimum_required(VERSION 3.24)
project(App LANGUAGES CXX)
add_executable(App)
target_sources(App
PRIVATE
main.cpp
)
target_compile_features(App
PUBLIC
cxx_std_17
)
target_include_directories(App
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/../MathLib/include"
)
target_compile_definitions(App
PUBLIC
MATHLIB
$<$<CONFIG:Debug>:DEBUG>
$<$<CONFIG:Release>:NDEBUG>
)
target_link_libraries(App
PUBLIC
MathLib
)
target_compile_options(App
PUBLIC
$<$<CONFIG:Debug>:/W4>
$<$<CONFIG:Release>:/O2>
)
ExampleSolution/CMakeLists.txt:
cmake_minimum_required(VERSION 3.24)
project(ExampleSolution)
add_subdirectory(MathLib)
add_subdirectory(App)
Limitations
- vcxproj2cmake expects project configurations and build platforms to be named
Debug/ReleaseandWin32/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, extendConfig.Configsin 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
_DEBUGorWIN32are 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 linke
