我知道如何使用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}")
答案 0 :(得分:1)
我是如何解决我的问题的: 使用
下载细节子模块GIT_SUBMODULES选项
使用并在仅安装静态版本
的情况下将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()