gpt4 book ai didi

boost - 如何使用 cmake 从 Boost 克隆特定子模块

转载 作者:行者123 更新时间:2023-12-04 03:13:52 26 4
gpt4 key购买 nike

我知道如何使用 b2 安装 Boost命令并指定仅安装文件系统库。 Boost 目录有很多我不需要的内容,而且克隆所有子模块需要很长时间。我有这个 cmake 文件可以下载、构建和安装 Boost。但是我不知道如何在 CMakeLists.txt 中指定要克隆的子模块。 .我正在使用 ExternalProject_add下载、构建和安装 Boost。

cmake_minimum_required(VERSION 2.8)
include(ExternalProject)
# Download boost from git

SET (BOOST_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/boost/src/boost/lib/filesystem/include/boost/)
SET (BOOST_URL https://github.com/boostorg/boost.git )
get_filename_component(BOOST_STATIC_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/lib/libboost_filesystem.a ABSOLUTE)

if ( UNIX )
SET (BOOST_STATIC_LIBRARIES ${BOOST_BUILD}/libboost_filesystem.a)
endif ()

ExternalProject_Add(
boost
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/boost
GIT_REPOSITORY ${BOOST_URL}

UPDATE_COMMAND ./bootstrap.sh --with-libraries=filesystem,system
CONFIGURE_COMMAND ""
BUILD_COMMAND ./b2 link=static install --exec-prefix=${CMAKE_BINARY_DIR}/lib/ --includedir=${CMAKE_BINARY_DIR}/include/boost/
BUILD_IN_SOURCE 1
INSTALL_COMMAND ""
)

set(BOOST_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/lib)
message ("${BOOST_STATIC_LIBRARIES}")

编辑

我现在有以下 CMakeLists.txt文件:
cmake_minimum_required(VERSION 2.8)
include(ExternalProject)
# Download boost from git
SET (BOOST_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/boost/src/boost/lib/filesystem/include/boost/)
SET (BOOST_URL https://github.com/boostorg/boost.git )
get_filename_component(BOOST_STATIC_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/lib/libboost_filesystem.a ABSOLUTE)

if ( UNIX )
SET (BOOST_STATIC_LIBRARIES ${BOOST_BUILD}/libboost_filesystem.a)
endif ()

ExternalProject_Add(
boost
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/boost
GIT_REPOSITORY ${BOOST_URL}
GIT_SUBMODULES libs/assert libs/utility libs/config libs/predef libs/system libs/detail libs/filesystem tools/boostdep tools/build tools/bcp tools/boostbook tools/inspect tools/litre tools/quickbook tools/auto_index
UPDATE_COMMAND ./bootstrap.sh --with-libraries=filesystem,system
CONFIGURE_COMMAND ./b2 headers
BUILD_COMMAND ./b2 link=static install
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/lib
BUILD_IN_SOURCE 1
INSTALL_COMMAND ""
)

set(BOOST_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/lib)
message ("${BOOST_STATIC_LIBRARIES}")

但我收到此错误消息:
...patience...
...found 925 targets...
...updating 337 targets...
common.mkdir /usr/local/include/boost
mkdir: Unable to create directory "/usr/local/include/boost": Permission denied.

mkdir -p "/usr/local/include/boost"

...failed common.mkdir /usr/local/include/boost...

但在 cmake 文件中我使用这个:
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/lib

安装在与 root 不同的目录中。
但它似乎不起作用。

编辑 2:

我知道如何安装在与 root 不同的目录中。但似乎还有另一个问题,因为与以前相同的问题发生了。我能做些什么?

我添加了这个:
UPDATE_COMMAND ./bootstrap.sh --with-libraries=filesystem,system --includedir=${CMAKE_BINARY_DIR}/include/


cmake_minimum_required(VERSION 2.8)
include(ExternalProject)
# Download boost from git
SET (BOOST_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/boost/src/boost/lib/filesystem/include/boost/)
SET (BOOST_URL https://github.com/boostorg/boost.git )
get_filename_component(BOOST_STATIC_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/lib/libboost_filesystem.a ABSOLUTE)

if ( UNIX )
SET (BOOST_STATIC_LIBRARIES ${BOOST_BUILD}/libboost_filesystem.a)
endif ()

ExternalProject_Add(
boost
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/boost
GIT_REPOSITORY ${BOOST_URL}
GIT_SUBMODULES libs/assert libs/utility libs/config libs/predef libs/system libs/detail libs/filesystem tools/boostdep tools/build tools/bcp tools/boostbook tools/inspect tools/litre tools/quickbook tools/auto_index
UPDATE_COMMAND ./bootstrap.sh --with-libraries=filesystem,system --includedir=${CMAKE_BINARY_DIR}/include/
CONFIGURE_COMMAND ./b2 headers
BUILD_COMMAND ./b2 link=static install
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/lib
BUILD_IN_SOURCE 1
INSTALL_COMMAND ""
)

set(BOOST_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/lib)
message ("${BOOST_STATIC_LIBRARIES}")

最佳答案

我如何解决我的问题:
使用下载具体的子模块

GIT_SUBMODULES option



使用在不同的目录中安装 boost 并且只安装静态版本

BUILD_COMMAND ./b2 link=static install --libdir=${CMAKE_BINARY_DIR}/lib



还有:使用以下方法安装了具体的二进制文件:

UPDATE_COMMAND ./bootstrap.sh --with-libraries=filesystem,system,regex,program_options --includedir=${CMAKE_BINARY_DIR}/include


cmake_minimum_required ( VERSION 2.8.7 )

# Download boost from git

include(ExternalProject)

if ( UNIX )

if (NOT Boost)

SET (Boost_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/include/boost/)
SET (Boost_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/lib )
SET (BOOST_URL https://github.com/boostorg/boost.git )
SET (BOOST_BUILD ${CMAKE_CURRENT_BINARY_DIR})
SET (FILESYSTEM_STATIC_LIBRARIES ${BOOST_BUILD}/lib/libboost_filesystem.a)
SET (SYSTEM_STATIC_LIBRARIES ${BOOST_BUILD}/lib/libboost_system.a)
SET (REGEX_STATIC_LIBRARIES ${BOOST_BUILD}/lib/libboost_regex.a)
SET (PROGRAM_OPTIONS_STATIC_LIBRARIES ${BOOST_BUILD}/lib/libboost_program_options.a)

ExternalProject_Add( Boost
PREFIX Boost
GIT_REPOSITORY ${BOOST_URL}
GIT_SUBMODULES libs/asio libs/date_time libs/config libs/core libs/detail libs/io libs/iterator libs/predef libs/preprocessor libs/smart_ptr libs/throw_exception libs/system libs/filesystem libs/integer tools/build tools/bcp libs/serialization libs/interprocess libs/tokenizer libs/algorithm libs/program_options libs/regex libs/static_assert libs/thread libs/utility libs/numeric libs/range libs/array libs/bind libs/concept_check libs/lexical_cast libs/math libs/functional libs/assert libs/type_traits libs/mpl libs/move libs/container libs/any libs/type_index libs/function

UPDATE_COMMAND ./bootstrap.sh --with-libraries=filesystem,system,regex,program_options --includedir=${CMAKE_BINARY_DIR}/include/
CONFIGURE_COMMAND ./b2 headers
BUILD_COMMAND ./b2 link=static install --libdir=${CMAKE_BINARY_DIR}/lib
BUILD_IN_SOURCE 1
INSTALL_COMMAND ""
)

ADD_LIBRARY (Boost_LIB STATIC IMPORTED DEPENDS Boost)
SET_TARGET_PROPERTIES (Boost_LIB PROPERTIES IMPORTED_LOCATION ${FILESYSTEM_STATIC_LIBRARIES})
SET_TARGET_PROPERTIES (Boost_LIB PROPERTIES IMPORTED_LOCATION ${SYSTEM_STATIC_LIBRARIES})
SET_TARGET_PROPERTIES (Boost_LIB PROPERTIES IMPORTED_LOCATION ${REGEX_STATIC_LIBRARIES})
SET_TARGET_PROPERTIES (Boost_LIB PROPERTIES IMPORTED_LOCATION ${PROGRAM_OPTIONS_STATIC_LIBRARIES})

endif()
endif()

关于boost - 如何使用 cmake 从 Boost 克隆特定子模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42835837/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com