mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.51k stars 1.6k forks source link

Boost dependency doesn't add -DBOOST_HAS_THREADS appropriately #10371

Open fghzxm opened 2 years ago

fghzxm commented 2 years ago

Describe the bug When using the boost dependency (with threading : multi), -DBOOST_HAS_THREADS is not added automatically to the compiler arguments.

To Reproduce

# meson.build
project('example', 'cpp')
static_library('example', 'lib.cpp', dependencies : [dependency('boost')])
// lib.cpp
#include <boost/config/requires_threads.hpp>

Expected behavior Compilation succeeds.

Actual behavior

> ninja -C builddir
ninja: Entering directory `builddir'
[1/2] Compiling C++ object libexample.a.p/lib.cpp.obj
FAILED: libexample.a.p/lib.cpp.obj
"clang++" "-Ilibexample.a.p" "-I." "-I.." "-IC:/path/to/boost" "-fcolor-diagnostics" "-D_FILE_OFFSET_BITS=64" "-Wall" "-Winvalid-pch" "-Wnon-virtual-dtor" "-O0" "-g" "-DBOOST_ALL_NO_LIB" -MD -MQ libexample.a.p/lib.cpp.obj -MF "libexample.a.p\lib.cpp.obj.d" -o libexample.a.p/lib.cpp.obj "-c" ../lib.cpp
In file included from ../lib.cpp:1:
C:/path/to/boost\boost/config/requires_threads.hpp:82:4: error: "Compiler threading support is not turned on. Please set the correct command line options for threading: either /MT /MTd /MD or /MDd"
#  error "Compiler threading support is not turned on. Please set the correct command line options for threading: either /MT /MTd /MD or /MDd"
   ^
1 error generated.
ninja: build stopped: subcommand failed.

system parameters

mensinda commented 2 years ago

Could you please check if this change fixes your issue? I am unable to reproduce this with your test case since I am on Linux.

diff --git a/mesonbuild/dependencies/boost.py b/mesonbuild/dependencies/boost.py
index 544e844f2..5477a7467 100644
--- a/mesonbuild/dependencies/boost.py
+++ b/mesonbuild/dependencies/boost.py
@@ -1032,8 +1032,8 @@ boost_libraries = {
     ),
     'boost_thread': BoostLibrary(
         name='boost_thread',
-        shared=['-DBOOST_THREAD_BUILD_DLL=1', '-DBOOST_THREAD_USE_DLL=1'],
-        static=['-DBOOST_THREAD_BUILD_LIB=1', '-DBOOST_THREAD_USE_LIB=1'],
+        shared=['-DBOOST_THREAD_BUILD_DLL=1', '-DBOOST_THREAD_USE_DLL=1', '-DBOOST_HAS_THREADS'],
+        static=['-DBOOST_THREAD_BUILD_LIB=1', '-DBOOST_THREAD_USE_LIB=1', '-DBOOST_HAS_THREADS'],
         single=[],
         multi=[],
     ),

Also dependency('boost') should be dependency('boost', modules: ['thread']).