Skip to content

[cmake] Hardcode some check_include_file checks #104706

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 16 commits into from
Jan 16, 2025
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
94 changes: 80 additions & 14 deletions llvm/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,86 @@ include(CheckCompilerVersion)
include(CheckProblematicConfigurations)
include(HandleLLVMStdlib)

if (ANDROID OR CYGWIN OR CMAKE_SYSTEM_NAME MATCHES "AIX|DragonFly|FreeBSD|Haiku|Linux|NetBSD|OpenBSD|SunOS")
set(HAVE_DLFCN_H 1)
set(HAVE_MACH_MACH_H 0)
set(HAVE_MALLOC_MALLOC_H 0)
set(HAVE_PTHREAD_H 1)
set(HAVE_SIGNAL_H 1)
set(HAVE_SYS_IOCTL_H 1)
set(HAVE_SYS_MMAN_H 1)
set(HAVE_SYS_PARAM_H 1)
set(HAVE_SYS_RESOURCE_H 1)
set(HAVE_SYS_STAT_H 1)
set(HAVE_SYS_TIME_H 1)
set(HAVE_SYSEXITS_H 1)
set(HAVE_TERMIOS_H 1)
set(HAVE_UNISTD_H 1)
elseif (APPLE)
set(HAVE_DLFCN_H 1)
set(HAVE_MACH_MACH_H 1)
set(HAVE_MALLOC_MALLOC_H 1)
set(HAVE_PTHREAD_H 1)
set(HAVE_SIGNAL_H 1)
set(HAVE_SYS_IOCTL_H 1)
set(HAVE_SYS_MMAN_H 1)
set(HAVE_SYS_PARAM_H 1)
set(HAVE_SYS_RESOURCE_H 1)
set(HAVE_SYS_STAT_H 1)
set(HAVE_SYS_TIME_H 1)
set(HAVE_SYSEXITS_H 1)
set(HAVE_TERMIOS_H 1)
set(HAVE_UNISTD_H 1)
elseif (PURE_WINDOWS)
set(HAVE_DLFCN_H 0)
set(HAVE_MACH_MACH_H 0)
set(HAVE_MALLOC_MALLOC_H 0)
set(HAVE_PTHREAD_H 0)
set(HAVE_SIGNAL_H 1)
set(HAVE_SYS_IOCTL_H 0)
set(HAVE_SYS_MMAN_H 0)
set(HAVE_SYS_PARAM_H 0)
set(HAVE_SYS_RESOURCE_H 0)
set(HAVE_SYS_STAT_H 1)
set(HAVE_SYS_TIME_H 0)
set(HAVE_SYSEXITS_H 0)
set(HAVE_TERMIOS_H 0)
set(HAVE_UNISTD_H 0)
elseif (ZOS)
# Confirmed in
# https://github.com/llvm/llvm-project/pull/104706#issuecomment-2297109613
set(HAVE_DLFCN_H 1)
set(HAVE_MACH_MACH_H 0)
set(HAVE_MALLOC_MALLOC_H 0)
set(HAVE_PTHREAD_H 1)
set(HAVE_SIGNAL_H 1)
set(HAVE_SYS_IOCTL_H 1)
set(HAVE_SYS_MMAN_H 1)
set(HAVE_SYS_PARAM_H 0)
set(HAVE_SYS_RESOURCE_H 1)
set(HAVE_SYS_STAT_H 1)
set(HAVE_SYS_TIME_H 1)
set(HAVE_SYSEXITS_H 0)
set(HAVE_TERMIOS_H 1)
set(HAVE_UNISTD_H 1)
else()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, once you set the values, the check queries will early-out because they detect the cached value. Having it always call the check functions (even if the value is set) may make it easy to add platforms where some of these are known to exist, but others may not be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to the set(ZOS 1) line. Since the cmake platform files are already defining ZOS should we be defining it in the llvm cmake files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to the set(ZOS 1) line. Since the cmake platform files are already defining ZOS should we be defining it in the llvm cmake files?

If ZOS is always provided on z/OS CMake for one reason or another, we better skip setting it indeed. But it's news for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, once you set the values, the check queries will early-out because they detect the cached value.

I've never felt I understood cache variables enough to feel comfortable relying on them. But I agree, this should be the case.

Having it always call the check functions (even if the value is set) may make it easy to add platforms where some of these are known to exist, but others may not be.

Are you sure this would serve a practical purpose? If one cares enough to set some of them beforehand to improve configuration times, I don't see how they would not check the rest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, once you set the values, the check queries will early-out because they detect the cached value.

I agree that this is the behavior (https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/CheckIncludeFile.cmake?ref_type=heads#L46), but I don't see it documented at https://cmake.org/cmake/help/latest/module/CheckIncludeFile.html. So I'm reluctant to rely on this.

# Other platforms that we don't promise support for.
check_include_file(dlfcn.h HAVE_DLFCN_H)
check_include_file(mach/mach.h HAVE_MACH_MACH_H)
check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
check_include_file(pthread.h HAVE_PTHREAD_H)
check_include_file(signal.h HAVE_SIGNAL_H)
check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
check_include_file(sys/param.h HAVE_SYS_PARAM_H)
check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
check_include_file(sys/stat.h HAVE_SYS_STAT_H)
check_include_file(sys/time.h HAVE_SYS_TIME_H)
check_include_file(sysexits.h HAVE_SYSEXITS_H)
check_include_file(termios.h HAVE_TERMIOS_H)
check_include_file(unistd.h HAVE_UNISTD_H)
endif()

if( UNIX AND NOT (APPLE OR BEOS OR HAIKU) )
# Used by check_symbol_exists:
list(APPEND CMAKE_REQUIRED_LIBRARIES "m")
Expand Down Expand Up @@ -58,19 +138,6 @@ if(LLVM_USING_GLIBC)
endif()

# include checks
check_include_file(dlfcn.h HAVE_DLFCN_H)
check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
if( NOT PURE_WINDOWS )
check_include_file(pthread.h HAVE_PTHREAD_H)
endif()
check_include_file(signal.h HAVE_SIGNAL_H)
check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
check_include_file(sys/time.h HAVE_SYS_TIME_H)
check_include_file(sysexits.h HAVE_SYSEXITS_H)
check_include_file(termios.h HAVE_TERMIOS_H)
check_include_file(unistd.h HAVE_UNISTD_H)
check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT)
check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)
Expand All @@ -86,7 +153,6 @@ check_c_source_compiles("
int main(void) { return 0; }"
HAVE_BUILTIN_THREAD_POINTER)

check_include_file(mach/mach.h HAVE_MACH_MACH_H)
check_include_file(CrashReporterClient.h HAVE_CRASHREPORTERCLIENT_H)
if(APPLE)
check_c_source_compiles("
Expand Down
Loading