使用CMake生成Visual Studio 2017项目 [英] Generating Visual Studio 2017 projects with CMake
问题描述
我试图构建在项目中使用的Mongo C ++ 11驱动程序. Mongo驱动程序编译正常.使用它们的说明坚持认为,当将其用于自己的项目时,以下代码也应属于我的项目的.vcxproj
的一部分(如果使用Visual Studio,我在Windows 10 64bit上也要这样做).
I tried to build Mongo C++11 drivers for use in my project. The Mongo drivers compiles fine. Instruction on using them insist that when using for own project the following piece of code should also be part of the .vcxproj
of my project (if one use Visual Studio, which I do on Windows 10 64bit).
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>c:\local\boost_1_59_0\;C:\mongo-cxx-driver\include\mongocxx\v_noabi;C:\mongo-cxx-driver\include\bsoncxx\v_noabi;C:\mongo-c-driver\include\libmongoc-1.0;C:\mongo-c-driver\include\libbson-1.0;$(IncludePath)</IncludePath>
<LibraryPath>c:\mongo-c-driver\lib\;c:\mongo-cxx-driver\lib\;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>MONGOCXX_STATIC;BSONCXX_STATIC;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libmongocxx.lib;libbsoncxx.lib;mongoc-static-1.0.lib;bson-1.0.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
我需要哪种代码来确保这段代码自动包含在CMake生成的.vcxproj
中?
我的CMakeLists.txt如下.
What kind of code do I need to make sure that this piece of code is automatically included in my .vcxproj
generated by CMake?
My CMakeLists.txt is as below.
# CMakeLists.txt
# Building the test project
cmake_minimum_required(VERSION 3.7)
project(testing)
set(APP_SOURCES
test.cpp
)
link_directories(../../installed_mongocxx/lib)
add_executable(testapp ${APP_SOURCES})
target_link_libraries(testapp mongocxx bsoncxx)
target_include_directories(testapp PUBLIC
../../installed_mongocxx/include/mongocxx/v_noabi
../../installed_mongocxx/include/bsoncxx/v_noabi
E:/Software/Libraries/Boost/boost_1_64_0
)
install(TARGETS testapp
DESTINATION bin)
推荐答案
使用vcpkg怎么样,这是一种编译库/驱动程序的简便方法.
How about using the vcpkg it is an easy way of compiling libraries/driver.
按照git上的说明下载vcpkg. https://github.com/Microsoft/vcpkg
Download vcpkg follow the instructions as mentioned on git. https://github.com/Microsoft/vcpkg
步骤1 C:\ vcpkg>.\ vcpkg搜索mongodb
您会看到类似的东西
mongo-c-driver 1.6.2-1用C语言编写的MongoDB客户端库.
mongo-c-driver 1.6.2-1 Client library written in C for MongoDB.
mongo-cxx驱动程序3.1.1-1 MongoDB C ++驱动程序.
mongo-cxx-driver 3.1.1-1 MongoDB C++ Driver.
步骤2 C:.\ vcpkg搜索mongodb安装mongo-cxx-driver
然后抢一杯咖啡....
then grab cup of coffee ....
第3步
C:\ vcpkg>.\ vcpkg集成安装
完成..
注意前提条件:
Windows 10、8.1或7
Windows 10, 8.1, or 7
Visual Studio 2017或Visual Studio 2015 Update 3
Visual Studio 2017 or Visual Studio 2015 Update 3
然后只需创建一个项目,然后在项目中添加所需的包含.
then simply create a project and add the required include in the project .
由@JoyoWaseem回答
Answered by @JoyoWaseem
这篇关于使用CMake生成Visual Studio 2017项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!