Skip to content

Commit c633e9c

Browse files
committed
[Clang][CMake] respect LLVMConfig.cmake's LLVM_DEFINITIONS
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.
1 parent 17a0639 commit c633e9c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

clang/CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ if(CLANG_BUILT_STANDALONE)
6868
option(CLANG_ENABLE_BOOTSTRAP "Generate the clang bootstrap target" OFF)
6969
option(LLVM_ENABLE_LIBXML2 "Use libxml2 if available." ON)
7070

71+
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
72+
add_definitions(${LLVM_DEFINITIONS_LIST})
73+
list(APPEND CMAKE_REQUIRED_DEFINITIONS ${LLVM_DEFINITIONS_LIST})
74+
7175
include(AddLLVM)
7276
include(TableGen)
7377
include(HandleLLVMOptions)
@@ -183,18 +187,17 @@ check_include_file(sys/resource.h CLANG_HAVE_RLIMITS)
183187
# This check requires _GNU_SOURCE on linux
184188
check_include_file(dlfcn.h CLANG_HAVE_DLFCN_H)
185189
if( CLANG_HAVE_DLFCN_H )
190+
include(CMakePushCheckState)
186191
include(CheckLibraryExists)
187192
include(CheckSymbolExists)
188193
check_library_exists(dl dlopen "" HAVE_LIBDL)
194+
cmake_push_check_state()
189195
if( HAVE_LIBDL )
190196
list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
191197
endif()
192198
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
193199
check_symbol_exists(dladdr dlfcn.h CLANG_HAVE_DLADDR)
194-
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
195-
if( HAVE_LIBDL )
196-
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl)
197-
endif()
200+
cmake_pop_check_state()
198201
endif()
199202

200203
set(CLANG_RESOURCE_DIR "" CACHE STRING

0 commit comments

Comments
 (0)