[CMake] FindBoost with MSVC and LLVM Toolset

Иннокентий Алайцев alaitsev at gmail.com
Wed Jun 20 08:55:08 EDT 2018


Hello!

I got a problem while trying to use CMake 3.11.3 to configure a project
that uses Boost.Exception library and LLVM-vs2014 toolset with MSVS 2017
v15.7.4.

I configure the project using cmake-gui. I select the Visual Studio 15 2017
generator and set optional toolset option to LLVM-vs2014. I have LLVM 6.0
x64 installed.

CMakeLists.txt:
# Boost settings
if (WIN32)
  # According to documentation:
  #
  # On Visual Studio and Borland compilers Boost headers request
automatically
  # linking to corresponding libraries. This requires matching libraries to
be
  # linked explicitly or available in the link library search path. In this
case
  # setting Boost_USE_STATIC_LIBS to OFF may not achieve dynamic linking.
Boost
  # automatic linking typically requests static libraries with a few
exceptions
  # (such as Boost.Python).
  #
  # That's why for static libraries it is required to explicitly enable
static
  # libraries usage.
  set (Boost_USE_STATIC_LIBS ON)
endif (WIN32)

find_package (Boost 1.38.0 REQUIRED
  COMPONENTS
  exception)


Error message:

CMake Error at C:/Program
Files/CMake/share/cmake-3.11/Modules/FindBoost.cmake:2044 (message):
Unable to find the requested Boost libraries.

Boost version: 1.67.0

Boost include path: W:/boost/1.67.0

Could not find the following static Boost libraries:

boost_exception

No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the
directory containing Boost libraries or BOOST_ROOT to the location of
Boost.
Call Stack (most recent call first):
...

I performed a little investigation. It seems that FindBoost module the is
distributed with CMake does not support using an alternative toolset with
MSVS generator. The function _Boost_GUESS_COMPILER_PREFIX (line 451) checks
Intel, MSVC, Borland and MinGW compilers (and general UNIX case). The thing
is that CMAKE_CXX_COMPILER_ID for the LLVM-v140 toolset is Clang. As a
result, an empty Boost compiler prefix is returned by the function.

I managed to workaround the issue by adding the following check before the
other checks performed by the _Boost_GUESS_COMPILER_PREFIX function:

if("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xClang")
  if("${CMAKE_VS_PLATFORM_TOOLSET}" STREQUAL "LLVM-vs2010")
    set(_boost_COMPILER "-vc100")
  elseif("${CMAKE_VS_PLATFORM_TOOLSET}" STREQUAL "LLVM-vs2012")
    set(_boost_COMPILER "-vc110")
  elseif("${CMAKE_VS_PLATFORM_TOOLSET}" STREQUAL "LLVM-vs2013")
    set(_boost_COMPILER "-vc120")
  elseif("${CMAKE_VS_PLATFORM_TOOLSET}" STREQUAL "LLVM-vs2014")
    set(_boost_COMPILER "-vc141;-vc140")
  endif()
else

I am not sure that this is the right solution in general, but it has
resolved the issue that I had.

What is the correct solution for the problem.

Best regards,
Innokentiy Alaytsev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180620/97cdc283/attachment.html>


More information about the CMake mailing list