基于cmake的项目重建最新文件

时间:2019-01-14 21:32:23

标签: c++ cmake

有一个使用mongoc / mongocxx / mangrove的cmake项目, 添加为外部项目(独立脚本包含在cmakelists.txt中):

cmake_minimum_required(VERSION 3.10)

include(ExternalProject)

set(EXTERNAL_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/external)

# mongo-c-driver
ExternalProject_Add(mongo-c-driver
        GIT_REPOSITORY https://github.com/mongodb/mongo-c-driver.git
        GIT_TAG r1.13-debian
        CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF
        UPDATE_DISCONNECTED TRUE
        )
include_directories(${EXTERNAL_INSTALL_LOCATION}/include/libbson-1.0
        ${EXTERNAL_INSTALL_LOCATION}/include/libmongoc-1.0)
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)

# mongo-cxx-driver
ExternalProject_Add(mongo-cxx-driver
        GIT_REPOSITORY https://github.com/mongodb/mongo-cxx-driver.git
        GIT_TAG releases/stable
        CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} -DCMAKE_CXX_STANDARD=17 -DBSONCXX_POLY_USE_MNMLSTC=1.
        UPDATE_DISCONNECTED TRUE
        )
ExternalProject_Add_StepDependencies(mongo-cxx-driver build mongo-c-driver)
include_directories(${EXTERNAL_INSTALL_LOCATION}/include/bsoncxx/v_noabi
        ${EXTERNAL_INSTALL_LOCATION}/include/mongocxx/v_noabi)
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)

#                 mangrove
ExternalProject_Add(mangrove
        GIT_REPOSITORY https://github.com/amigo421/mangrove.git
        CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
        UPDATE_DISCONNECTED TRUE
        )

ExternalProject_Add_StepDependencies(mangrove build mongo-c-driver mongo-cxx-driver)

include_directories(${EXTERNAL_INSTALL_LOCATION}/include/mangrove/v_noabi
        ${EXTERNAL_INSTALL_LOCATION}/include/boson/v_noabi
        )
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)

主脚本(简化版)如下:

...
include(AddMongo)

add_executable(
        myproject
        main.cpp
        webclient.cpp
        bot.cpp
        #here are a required headers       
        ../othersources/settings.cpp
        ../othersources/restapi.cpp
)

add_dependencies(myproject mangrove mongo-cxx-driver  )
target_link_libraries(myproject
        Qt5::Core
        Qt5::Network
        Qt5::Positioning
        Qt5::Test Qt5::Widgets
        mongocxx
        bsoncxx
        boson
        )

因此,此项目始终会编译文件main.cpp webclient.cpp bot.cpp 甚至这些都是最新的。

看起来很奇怪,但是文件

../ othersources / settings.cpp

../ othersources / restapi.cpp

按预期工作-仅更改了编译。

知道为什么会这样吗? 我添加了包含文件的全文,因为如果我对此进行注释, 一切正常,符合预期

0 个答案:

没有答案