Skip to content

Commit ec9aa4a

Browse files
authored
[cmake] Hardcode some check_include_file checks (#104706)
This patch removes 11 `check_include_file` invocations from configuration phase of LLVM subproject on most of the platforms, hardcoding the results. Fallback is left for platforms that we don't document as supported or that are not detectable via `CMAKE_SYSTEM_NAME`, e.g. z/OS. This patch reduces configuration time on Linux by 10%, going from 44.7 seconds down to 40.6 seconds on my Debian machine (ramdisk, `cmake -DLLVM_ENABLE_PROJECTS="clang;lldb;clang-tools-extra" -DLLVM_ENABLE_RUNTIMES="libunwind;libcxx;libcxxabi" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_DOXYGEN=ON -DLLVM_ENABLE_LIBCXX=ON -DBUILD_SHARED_LIBS=ON -DLLDB_ENABLE_PYTHON=ON ~/endill/llvm-project/llvm`). In order to determine the values to hardcode, I prepared the following header: ```cpp #include <dlfcn.h> #include <errno.h> #include <fcntl.h> #include <fenv.h> #include <mach/mach.h> #include <malloc/malloc.h> #include <pthread.h> #include <signal.h> #include <sys/ioctl.h> #include <sys/mman.h> #include <sys/param.h> #include <sys/resource.h> #include <sys/stat.h> #include <sys/time.h> #include <sys/types.h> #include <sysexits.h> #include <termios.h> #include <unistd.h> int main() {} ``` and tried to compile it on the oldest versions of platforms that are still supported (which was problematic to determine sometimes): macOS 12, Cygwin, DragonFly BSD 6.4.0, FreeBSD 13.3, Haiku R1 beta 4, RHEL 8.10 as a glibc-based Linux, Alpine 3.17 as musl-based Linux, NetBSD 9, OpenBSD 7.4, Solaris 11.4, Windows SDK 10.0.17763.0, which corresponds to Windows 10 1809 and is the oldest Windows 10 SDK in Visual Studio Installer. For platforms I don't have access to, which are AIX 7.2 TL5 and z/OS 2.4.0, I had to rely on the official documentation. I suspect that AIX offers a better set of headers than what this PR claims, so I'm open to input from people who have access to a live system to test it. Similarly to AIX, I have values for z/OS compiled from the official documentation that are not included in this patch, because apparently upstream CMake doesn't even support z/OS, so I don't even know how to make a place to hold those values. I see `if (ZOS)` in several places across our CMake files, but it's a mystery to me where this variable comes from. Input from people who have access to live z/OS instance is welcome.
1 parent d897512 commit ec9aa4a

File tree

1 file changed

+80
-14
lines changed

1 file changed

+80
-14
lines changed

llvm/cmake/config-ix.cmake

Lines changed: 80 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,86 @@ include(CheckCompilerVersion)
1717
include(CheckProblematicConfigurations)
1818
include(HandleLLVMStdlib)
1919

20+
if (ANDROID OR CYGWIN OR CMAKE_SYSTEM_NAME MATCHES "AIX|DragonFly|FreeBSD|Haiku|Linux|NetBSD|OpenBSD|SunOS")
21+
set(HAVE_DLFCN_H 1)
22+
set(HAVE_MACH_MACH_H 0)
23+
set(HAVE_MALLOC_MALLOC_H 0)
24+
set(HAVE_PTHREAD_H 1)
25+
set(HAVE_SIGNAL_H 1)
26+
set(HAVE_SYS_IOCTL_H 1)
27+
set(HAVE_SYS_MMAN_H 1)
28+
set(HAVE_SYS_PARAM_H 1)
29+
set(HAVE_SYS_RESOURCE_H 1)
30+
set(HAVE_SYS_STAT_H 1)
31+
set(HAVE_SYS_TIME_H 1)
32+
set(HAVE_SYSEXITS_H 1)
33+
set(HAVE_TERMIOS_H 1)
34+
set(HAVE_UNISTD_H 1)
35+
elseif (APPLE)
36+
set(HAVE_DLFCN_H 1)
37+
set(HAVE_MACH_MACH_H 1)
38+
set(HAVE_MALLOC_MALLOC_H 1)
39+
set(HAVE_PTHREAD_H 1)
40+
set(HAVE_SIGNAL_H 1)
41+
set(HAVE_SYS_IOCTL_H 1)
42+
set(HAVE_SYS_MMAN_H 1)
43+
set(HAVE_SYS_PARAM_H 1)
44+
set(HAVE_SYS_RESOURCE_H 1)
45+
set(HAVE_SYS_STAT_H 1)
46+
set(HAVE_SYS_TIME_H 1)
47+
set(HAVE_SYSEXITS_H 1)
48+
set(HAVE_TERMIOS_H 1)
49+
set(HAVE_UNISTD_H 1)
50+
elseif (PURE_WINDOWS)
51+
set(HAVE_DLFCN_H 0)
52+
set(HAVE_MACH_MACH_H 0)
53+
set(HAVE_MALLOC_MALLOC_H 0)
54+
set(HAVE_PTHREAD_H 0)
55+
set(HAVE_SIGNAL_H 1)
56+
set(HAVE_SYS_IOCTL_H 0)
57+
set(HAVE_SYS_MMAN_H 0)
58+
set(HAVE_SYS_PARAM_H 0)
59+
set(HAVE_SYS_RESOURCE_H 0)
60+
set(HAVE_SYS_STAT_H 1)
61+
set(HAVE_SYS_TIME_H 0)
62+
set(HAVE_SYSEXITS_H 0)
63+
set(HAVE_TERMIOS_H 0)
64+
set(HAVE_UNISTD_H 0)
65+
elseif (ZOS)
66+
# Confirmed in
67+
# https://github.com/llvm/llvm-project/pull/104706#issuecomment-2297109613
68+
set(HAVE_DLFCN_H 1)
69+
set(HAVE_MACH_MACH_H 0)
70+
set(HAVE_MALLOC_MALLOC_H 0)
71+
set(HAVE_PTHREAD_H 1)
72+
set(HAVE_SIGNAL_H 1)
73+
set(HAVE_SYS_IOCTL_H 1)
74+
set(HAVE_SYS_MMAN_H 1)
75+
set(HAVE_SYS_PARAM_H 0)
76+
set(HAVE_SYS_RESOURCE_H 1)
77+
set(HAVE_SYS_STAT_H 1)
78+
set(HAVE_SYS_TIME_H 1)
79+
set(HAVE_SYSEXITS_H 0)
80+
set(HAVE_TERMIOS_H 1)
81+
set(HAVE_UNISTD_H 1)
82+
else()
83+
# Other platforms that we don't promise support for.
84+
check_include_file(dlfcn.h HAVE_DLFCN_H)
85+
check_include_file(mach/mach.h HAVE_MACH_MACH_H)
86+
check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
87+
check_include_file(pthread.h HAVE_PTHREAD_H)
88+
check_include_file(signal.h HAVE_SIGNAL_H)
89+
check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
90+
check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
91+
check_include_file(sys/param.h HAVE_SYS_PARAM_H)
92+
check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
93+
check_include_file(sys/stat.h HAVE_SYS_STAT_H)
94+
check_include_file(sys/time.h HAVE_SYS_TIME_H)
95+
check_include_file(sysexits.h HAVE_SYSEXITS_H)
96+
check_include_file(termios.h HAVE_TERMIOS_H)
97+
check_include_file(unistd.h HAVE_UNISTD_H)
98+
endif()
99+
20100
if( UNIX AND NOT (APPLE OR BEOS OR HAIKU) )
21101
# Used by check_symbol_exists:
22102
list(APPEND CMAKE_REQUIRED_LIBRARIES "m")
@@ -58,19 +138,6 @@ if(LLVM_USING_GLIBC)
58138
endif()
59139

60140
# include checks
61-
check_include_file(dlfcn.h HAVE_DLFCN_H)
62-
check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
63-
if( NOT PURE_WINDOWS )
64-
check_include_file(pthread.h HAVE_PTHREAD_H)
65-
endif()
66-
check_include_file(signal.h HAVE_SIGNAL_H)
67-
check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
68-
check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
69-
check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
70-
check_include_file(sys/time.h HAVE_SYS_TIME_H)
71-
check_include_file(sysexits.h HAVE_SYSEXITS_H)
72-
check_include_file(termios.h HAVE_TERMIOS_H)
73-
check_include_file(unistd.h HAVE_UNISTD_H)
74141
check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
75142
check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT)
76143
check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)
@@ -86,7 +153,6 @@ check_c_source_compiles("
86153
int main(void) { return 0; }"
87154
HAVE_BUILTIN_THREAD_POINTER)
88155

89-
check_include_file(mach/mach.h HAVE_MACH_MACH_H)
90156
check_include_file(CrashReporterClient.h HAVE_CRASHREPORTERCLIENT_H)
91157
if(APPLE)
92158
check_c_source_compiles("

0 commit comments

Comments
 (0)