Skip to content

[CMake] Do all availability checks with -D_GNU_SOURCE #116640

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

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions llvm/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
endif()

# Newer POSIX functions aren't available without the appropriate defines.
# Usually those are set by the use of -std=gnuXX, but one can also use the
# newer functions with -std=c(++)XX, i.e. without the GNU language extensions.
# Keep this at the top to make sure we don't add _GNU_SOURCE dependent checks
# before adding it.
check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
if(LLVM_USING_GLIBC)
add_compile_definitions(_GNU_SOURCE)
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")

# enable 64bit off_t on 32bit systems using glibc
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
add_compile_definitions(_FILE_OFFSET_BITS=64)
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
endif()
endif()

# include checks
check_include_file(dlfcn.h HAVE_DLFCN_H)
check_include_file(errno.h HAVE_ERRNO_H)
Expand Down Expand Up @@ -336,17 +353,6 @@ else()
"sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
endif()

check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
if( LLVM_USING_GLIBC )
add_compile_definitions(_GNU_SOURCE)
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
# enable 64bit off_t on 32bit systems using glibc
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
add_compile_definitions(_FILE_OFFSET_BITS=64)
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
endif()
endif()

# This check requires _GNU_SOURCE.
if (NOT PURE_WINDOWS)
if (LLVM_PTHREAD_LIB)
Expand Down
Loading