问题
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>
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)
回答1:
How about using the vcpkg it is an easy way of compiling libraries/driver.
Download vcpkg follow the instructions as mentioned on git. https://github.com/Microsoft/vcpkg
Step 1 C:\vcpkg>.\vcpkg search mongodb
you will see something like that
mongo-c-driver 1.6.2-1 Client library written in C for MongoDB.
mongo-cxx-driver 3.1.1-1 MongoDB C++ Driver.
Step 2 C:.\vcpkg search mongodb install mongo-cxx-driver
then grab cup of coffee ....
Stap 3
C:\vcpkg>.\vcpkg integrate install
Done..
Note Prerequisites:
Windows 10, 8.1, or 7
Visual Studio 2017 or Visual Studio 2015 Update 3
then simply create a project and add the required include in the project .
Answered by @JoyoWaseem
How can I build a program using c++ driver of MongoDB?
来源:https://stackoverflow.com/questions/44737859/generating-visual-studio-2017-projects-with-cmake