Skip to content

Commit 2274588

Browse files
committed
[CMake] Test more things under -D_GNU_SOURCE
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.
1 parent 4c4a413 commit 2274588

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

llvm/cmake/config-ix.cmake

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
4040
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
4141
endif()
4242

43+
check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
44+
if(LLVM_USING_GLIBC)
45+
# Newer POSIX functions aren't available without the appropriate defines.
46+
# Usually those are set by the use of -std=gnuXX, but one can also use the
47+
# newer functions with -std=c(++)XX, i.e. without the GNU language extensions.
48+
add_compile_definitions(_GNU_SOURCE)
49+
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
50+
51+
# enable 64bit off_t on 32bit systems using glibc
52+
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
53+
add_compile_definitions(_FILE_OFFSET_BITS=64)
54+
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
55+
endif()
56+
endif()
57+
4358
# include checks
4459
check_include_file(dlfcn.h HAVE_DLFCN_H)
4560
check_include_file(errno.h HAVE_ERRNO_H)
@@ -336,17 +351,6 @@ else()
336351
"sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
337352
endif()
338353

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-
350354
# This check requires _GNU_SOURCE.
351355
if (NOT PURE_WINDOWS)
352356
if (LLVM_PTHREAD_LIB)

0 commit comments

Comments
 (0)