Use CMake Converter¶
To use CMake Converter, simply give your
vcxproj file to cmake-converter command:
cmake-converter -p /path/to/your/project.vcxproj
cmake-converter command accepts a lot of parameters to try to suit the majority of situations.
CMake-Converter command line interface:
Usage: cmake-converter [-h] cmake-converter [-V] cmake-converter (-s solution | -p project) [-i] [-c cmake] [-D dependency...] [-O cmakeoutput] [-a codefile] [-I cmakefile] [-S std] Options: -h, --help Show this help message and exit -V, --version Show application version -s, --solution=solution Path to a MSVC solution (.sln) (BETA) -p, --project=project Path to a MSVC project (.vcxproj) -c, --cmake=cmake Specify output of generated CMakeLists.txt -D, --dependencies=dep Replace dependencies found in ".vcxproj" file. This parameter, can be used multiple times for each dependency. -O, --cmakeoutput=output Define output of artefact produces by CMake. -i, --include Add include directories in CMakeLists.txt. [default: False] -a, --additional=file Import cmake code from any file to generated CMakeLists.txt. -I, --includecmake=file Add Include directive for given file in CMakeLists.txt. -S, --std=std Choose your C++ std version. [default: c++11] Use cases: Display help message: cmake-converter (-h | --help) Display current version: cmake-converter (-V | --version) Convert an MSVC project and defines output of artefacts: cmake-converter -p ../msvc/foo/foo.vcxproj -c ../cmake/foo -O ../build/compiler Convert an MSVC project and add ".cmake" file: cmake-converter -p ../msvc/foo/foo.vcxproj -I ../cmake/foo/file.cmake Convert an MSVC project with specific STD version: cmake-converter -p ../msvc/foo/foo.vcxproj -c ../cmake/foo -S c++17 Hint and tips: It is important to check that the generated CMake files are working properly before using them in production. CMake Converter only manage Debug and Release build types. You can provide the build type by add "-DCMAKE_BUILD_TYPE=<BUILD_TYPE>" to cmake command. CMake-Converter will try to respect as much as possible the data of your MSVC project. However, it is necessary to pay attention to the relative paths of the files. If your project is in the following path: "../msvc/foo", your CMakeLists file should have the same tree level. The same is to be done for the files to include ! Solutions conversion: The solution conversion is still in BETA and may therefore have some problems ! Your Visual Studio projects must each have their respective folders for the conversion to work. Note that the "--dependencies" and "--cmake" parameters are not used during solution conversion !
With the following project structure:
project/ ├── cmake │ ├── additional_code.txt │ └── File.cmake └── msvc ├── myexec.sln └── myexec.vcxproj
You can use cmake-converter as follows:
cmake-converter \ --project=../project/msvc/myexec.vcxproj \ --cmake=../project/cmake/ \ --cmakeoutput=../project/cmake \ --additional=../project/cmake/additional_code.txt \ --includecmake=../cmake/File.cmake \ --std=c++17 \ --include
With CMake-Converter, you can also convert full Visual Studio solutions. For the moment, this feature is still in BETA, but remains functional.
The script will extract data from all vcxproj and create the corresponding CMakeLists.txt.
vcxproj included in the solution must be in a dedicated directory, to ensure the smooth conversion.
--cmake parameters can not be used (and will not be used) during solution conversion !
With the following project structure:
project/ ├── externals │ └── cmake │ └── File.cmake └── msvc ├── libone │ └── libone.vcxproj ├── libtwo │ └── libtwo.vcxproj └── myexec ├── myexec.sln └── myexec.vcxproj
Then you’ll run cmake-converter as follow:
cmake-converter \ --solution=project/msvc/myexec/myexec.sln \ --cmakeoutput=project/build/x64/ \ --includecmake=../../externals/cmake/File.cmake \ --std=c++17 \ --include
And you’ll have the following CMakeLists.txt generated:
project/ ├── externals │ └── cmake │ └── File.cmake └── msvc ├── libone │ ├── CMakeLists.txt * │ └── libone.vcxproj ├── libtwo │ ├── CMakeLists.txt * │ └── libtwo.vcxproj └── myexec ├── CMakeLists.txt * ├── myexec.sln └── myexec.vcxproj
If you use —cmake parameter, ensure that given path has same directory level than your .vcxproj.
If you use —includecmake parameter, you have to give path relative to project itself, and not for script !
You can use CMake variables in parameters, by escaping
$ with a backslash. Example:
If you use variables defined by yourself, make sure that they are defined in a .cmake file or the code you are importing !