Skip to content

Commit f70b229

Browse files
authored
[LLDB] Define _BSD_SOURCE globally, to get optreset available in mingw's getopt.h (llvm#76137)
We previously were defining _BSD_SOURCE right before including getopt.h. However, on mingw-w64, getopt.h is also transitively included by unistd.h, and unistd.h can be transitively included by many headers (recently, by some libc++ headers). Therefore, to be safe, we need to define _BSD_SOURCE before including any header. Thus do this in CMake. This fixes llvm#76050.
1 parent e64f5d6 commit f70b229

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lldb/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ endif()
4444

4545
if (WIN32)
4646
add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
47+
if (NOT MSVC)
48+
# _BSD_SOURCE is required for MinGW's getopt.h to define optreset
49+
add_definitions(-D_BSD_SOURCE)
50+
endif()
4751
endif()
4852

4953
if (LLDB_ENABLE_PYTHON)

lldb/include/lldb/Host/HostGetOpt.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111

1212
#if !defined(_MSC_VER) && !defined(__NetBSD__)
1313

14-
#ifdef _WIN32
15-
#define _BSD_SOURCE // Required so that getopt.h defines optreset
16-
#endif
17-
1814
#include <getopt.h>
1915
#include <unistd.h>
2016

0 commit comments

Comments
 (0)