I am working on a Visual Studio 2013 project and would like to link it to a library that uses CMake to generate a build configuration. For example:
project
|-> src
|-> project.sln
|-> dep
|-> library
|-> src
|-> CMakeLists.txt
Is there a way to configure, build, and link my library to my project when I build the project in Visual Studio?
I would like to eventually make the whole project a CMake project and generate a comprehensive Visual Studio solution, but it is currently quite large and complicated. With limited time, I'm wondering what my best option is. Is there a clean way to do this with VS Custom Build commands?
To run an explicitely installed CMake you should download a CMake suitable for your platform from https://cmake.org/download install it and add the bin folder of the installation directory to your PATH variable, e.g. set PATH=C:\Program Files\CMake\bin;%PATH% on Windows.
Running CMake for Windows / Microsoft Visual C++ (MSVC)Run cmake-gui.exe, which should be in your Start menu under Program Files, there may also be a shortcut on your desktop, or if you built from source, it will be in the build directory.
The latest version of CMake tools is now available for download in the VS Code Marketplace or using the . vsix file.
Here is most simplified version of CMake's configuration and build steps.
Just create a Configuration Type / Utility project in the same folder as your CMakeLists.txt
and add:
Pre-Build Event / Command Line
IF NOT EXIST "bin\*.sln" ( cmake -H"." -B"bin" )
or for newer versions of CMake
IF NOT EXIST "bin\*.sln" (
cmake -H"." -B"bin" -DCMAKE_MAKE_PROGRAM:PATH="$(DevEnvDir)\devenv.exe"
)
Just because I personally don't like it to use msbuild.exe
(which would be the default).
Post-Build Event / Command Line
cmake --build "bin" --config "$(Configuration)"
Alternative
You can also create a root CMakeLists.txt
importing existing .vcproj
files via include_external_msproject()
commands:
cmake_minimum_required(VERSION 2.6)
project(project)
include_external_msproject(${PROJECT_NAME} src/${PROJECT_NAME}.vcxproj)
...
add_subdirectory(dep/library/src library)
Reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With