0

I am trying to build gnucash on ubuntu with some updated boost libs. I am using cmake-3.21.1 but have also tried with 3.16.3.

I want to link/include against boost 1.75. In order to do that i built boost as (all the gory details):

- sudo mkdir -p /opt/software/boost/boost_1_75
- sudo chmod -R 755 /opt/software
- cd /opt/software/boost/boost_1_75
- wget -O boost_1_75_0.tar.gz https://sourceforge.net/projects/boost/files/boost/1.75.0/boost_1_75_0.tar.gz/download
- tar -xzvf boost_1_75_0.tar.gz
- cd boost_1_75
- ./bootstrap.sh --prefix=/opt/software
- ./b2
- ./b2 install

which will give me (as expected) directories

- /opt/software/include/boost
- /opt/software/lib/libboost*

So far, so good.

Now i try to configure gnucash as follows (extracted gnucash code resides in $SRCROOT/gnucash):

- cd $SRCROOT
- mkdir gnucash-build
- cd gnucash-build
- export BOOST_ROOT=/opt/software; export CC=/usr/bin/clang; export CXX=/usr/bin/clang++; /opt/software/cmake/cmake-3.21.1/bin/cmake -DBOOST_ROOT=$BOOST_ROOT $SRCROOT/gnucash-build

The relevant section in the CMakeLists.txt is

if (NOT DEFINED ${BOOST_ROOT})
  set(BOOST_ROOT $ENV{BOOST_ROOT})
  find_package (Boost COMPONENTS date_time regex locale filesystem system program_options)
  message(STATUS "1.1: ${BOOST_ROOT}")
else()
  find_package (Boost 1.67.0 COMPONENTS date_time regex locale filesystem system program_options)
  message(STATUS "1.2: ${BOOST_ROOT}")
endif()
message(STATUS "2: Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")

Running

export BOOST_ROOT=/opt/software; export CC=/usr/bin/clang; export CXX=/usr/bin/clang++; /opt/software/cmake/cmake-3.21.1/bin/cmake -DBOOST_ROOT=$BOOST_ROOT $SRCROOT/gnucash-build

gives me:

1.1: /opt/software
2: Boost_INCLUDE_DIRS: /usr/include

so i know it enters the correct case.

However, Boost_INCLUDE_DIRS should be /opt/software/include/boost and not '/usr/include'

I also tried without (default) and with (which i added):

cmake_policy(SET CMP0074 NEW)

Neither appears to work.

I am not sure on how to about debugging this issue. Likely i am doing something wrong here. Any pointers are greatly appreciated.

EDIT 1

Doing find_package (Boost 1.75.0 COMPONENTS date_time regex locale filesystem system program_options) instead of find_package (Boost COMPONENTS date_time regex locale filesystem system program_options) will actually do what i want. However, i would have expected that, without specifying the exact version, by specifying BOOST_ROOT, the cmake compiler will first look into the specified directory and take whatever version it finds there and use it.

From the docs (https://cmake.org/cmake/help/latest/module/FindBoost.html):

BOOST_ROOT, BOOSTROOT
    Preferred installation prefix.
matze999
  • 431
  • 1
  • 5
  • 18
  • 1
    With CMP0074, the name of the variable needs to match the name used in the `find_package` call. In this case it should thus be `Boost_ROOT` instead of `BOOST_ROOT`. – Corristo Aug 11 '21 at 08:23
  • @Corristo Doing: 'export BOOST_ROOT=/opt/software; export Boost_ROOT=$BOOST_ROOT; export CC=/usr/bin/clang; export CXX=/usr/bin/clang++; /opt/software/cmake/cmake-3.21.1/bin/cmake -DBOOST_ROOT=$BOOST_ROOT -DBoost_ROOT=$BOOST_ROOT $SRCROOT/gnucash-build' does not work either. – matze999 Aug 11 '21 at 08:49
  • The output you showed suggests that ended up in the `if (NOT DEFINED ${BOOST_ROOT})` case, which is weird given that you specified it on the command line. Have you tried explicitly setting `-DBOOST_ROOT=/opt/software` instead of using the env variable? – Corristo Aug 11 '21 at 09:34
  • Neither: 'export CC=/usr/bin/clang; export CXX=/usr/bin/clang++; /opt/software/cmake/cmake-3.21.1/bin/cmake -DBoost_ROOT=/opt/software $SRCROOT/gnucash-build' nor 'export CC=/usr/bin/clang; export CXX=/usr/bin/clang++; /opt/software/cmake/cmake-3.21.1/bin/cmake -DBOOST_ROOT=/opt/software $SRCROOT/gnucash-build' works. Is there any way to print out debugging messages within find_packages? – matze999 Aug 11 '21 at 09:48
  • Yes, you can use `cmake --debug-find` – Corristo Aug 11 '21 at 09:51
  • `if (NOT DEFINED ${BOOST_ROOT})` is bogus since it expands `BOOST_ROOT` and then tests if that value names a variable. – Alex Reinking Aug 11 '21 at 13:27
  • @AlexReinking Not quite. To my understanding it is testing the environment variable ${BOOST_ROOT} and then setting internal variable BOOST_ROOT to its value. – matze999 Aug 11 '21 at 13:46
  • 1
    @matze999 - You are wrong. **That code is not testing whether the variable `BOOST_ROOT` is defined.** To test whether an environment variable is defined, one would write `if (DEFINED ENV{VAR})`. Here's an interaction that proves my point: https://hastebin.com/ujucijitiq.txt – Alex Reinking Aug 11 '21 at 13:52
  • @AlexReinking You are correct. I was wrong. However, I still do not understand why, if BOOST_ROOT is defined, i need to specify the boost version explicitly for cmake to pick up the version i pointed to with BOOST_ROOT (see 'EDIT 1') above. – matze999 Aug 12 '21 at 08:58
  • Probably unrelated, but still relevant: To use Boost 1.75 you need CMake 3.19.5 or newer, see https://stackoverflow.com/a/42124857/2799037 – usr1234567 Aug 12 '21 at 09:12
  • @usr1234567 Using cmake-3.21.1 – matze999 Aug 18 '21 at 08:36

0 Answers0