-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[LLVM][Cygwin] Define _GNU_SOURCE on Cygwin as well. #138329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@mstorsjo (It's already unsupported upstream, I personally only plan to try to support it until Windows 10 end-of-support, and Git-for-Windows needs to support some tiny subset until 2029 IIRC. I'm sure llvm isn't part of that since it hasn't been usable up to now). |
Yeah I don't have a very strong opinion either way. Theoretically, cygwin could start using it, but it's of course unlikely. Then again, it doesn't hurt keeping it like this either. But perhaps we could split the if and just do the |
so if (CYGWIN)
add_compile_definitions(_GNU_SOURCE)
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
endif () right above, to go with the |
Nah, I'd split the current |
Without it, certain functions such as dladdr are not make available by the headers. Signed-off-by: Jeremy Drake <github@jdrake.com>
31e9552
to
3fc3075
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Without it, certain functions such as dladdr are not make available by the headers. Signed-off-by: Jeremy Drake <github@jdrake.com>
cygwin's packaging builds clang standalone, and in that configuration it seems that |
Hmm. I don't really have any experience with building clang standalone in that way; does the clang source tree have any form of local corresponding code that sets |
just llvm-project/clang/CMakeLists.txt Lines 183 to 198 in 944e60f
Yep, I'm trying to build and integrate the patches I've been contributing here into Cygwin's package in addition to MSYS2's. Actually:
This is odd, the other |
Ok, I see. I guess if it strictly is necessary, then the (In case you're building in an existing build tree, things like this might not be picked up due to CMakeCache.txt.) |
also, Perhaps it needs to explicitly add |
https://llvm.org/docs/CMake.html#developing-llvm-passes-out-of-source says use find_package(LLVM REQUIRED CONFIG)
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS_LIST})
include_directories(${LLVM_INCLUDE_DIRS}) clang/CMakeLists.txt has find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
...
include_directories(${LLVM_INCLUDE_DIRS})
link_directories("${LLVM_LIBRARY_DIR}") So I'm thinking the separate_arguments and add_definitions should be plugged in there? |
this seems to work --- 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:
|
In llvm#138329, _GNU_SOURCE was added for Cygwin, but when building Clang standalone against an installed LLVM this definition was not picked up, resulting in undefined strnlen. Follow the documentation in https://llvm.org/docs/CMake.html#developing-llvm-passes-out-of-source and add the LLVM_DEFINITIONS in Clang's CMakeLists.txt. Get rid of the list(REMOVE CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) later, as list(REMOVE) is documented to remove *all* occurences of the item, not just the one that was just added. Instead, make use of cmake_push_check_state() and cmake_pop_check_state(), which is already used in other cmake files.
Without it, certain functions such as dladdr are not make available by the headers. Signed-off-by: Jeremy Drake <github@jdrake.com>
In llvm#138329, _GNU_SOURCE was added for Cygwin, but when building Clang standalone against an installed LLVM this definition was not picked up, resulting in undefined strnlen. Follow the documentation in https://llvm.org/docs/CMake.html#developing-llvm-passes-out-of-source and add the LLVM_DEFINITIONS in Clang's CMakeLists.txt. Get rid of the list(REMOVE CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) later, as list(REMOVE) is documented to remove *all* occurences of the item, not just the one that was just added. Instead, make use of cmake_push_check_state() and cmake_pop_check_state(), which is already used in other cmake files.
Without it, certain functions such as dladdr are not make available by the headers. Signed-off-by: Jeremy Drake <github@jdrake.com>
Without it, certain functions such as dladdr are not make available by the headers. Signed-off-by: Jeremy Drake <github@jdrake.com>
Without it, certain functions such as dladdr are not make available by the headers. Signed-off-by: Jeremy Drake <github@jdrake.com>
Without it, certain functions such as dladdr are not make available by the headers. Signed-off-by: Jeremy Drake <github@jdrake.com>
In llvm#138329, _GNU_SOURCE was added for Cygwin, but when building Clang standalone against an installed LLVM this definition was not picked up, resulting in undefined strnlen. Follow the documentation in https://llvm.org/docs/CMake.html#developing-llvm-passes-out-of-source and add the LLVM_DEFINITIONS in standalone projects' cmakes.
Without it, certain functions such as dladdr are not make available by the headers. Signed-off-by: Jeremy Drake <github@jdrake.com>
In llvm#138329, _GNU_SOURCE was added for Cygwin, but when building Clang standalone against an installed LLVM this definition was not picked up, resulting in undefined strnlen. Follow the documentation in https://llvm.org/docs/CMake.html#developing-llvm-passes-out-of-source and add the LLVM_DEFINITIONS in standalone projects' cmakes.
In llvm#138329, _GNU_SOURCE was added for Cygwin, but when building Clang standalone against an installed LLVM this definition was not picked up, resulting in undefined strnlen. Follow the documentation in https://llvm.org/docs/CMake.html#developing-llvm-passes-out-of-source and add the LLVM_DEFINITIONS in standalone projects' cmakes.
Without it, certain functions such as dladdr are not make available by the headers. Signed-off-by: Jeremy Drake <github@jdrake.com>
In llvm#138329, _GNU_SOURCE was added for Cygwin, but when building Clang standalone against an installed LLVM this definition was not picked up, resulting in undefined strnlen. Follow the documentation in https://llvm.org/docs/CMake.html#developing-llvm-passes-out-of-source and add the LLVM_DEFINITIONS in standalone projects' cmakes.
Without it, certain functions such as dladdr are not make available by the headers.