M
M
Mars362021-04-03 21:29:22
CMake
Mars36, 2021-04-03 21:29:22

How to install boost::program_options dependency along with your project using ExternalProject_Add in cmake?

You need to add this dependency to the project. When assembled, it gives

mistake

Серьезность	Код	Описание	Проект	Файл	Строка	Состояние подавления
Ошибка	MSB8066	пользовательская сборка для "F:\code\C++\tasks\build\CMakeFiles\a02e4265147eb1a3546f70796cde7b11\external_boost-build.rule;F:\code\C++\tasks\build\CMakeFiles\a02e4265147eb1a3546f70796cde7b11\external_boost-install.rule;F:\code\C++\tasks\build\CMakeFiles\0e4e7d5d50178db39cc1c505593c8a26\external_boost-complete.rule;F:\code\C++\tasks\build\CMakeFiles\2daa0d109a3f41d5cd6f5bdbb5817a2f\external_boost.rule" завершила работу с кодом 9009.	external_boost	F:\microsoft\visual_studio\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets	240


ExternalProject.cmake

include( ExternalProject )

set( boost_URL "http://sourceforge.net/projects/boost/files/boost/1.63.0/boost_1_63_0.zip" )
set( boost_SHA1 "4364989afbe6b11f2d5e59df902c3ca4d7851824" )
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.bat
            --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 .lib )

add_library( boost::program_options  STATIC IMPORTED )
set_property( TARGET boost::program_options PROPERTY IMPORTED_LOCATION ${boost_LIB_DIR}/libboost_program_options ${boost_LIBRARY_SUFFIX} )
set_property( TARGET boost::program_options PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${boost_INCLUDE_DIR} )
add_dependencies( boost::program_options  external_boost )


If you try to start installing the downloaded boost through the console manually, then the following errors will appear
F:\code\C++\tasks\build\boost\src\external_boost\tools\build\src\engine\jam.h(71): fatal error C1034: ctype.h: не указан путь поиска включаемых файлов
compile.c
F:\code\C++\tasks\build\boost\src\external_boost\tools\build\src\engine\jam.h(71): fatal error C1034: ctype.h: не указан путь поиска включаемых файлов
constants.c
debug.c
F:\code\C++\tasks\build\boost\src\external_boost\tools\build\src\engine\jam.h(71): fatal error C1034: ctype.h: не указан путь поиска включаемых файлов
execcmd.c

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
klirichek, 2021-05-04
@Mars36

And what for this mouse fuss with manual import?
I did something like this for boost::context


cmake_minimum_required(VERSION 2.8.2)
project(boost-context-download NONE)
include(ExternalProject)
ExternalProject_Add(boost-context
SOURCE_DIR "@[email protected]"
BUILD_IN_SOURCE ON
CONFIGURE_COMMAND bootstrap.bat
BUILD_COMMAND b2 --with-context
INSTALL_COMMAND b2 install --with -context --build-type=complete [email protected][email protected]
)

The parameters are slightly different than yours (in the configurator, the list or is optional. But when building, it is already necessary. And there is also a separate installation where they are also needed).
Even during assembly, it is desirable to remove (if any) the CXX environment variable, if it is suddenly defined in the project above (b2 has its own introspection, which is afraid of this).
Just further, after building external_project - and the usual find_package (Boost 1.61.0 COMPONENTS context) goes, which creates all the necessary imported targets. And the subsequent target_link_libraries(boost::context) uses them.
But in general, the approach itself is not very good. Under Windows, you can find ready-made boost assemblies. Download about the same amount, but you don’t need to mess with the installation at all. I unpacked the archive, set BOOST_ROOT into it, called find_package(boost...) - and voila!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question