Boost logo

Boost-Build :

Subject: [Boost-build] [boost-build] how to link against library conditional on compiler version?
From: Steve Lorimer (steve.lorimer_at_[hidden])
Date: 2016-08-04 11:11:51


I have a vendor supplied library which we need to link against.

gcc-5 is not ABI compatible with gcc-4 and below, so I have two versions of
the vendor library, one for gcc-5 builds, and one for gcc-4 builds.

I need to check which compiler I'm building with, and select the correct
variant.

In CMake, I can check CMAKE_CXX_COMPILER_VERSION and set a variable:

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)
        set(API_LOC "gcc-4")
    else()
        set(API_LOC "gcc-5")
    endif()
endif()

add_library (foo_api STATIC IMPORTED GLOBAL)
set_target_properties(foo_api PROPERTIES IMPORTED_LOCATION
"${CMAKE_CURRENT_LIST_DIR}/${API_LOC}/foo.a")

Now, other components just need to add foo_api as a dependency, and they'll
automatically get the correct version.

I know how to create a similar library in boost.build

lib foo_api : : <name>foo <file>foo.a ;

I don't, however, know how to conditionally specify the <file> argument
dependent on compiler version.

How can I check the compiler version and select the correct library?



Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk