Skip to content

Commit ddc0c5c

Browse files
authored
[CMake] Do all availability checks with -D_GNU_SOURCE (#116640)
When compiling LLVM with -std=c++ instead of -std=gnu we'd fail to detect many newer POSIX functions. We define it for the whole of LLVM anyway so moving the definition to the top fixes detection of a bunch of these on such setups. Keeping it at the top also avoids accidentally introducing new dependent checks before it being defined.
1 parent ac38ab5 commit ddc0c5c

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

llvm/cmake/config-ix.cmake

+17-11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
4040
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
4141
endif()
4242

43+
# Newer POSIX functions aren't available without the appropriate defines.
44+
# Usually those are set by the use of -std=gnuXX, but one can also use the
45+
# newer functions with -std=c(++)XX, i.e. without the GNU language extensions.
46+
# Keep this at the top to make sure we don't add _GNU_SOURCE dependent checks
47+
# before adding it.
48+
check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
49+
if(LLVM_USING_GLIBC)
50+
add_compile_definitions(_GNU_SOURCE)
51+
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
52+
53+
# enable 64bit off_t on 32bit systems using glibc
54+
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
55+
add_compile_definitions(_FILE_OFFSET_BITS=64)
56+
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
57+
endif()
58+
endif()
59+
4360
# include checks
4461
check_include_file(dlfcn.h HAVE_DLFCN_H)
4562
check_include_file(errno.h HAVE_ERRNO_H)
@@ -336,17 +353,6 @@ else()
336353
"sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
337354
endif()
338355

339-
check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
340-
if( LLVM_USING_GLIBC )
341-
add_compile_definitions(_GNU_SOURCE)
342-
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
343-
# enable 64bit off_t on 32bit systems using glibc
344-
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
345-
add_compile_definitions(_FILE_OFFSET_BITS=64)
346-
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
347-
endif()
348-
endif()
349-
350356
# This check requires _GNU_SOURCE.
351357
if (NOT PURE_WINDOWS)
352358
if (LLVM_PTHREAD_LIB)

0 commit comments

Comments
 (0)