FindBoost ignores all hints and won't find the right installation

I’m trying to get some software built on CentOS 7 with modules. The boost module is loaded and BOOST_DIR is set as an environment variable to the appropriate path.

I’m trying to get FindBoost to pick up the module installation rather than the (older) system installation.

I have:

message( STATUS "BOOST_DIR: $ENV{BOOST_DIR}" )
if( NOT $ENV{BOOST_DIR} STREQUAL "" )
  message( STATUS "searching for boost in environment path: $ENV{BOOST_DIR}" )
  set( BOOST_ROOT $ENV{BOOST_DIR} )
  set( ENV{BOOST_ROOT} $ENV{BOOST_DIR} )
endif()
if( DEFINED BOOST_ROOT )
  message( STATUS "Setting boost installation location as: " ${BOOST_ROOT} )
  set( Boost_NO_SYSTEM_PATHS ON )  # only look in the user-specified location - nowhere else!
endif()

set( BOOST_MIN_VERSION "1.54.0" )
find_package( Boost ${BOOST_MIN_VERSION} MODULE REQUIRED COMPONENTS ${boost_comps} )

The message statements all output as expected, but then boost is not found. I’ve tried this with and without the MODULE keyword and it doesn’t make a difference.

Version information:

  • cmake version: 3.18.2
  • Boost version: 1.69.0

Is there some trick to make FindBoost.cmake actually respect the hints I’m passing it?

Things I’ve tried:

  • Invoke cmake with -DBOOST_LIBRARYDIR=$BOOST_DIR/lib -DBOOST_INCLUDEDIR=$BOOST_DIR/include
  • Invoke cmake with -DBOOST_ROOT=$BOOST_DIR

Note that I’m also setting Boost_NO_SYSTEM_PATHS=ON, but boost still reports that it found an “unsuitable” system install in /usr that wasn’t compatible with my specified minimum version.

So it seems that FindBoost is ignoring everything I’m telling it about where to look.

Thanks for any tips!

Does cmake --debug-find help out? There’s also the Boost_DEBUG variable you can use for FindBoost specifically.

Observations when using Boost_DEBUG:

  1. BOOST_ROOT is picked up correctly within FindBoost:
    BOOST_ROOT = "/uufs/chpc.utah.edu/sys/installdir/boost/1.69.0i19-impi"
    This is the location where boost is installed (the only subdirs there are include and lib).
  2. FindBoost apparently ignores the fact that I’m setting Boost_NO_SYSTEM_PATHS. For example:
    • _boost_LIBRARY_SEARCH_DIRS_RELEASE = "/usr/lib64;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH"
    • location of version.hpp: /usr/include/boost/version.hpp
      I’m specifically trying to avoid the installation in /usr and find the one loaded by the module in the /uufs path.

This seemingly confirms my suspicion that FindBoost is ignoring all of the path information I’m trying to provide it.

Observations when running with the --debug-find flag:

  1. I was able to confirm that no Config module was found (although it indicated that it looked in a large number of places for it, including system libraries). This is despite the fact that I had the MODULE keyword in the call to find_package (see original post).
  2. The variable CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH contains the desired boost path, but also others including system level ones in /usr. My guess is that this is expected.

Any other tips?

Yes, the hard-coded /usr/lib64 would be problematic. Is it fine if you remove that path (wherever it comes from)?

Hmm - after all of this churn, wiping out my whole build directory and starting over made it work. So something must have been cached that broke things.

Sorry for the wild goose chase :grimacing:

I probably have a different problem, but I’m trying to build the same project with boost 1.69 on both Debian 9 and CentOS 7, and FindBoost works without any environment variables on Debian 9 but not CentOS 7.

I’ve noticed that on Debian 9, the headers/libs are installed in:
/usr/include/boost

and on CentOS 7, these are in:

/usr/include/boost169/

I’m wondering if this differently named subdirectory is causing CMake to fail. It’s not obvious to me how to patch the module to get it to find this subdirectory.

I guess globbing for /usr/include/boost* may be necessary? Though I suspect that version-specific searching would get more complicated at that point.

FYI, I found an issue with what I was originally doing here.
Replace:

if( NOT $ENV{BOOST_DIR} STREQUAL "" )

with:

if( DEFINED ENV{BOOST_DIR} )

This seems to work as intended, while the first approach did not.