我有很多外部依賴關係,我想用ExternalProject_Add
來拉入我的項目。訣竅是以最簡潔的方式導出包含目錄和生成的靜態鏈接庫。建立作爲ExternalProject_Add Boost並且或者FindBoost或者導出結果
是否有可能使FindBoost
依賴於ExternalProject_Add
或者至少使用target_link_libraries
將項目拉入庫和頭中?
升壓
include(ExternalProject)
set(boost_URL "http://sourceforge.net/projects/boost/files/boost/1.63.0/boost_1_63_0.tar.bz2")
set(boost_SHA1 "9f1dd4fa364a3e3156a77dc17aa562ef06404ff6")
set(boost_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/third_party/boost)
set(boost_INCLUDE_DIR ${boost_INSTALL}/include)
set(boost_LIB_DIR ${boost_INSTALL}/lib)
ExternalProject_Add(external_boost
PREFIX boost
URL ${boost_URL}
URL_HASH SHA1=${boost_SHA1}
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ./bootstrap.sh
--with-libraries=filesystem
--with-libraries=system
--with-libraries=date_time
--prefix=<INSTALL_DIR>
BUILD_COMMAND
./b2 install link=static variant=release threading=multi runtime-link=static
INSTALL_COMMAND ""
INSTALL_DIR ${boost_INSTALL})
set(boost_LIBRARY_SUFFIX .a)
add_library(boost::date_time STATIC IMPORTED)
set_property(TARGET boost::date_time PROPERTY IMPORTED_LOCATION ${boost_LIB_DIR}/libboost_date_time${boost_LIBRARY_SUFFIX})
set_property(TARGET boost::date_time PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${boost_INCLUDE_DIR})
add_dependencies(boost::date_time external_boost)
add_library(boost::system STATIC IMPORTED)
set_property(TARGET boost::system PROPERTY IMPORTED_LOCATION ${boost_LIB_DIR}/libboost_system${boost_LIBRARY_SUFFIX})
set_property(TARGET boost::system PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${boost_INCLUDE_DIR})
add_dependencies(boost::system external_boost)
add_library(boost::filesystem STATIC IMPORTED)
set_property(TARGET boost::filesystem PROPERTY IMPORTED_LOCATION ${boost_LIB_DIR}/libboost_filesystem${boost_LIBRARY_SUFFIX})
set_property(TARGET boost::filesystem PROPERTY INTERFACE_LINK_LIBRARIES boost::system)
set_property(TARGET boost::filesystem PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${boost_INCLUDE_DIR})
add_dependencies(boost::filesystem external_boost)