[CMake] Building Boost as an ExternalProject

Michael Powell mwpowellhtx at gmail.com
Mon Oct 2 17:36:43 EDT 2017


On Mon, Oct 2, 2017 at 4:54 PM, paul <pfultz2 at yahoo.com> wrote:
> For building boost with cmake you can use this cmake script:
>
> https://github.com/pfultz2/cget/blob/master/cget/cmake/boost.cmake
>
> You can drop it in at the top of the boost tree and it will build Boost.Build
> and then build boost with b2. This will map the cmake toolchain to the boost
> toolchain so the builds are consistent.

That does seem to be the rub, at least on a Windows build. Something
about ExternalProject_Add ain't quite kosher with what the Boost build
system expects and it needs a little help.

Using ExternalProject_Add, it succeeds, to a point. Then it falls over
looking for b2 no matter how I try to persuade it:

ExternalProject_Add (boost
    PREFIX ${CMAKE_CURRENT_BINARY_DIR}/boost
    GIT_REPOSITORY git at github.com:boostorg/boost.git
    GIT_TAG boost-${BOOST_VERSION}
    GIT_PROGRESS 1
    UPDATE_COMMAND ${BOOST_BOOTSTRAP_CMD}
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ${BOOST_BUILD_CMD} stage
    INSTALL_COMMAND ""
    LOG_DOWNLOAD 1
    LOG_UPDATE 1
    LOG_CONFIGURE 1
    LOG_BUILD 1
    LOG_INSTALL 1
)

It seems to use PREFIX a bit over zealously IMO, and not
WORKING_DIRECTORY one iota. I did have one breakthrough; at least
bootstrap.bat is building b2.exe, so that's something.

With the update step being a straight 'bootstrap.bat' invocation, then:

'b2.exe' '--prefix=G:/Source/Spikes/nanomsg/cppnngswig-working/boostbuild'
'-std=c++11' '--with-test' 'address-model=64' 'toolset=msvc-14.0'
'variant=debug' 'link=static' 'stage'

I'm really at a loss how folks are succeeding with that, maybe on *nix
systems, that is a different story, I don't know, I'm not aware.

So with this, it is a key departure from EP_Add in that it "helps" the
build system along. That was going to be my next approach.

I still think EP_Add should work, but I'm not sure what it is missing.
Maybe a simple <path/to/b2>\b2 ?

> On Mon, 2017-10-02 at 14:34 -0400, Michael Powell wrote:
>> Hello,
>>
>> This question has been raised from time to time I think. I am trying
>> to build Boost as an ExternalProject, but I am ending up with an
>> error: 'cmd.exe' returned with exit code 1. Along these lines.
>>
>> Perhaps I have involved one too many variables, but I doubt it. Ignore
>> the cross-plat stuff, this is building on Windows for the purposes of
>> this conversation.
>>
>> I tried to configure ExternalProject_Add with as much verbosity as
>> possible, but unfortunately the process is not especially talkative as
>> it turns out. But for the EC 1.
>>
>> set (BOOST_VERSION  1.65.1)
>>
>> message (STATUS "Adding Boost ${BOOST_VERSION} as an external project.")
>>
>> set (BOOST_BOOTSTRAP_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/boostbuild)
>> set (BOOST_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/boostbuild)
>> set (BOOST_BUILD_PREFIX ${BOOST_BOOTSTRAP_PREFIX}/boost)
>> set (BOOST_GIT_REPO_DIR ${CMAKE_CURRENT_SOURCE_DIR}/repos/boost)
>>
>> if (WIN32)
>>     set (BOOST_BOOTSTRAP_CMD ${BOOST_GIT_REPO_DIR}/bootstrap.bat)
>>     # It was bjam at one point; it is now b2
>>     set (BOOST_BUILD_CMD ${BOOST_GIT_REPO_DIR}/b2.exe)
>> elseif (UNIX)
>>     set (BOOST_BOOTSTRAP_CMD ./${BOOST_GIT_REPO_DIR}/bootstrap.sh)
>>     set (BOOST_BUILD_CMD ./${BOOST_GIT_REPO_DIR}/b2)
>> endif ()
>>
>> #  TODO: TBD: For now, assuming only 64-bit address models.
>> set (BOOST_ADDR_MODEL 64)
>>
>> # TODO: TBD: align with the toolchain that we want to build through
>> the CMake here... For now assuming:
>> if (MSVC_VERSION EQUAL 1900)
>>     set (BOOST_TOOLSET msvc-14.0)
>> endif ()
>>
>> ExternalProject_Add (boost
>>     # PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/repos/boost
>>     GIT_REPOSITORY git at github.com:boostorg/boost.git
>>     GIT_TAG boost-${BOOST_VERSION}
>>     GIT_PROGRESS ON
>>     CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:STRING=${BOOST_INSTALL_PREFIX}
>>     SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/repos/boost
>>     CONFIGURE_COMMAND ${BOOST_BOOTSTRAP_CMD} --
>> prefix=${BOOST_BOOTSTRAP_PREFIX}
>>     # I do not necessarily care about any other Boost build options;
>> but that could change the further I get into unit testing, at least so
>> long as I will be adopting the test library for usage.
>>     BUILD_COMMAND ${BOOST_BUILD_CMD} --with-test
>> toolset=${BOOST_TOOLSET} variant=debug link=static stage
>> --prefix=${BOOST_BUILD_PREFIX}
>>     LOG_DOWNLOAD ON
>>     LOG_UPDATE ON
>>     LOG_CONFIGURE ON
>>     LOG_BUILD ON
>>     LOG_INSTALL ON
>> )
>>
>> Cheers,
>>
>> Michael Powell
>
> .


More information about the CMake mailing list