Skip to content

Commit d45b964

Browse files
Martin Poschtzlaine
authored andcommitted
fix boost build b2.exe for non-msvc compilers in win32.
propagate the selected compiler from cmake down to the boost bootstrap process
1 parent 2a9687f commit d45b964

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

cmake/dependencies.cmake

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
3032
else()
3133
set(b2_exe b2)
@@ -39,8 +41,29 @@ add_custom_target(boost_clone_deps
3941
VERBATIM)
4042
add_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 ()
4467
else()
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

Comments
 (0)