[llvm] [LLVM][Cygwin] Define _GNU_SOURCE on Cygwin as well. (PR #138329)
via llvm-commits
llvm-commits at lists.llvm.org
Mon May 5 14:03:10 PDT 2025
jeremyd2019 wrote:
this seems to work
```cmake
--- clang-20.1.4-1.x86_64/origsrc/clang-20.1.4.src/CMakeLists.txt 2025-04-29 16:05:17.000000000 -0700
+++ clang-20.1.4-1.x86_64/src/clang-20.1.4.src/CMakeLists.txt 2025-05-05 13:58:28.443602600 -0700
@@ -68,6 +68,10 @@
option(CLANG_ENABLE_BOOTSTRAP "Generate the clang bootstrap target" OFF)
option(LLVM_ENABLE_LIBXML2 "Use libxml2 if available." ON)
+ separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
+ add_definitions(${LLVM_DEFINITIONS_LIST})
+ list(APPEND CMAKE_REQUIRED_DEFINITIONS ${LLVM_DEFINITIONS_LIST})
+
include(AddLLVM)
include(TableGen)
include(HandleLLVMOptions)
@@ -181,20 +185,19 @@
check_include_file(sys/resource.h CLANG_HAVE_RLIMITS)
# This check requires _GNU_SOURCE on linux
+include(CMakePushCheckState)
check_include_file(dlfcn.h CLANG_HAVE_DLFCN_H)
if( CLANG_HAVE_DLFCN_H )
include(CheckLibraryExists)
include(CheckSymbolExists)
check_library_exists(dl dlopen "" HAVE_LIBDL)
+ cmake_push_check_state()
if( HAVE_LIBDL )
list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
endif()
- list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
+ #list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
check_symbol_exists(dladdr dlfcn.h CLANG_HAVE_DLADDR)
- list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
- if( HAVE_LIBDL )
- list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl)
- endif()
+ cmake_pop_check_state()
endif()
set(CLANG_RESOURCE_DIR "" CACHE STRING
```
Issues I ran into:
* the `list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)` wipes out *all* occurences in the list, not just the one it just added. Better to push/pop (used in other llvm cmake files).
* HandleLLVMOptions.cmake nukes the `LLVM_DEFINITIONS` variable, so I had to add them *before* including that.
https://github.com/llvm/llvm-project/pull/138329
More information about the llvm-commits
mailing list