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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.