cmakeboostpatch

CMake - conditional statements on Boost version


The C++ Boost 1.74 that ships with Ubuntu 22.04 has code that is incompatible with C++20. There is an alternate file available that I need to copy prior to stating the build. The following is a snippet from the CMakeLists.txt file.

If I comment out the "if($Boost_VERSION..." and leave the file it works fine, but is not future proof.

My question is how to do the comparison for the boost version.

set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_DEBUG TRUE)
set(Boost_NO_BOOST_CMAKE OFF)
find_package(Boost 1.74.0 REQUIRED COMPONENTS program_options locale)

include(wtOptions.txt)
# Patch the boost include library for a C++2z error.
#if(${Boost_VERSION_MINOR} > 75)
  file(COPY ${CMAKE_SOURCE_DIR}/files/storage.hpp DESTINATION /usr/include/boost/numeric/ublas)
#endif()

` The error I get is

CMake Error at CMakeLists.txt:35 (if):
  if given arguments:

    "74" ">" "75"

  Unknown arguments specified

The idea is to patch automatically if the boost version is 1.74. I do not want to have to use a more recent version of boost and need to stick with the base installed version.


Solution

  • I believe that you need to do the conditional like this:

    if(${Boost_VERSION_MINOR} GREATER 75)
      # ...
    endif()
    

    Use GREATER rather than > for numerical comparisons.