Building boost and changing output dir/filename - c++

I'm trying to build boost via Boost.Build from the cmd line - https://boostorg.github.io/build/manual/develop/index.html#bbv2.overview.invocation
I want to have boost output my files at a certain folder and depending on address model + variant (debug/release 32/64) have a different name.
I tried something like this:
b2 --libdir=C:\ serialization filesystem system toolset=msvc-12.0 variant=debug,release threading=multi link=static runtime-link=static address-model=64,32 architecture=x86
It just builds to the default output path... and there seems to be no option to rename output files.
Also tried "--build-dir" with no success.
Any ideas?

Related

Installing Boost to custom directory

I have tried following the tutorial Boost gives on their documentation for installing boost and have looked at a few other questions here to try to determine why I can't install Boost at a custom location. Perhaps I'm misunderstanding, but the --prefix option is supposed to specify where the Boost headers and libs will go, then bootstrapper.sh creates a .jam file that is used when b2 or bjam is run.
When I issue the following command
./bootstrap.sh --prefix="$HOME/dev/emulator/src/boost" --includedir=headers --libdir=dist --with-libraries=date_time
I see that the correct lines are added to the generated project-config.jam file
option.set prefix : /home/liam/dev/emulator/src/boost ;
option.set exec-prefix : /home/liam/dev/emulator/src/boost ;
option.set libdir : dist ;
option.set includedir : headers ;
However, when I run ./b2 as instructed by the documentation, it installs the Boost libraries to the source folder; i.e.
The following directory should be added to compiler include paths:
/home/liam/Downloads/brave/boost_1_66_0
The following directory should be added to linker library paths:
/home/liam/Downloads/brave/boost_1_66_0/stage/lib
And running ./b2 install gives me no file output to the intended directory either.
You need to use your directory in both steps:
DST_DIR=${HOME}/dev/emulator/src/boost
./bootstrap.sh --prefix=${DST_DIR} --includedir=headers --libdir=dist --with-libraries=date_time
./b2 --prefix=${DST_DIR} install
Try
./bootstrap.sh --prefix=path/to/installation/prefix
./b2 install
So that means first bootstrap b2 and then use it to build and install boost.

CMake - how to build Boost after downloading it with FetchContent?

My goal is to download the Boost repository if it isn't found and then build it the default way, i.e. using boostrap and b2 tools.
I know, I can download it like this:
include(FetchContent)
FetchContent_Declare(
Boost
PREFIX external_dependencies/boost
GIT_REPOSITORY https://github.com/boostorg/boost.git
GIT_SUBMODULES libs/system libs/serialization libs/random
libs/function libs/config libs/headers libs/assert libs/core libs/integer
libs/type_traits libs/mpl libs/throw_exception libs/preprocessor libs/utility
libs/static_assert libs/smart_ptr libs/predef libs/move libs/io libs/iterator
libs/detail libs/spirit libs/optional libs/type_index libs/container_hash
libs/array libs/bind
tools/build tools/boost_install
)
FetchContent_GetProperties(Boost)
FetchContent_Populate(Boost)
But how can I build it now correctly? I'd like to run following commands:
./bootstrap.sh
./b2 headers
./b2 -q cxxflags="-fPIC" --layout=system variant=${BUILD_TYPE} link=${LINK_TYPE} address-model=64 --with-system --with-serialization --with-random
I'm thinking about add_custom_target() and add_custom_command() functions, but I'm not sure, if it's the recommended way to do this.
add_custom_target is probably better because it is declaring a target that is convenient to depend on,
using add_dependencies.
You may need one target per command, and that becomes quickly annoying. So instead I would try (I did not) writing a script performing the build, let's call it build-boost.sh:
#!/bin/bash
# This is meant to be run from the source directory of Boost.
./bootstrap.sh
./b2 headers
./b2 -q cxxflags="-fPIC" --layout=system variant=$2 link=$3 address-model=64 --with-system --with-serialization --with-random
./b2 install --prefix=$4
In your CMake code, you would be calling it this way:
add_custom_target(
build-boost
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build-boost.sh ${BUILD_TYPE} ${LINK_TYPE} ${CMAKE_CURRENT_BINARY_DIR}/external_dependencies/boost-installation
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/external_dependencies/boost
)
After that, you are not done yet.
You should still export all the variables FindBoost usually exports, and create all expected directories in advance (under ${CMAKE_CURRENT_BINARY_DIR}/external_dependencies/boost-installation), since at configuration time the binaries and headers are not present yet.
If you complete this work, please let the community know, since this can be helpful.

Boost.Regex with icu/unicode support

How to build Boost.Regex with icu/ unicode support? My compiler is GCC, and IDE is Eclipse C++. How to configure binary files with Eclipse?
I tried to do this "bjam --sHAVE_ICU=1 toolset=gcc". But it did not work.
When i check if icu support is enable with "bjam -has_icu", i still get "has icu builds : no".
I build Boost against ICU using -sICU_PATH=<icuRoot> and -sICU_LINK="-L<icuLibDir>".
I've seen Boost fail to properly detect ICU as well, and have needed to patch the file has_icu_test.cpp (simply return 0 from it's main() function). This will work if you know everything else is set up properly.
Solved the problem by adding directly include path of include ICU directory to cflags when executing b2. For instance:
./b2 --with-regex
cflags="-O0 -I\"$ICU_PATH/include\"
You also may need to add path of ICU lib and moreover full paths to libs to linker. Something like this:
export ICU_LINK="-L\"$ICU_PATH/lib\" -l\"$ICU_PATH/lib/libicudata.a\" -l\"$ICU_PATH/lib/libicui18n.a\" -l\"$ICU_PATH/lib/libicuuc.a\""
./b2 --with-regex
cflags="-O0 -I\"$ICU_PATH/include\"
-sICU_LINK=$ICU_LINK \
Behemoths and Juggernauts
On some unix, this worked for me:
./b2 link=static,shared -sICU_PATH=/usr/local install
In said system, ICU headers are installed in /usr/local/include and ICU libraries in /usr/local/lib
In order to test if you have ICU headers installed (say in /usr/local/include) see if the dir /usr/local/include/unicode/ exists and has lots of header files in it (e.g. symtable.h)
Note that when I followed general advice from then net and passed -sICU_LINK='-L/usr/local/lib' to boost's b2, ICU detection (version 1.62 and 1.63) failed.
In the previous answer, user "NuSkooler" mentions that patching boost file has_icu_test.cpp to simply return 0; short-circuits the test and boost believes all is genkhi with ICU and goes ahead with it.
However make sure you also delete all ICU-related function calls and header files from that file because it is usually the case that has_icu_test.cpp first fails to compile or link because ICU libraries or header files can not be found by boost internals.
With all these, I can confirm that Aegisub's configure now passes the ICU test for me.
(and all these because John Hurt sadly died and I tried to put subtitles in a clip of Heaven's Gate to give to a friend)
b.

Building a subset of boost libraries

I'm trying to build only a subset of boost libraries. For example, I have this code:
test.cpp:
#include <boost/thread.hpp>
int main (){
return 0;
}
I then do
./bcp --scan test.cpp ~/dev/boost_compact/
So the dependencies files are copied to ~/dev/boost_compact/boost.
Then, following this answer, I copy all files at the root of a regular boost and also the tools directory and run
./bootstrap
./bjam
./bjam install
This does copy all the headers to a destination directory, but it does not build/copy the libraries. This same set of actions does work in the full boost. What am I doing wrong?
Solved the problem. The reason the libraries were not being copied was that I was using the wrong boost directory, that is
./bcp --scan --boost=<path to boost build directory> test.cpp ~/dev/boost_compact/
when I should be using
./bcp --scan --boost=<path to boost source directory> test.cpp ~/dev/boost_compact/
If now you run
./bootstrap
./bjam
./bjam install
The libraries will be build.
Maybe a permission issue?
or
Perhaps try explicitly setting the libdir?
bjam --libdir=path/to/lib install

Building boost under msys, can't find mingw.jam

I need to build boost to use the regex library. I was able to creat bjam using bootstrap.sh like so:
./bootstrap.sh --with-toolset=mingw
Note - if I leave out the --with-toolset=mingw argument compilation fails - bootstrap can't find wait.h, resource.h, ar.h. With the mingw toolset argument, bjam is able to compile. Then I run bjam and get:
./bjam.exe
mingw.jam: No such file or directory
e:/libraries/boost_1_45_0/tools/build/v2/build\toolset.jam:38: in toolset.using
rule mingw.init unknown in module toolset.
e:/libraries/boost_1_45_0/tools/build/v2/build\project.jam:881: in using
project-config.jam:12: in modules.load
e:/libraries/boost_1_45_0/tools/build/v2\build-system.jam:257: in load-config
e:/libraries/boost_1_45_0/tools/build/v2\build-system.jam:423: in load-configuration-files
e:/libraries/boost_1_45_0/tools/build/v2\build-system.jam:554: in load
e:\libraries\boost_1_45_0\tools\build\v2/kernel\modules.jam:283: in import
e:\libraries\boost_1_45_0\tools\build\v2\kernel\bootstrap.jam:142: in boost-build
e:\libraries\boost_1_45_0\boost-build.jam:17: in module scope
I tried several variations of parameters and get the same error:
./bjam.exe --build-dir=e:/libraries/boost_1_45_0/ --toolset=mingw
./bjam.exe --build-dir=e:/libraries/boost_1_45_0/ --toolset=gcc
Not sure how to get bjam to build. Any suggestions?
Once you have built bjam with ./bootstrap.sh --with-toolset=mingw
Edit the file project-config.jam and replace 'mingw' by 'gcc'
Then launch bjam.exe and it should work