@@ -25,7 +25,9 @@ add_custom_command(
2525 https://github.com/boostorg/boost.git boost_root
2626 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} )
2727
28- if (MSVC )
28+ # MSVC determines the compiler and not the target platform
29+ # here we need to check WIN32
30+ if (WIN32 )
2931 set (b2_exe b2.exe)
3032else ()
3133 set (b2_exe b2)
@@ -39,8 +41,29 @@ add_custom_target(boost_clone_deps
3941 VERBATIM )
4042add_dependencies (boost_clone_deps boost_clone_superproject)
4143
42- if (MSVC )
43- set (bootstrap_cmd ./bootstrap.bat)
44+
45+ if (WIN32 )
46+ # Windows:
47+ # in order to build 'b2_exe' with the same toolset as configured in the current cmake run,
48+ # we need to tell the boost bootstrap process and pass some parameters
49+ # - as first parameter msvc, gcc or clang for the compiler type
50+ # - additionally, for non-MSVC we need to set the environment variable CXX to the compiler: ${CMAKE_CXX_COMPILER} which
51+ # is a fully qualified path name, so that the compiler can be found by the bootstrap_cmd
52+ # calling b2.exe should work also for non-MSVC compilers, as during the build, the runtime directory is part of the search PATH
53+
54+ if (MSVC OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC" )
55+ message (STATUS "configure BOOST for Visual Studio built-in compilers (i.e cl, clang-cl and clang" )
56+ set (bootstrap_cmd ./bootstrap.bat msvc )
57+ # here we do not need to distinguish the different compilers as only the frontend is different
58+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
59+ message (STATUS "configure BOOST for Clang compiler" )
60+ set (bootstrap_cmd ./bootstrap.bat clang)
61+ set (COMMAND_ENV set CXX=${CMAKE_CXX_COMPILER} )
62+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
63+ message (STATUS "configure BOOST for GCC compiler" )
64+ set (bootstrap_cmd ./bootstrap.bat gcc)
65+ set (COMMAND_ENV set CXX=${CMAKE_CXX_COMPILER} )
66+ endif ()
4467else ()
4568 # windres produces relocations that are rejected
4669 # by stricter ld configurations used in some distros
@@ -57,6 +80,7 @@ add_custom_command(
5780 COMMAND git submodule init libs/headers
5881 COMMAND git submodule init tools/boost_install
5982 COMMAND git submodule update --jobs 3 --depth 100
83+ COMMAND ${COMMAND_ENV}
6084 COMMAND ${bootstrap_cmd}
6185 COMMAND ./b2 headers
6286 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} /boost_root)
0 commit comments