summary refs log tree commit diff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CMakeLists.txt151
1 files changed, 151 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..5385049
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,151 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(dash VERSION 0.5.11.5 LANGUAGES C)
+
+include(CheckCSourceCompiles)
+include(CheckIncludeFile)
+include(CheckLibraryExists)
+include(CheckStructHasMember)
+include(CheckSymbolExists)
+include(CheckTypeSize)
+include(GNUInstallDirs)
+
+check_c_source_compiles([[
+void t() {}
+void a() __attribute__((__alias__("t")));
+int main() { a(); return 0; }
+]] HAVE_ALIAS_ATTRIBUTE)
+
+option(ENABLE_FNMATCH "Use fnmatch(3) from libc")
+option(ENABLE_GLOB "Use glob(3) from libc")
+
+# Checks for header files.
+check_include_file("alloca.h" HAVE_ALLOCA_H)
+check_include_file("paths.h" HAVE_PATHS_H)
+
+# Check for declarations
+check_symbol_exists(_PATH_BSHELL "paths.h" HAVE__PATH_BSHELL)
+check_symbol_exists(_PATH_DEVNULL "paths.h" HAVE__PATH_DEVNULL)
+check_symbol_exists(_PATH_TTY "paths.h" HAVE__PATH_TTY)
+add_compile_definitions(
+	$<$<NOT:$<BOOL:${HAVE__PATH_BSHELL}>>:_PATH_BSHELL="/bin/sh">
+	$<$<NOT:$<BOOL:${HAVE__PATH_DEVNULL}>>:_PATH_DEVNULL="/dev/null">
+	$<$<NOT:$<BOOL:${HAVE__PATH_TTY}>>:_PATH_TTY="/dev/tty">
+)
+
+# Some systems lack isblank
+check_symbol_exists(isblank "ctype.h" HAVE_DECL_ISBLANK)
+
+# Check for sizes of types
+check_type_size("intmax_t" SIZEOF_INTMAX_T)
+check_type_size("long long int" SIZEOF_LONG_LONG_INT)
+
+# Select a fallback format string for intmax_t in case we don't find PRIdMAX
+set(
+	INTMAX_FSTR
+	$<IF:$<EQUAL:${SIZEOF_INTMAX_T},${SIZEOF_LONG_LONG_INT}>,lld,jd>
+)
+
+# Check for PRIdMAX and define it to a fallback if not found
+check_symbol_exists(PRIdMAX "inttypes.h" HAVE_PRIdMAX)
+if(NOT HAVE_PRIdMAX)
+	add_compile_definitions(PRIdMAX="${INTMAX_FSTR}")
+endif()
+
+# Checks for library functions.
+check_symbol_exists(bsearch "stdlib.h" HAVE_BSEARCH)
+check_symbol_exists(faccessat "unistd.h" HAVE_FACCESSAT)
+check_symbol_exists(getpwnam "pwd.h" HAVE_GETPWNAM)
+check_symbol_exists(getrlimit "sys/resource.h" HAVE_GETRLIMIT)
+check_symbol_exists(isalpha "ctype.h" HAVE_ISALPHA)
+check_symbol_exists(killpg "signal.h" HAVE_KILLPG)
+check_symbol_exists(memcpy "string.h" HAVE_MEMCPY)
+check_symbol_exists(sigsetmask "signal.h" HAVE_SIGSETMASK)
+check_symbol_exists(stpcpy "string.h" HAVE_STPCPY)
+check_symbol_exists(strchrnul "string.h" HAVE_STRCHRNUL)
+check_symbol_exists(strsignal "string.h" HAVE_STRSIGNAL)
+check_symbol_exists(strtod "stdlib.h" HAVE_STRTOD)
+check_symbol_exists(strtoimax "inttypes.h" HAVE_STRTOIMAX)
+check_symbol_exists(strtoumax "inttypes.h" HAVE_STRTOUMAX)
+check_symbol_exists(sysconf "unistd.h" HAVE_SYSCONF)
+
+# Check whether it's worth working around FreeBSD PR kern/125009.
+# The traditional behavior of access/faccessat is crazy, but
+# POSIX.1-2008 explicitly allows those functions to misbehave.
+#
+# Unaffected kernels:
+#
+# - all versions of Linux
+# - NetBSD sys/kern/vfs_subr.c 1.64, 1997-04-23
+# - FreeBSD 9 (r212002), 2010-09-10
+# - OpenBSD sys/kern/vfs_subr.c 1.166, 2008-06-09
+#
+# Also worked around in Debian's libc0.1 2.13-19 when using
+# kFreeBSD 8.
+option(
+	ENABLE_TEST_WORKAROUND
+	"Guard against faccessat(2) that tells root all files are executable"
+	AUTO
+)
+if(ENABLE_TEST_WORKAROUND STREQUAL "AUTO" AND HAVE_FACCESSAT)
+	if(
+		CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
+		CMAKE_SYSTEM_NAME STREQUAL "GNU/kFreeBSD"
+	)
+		set(ENABLE_TEST_WORKAROUND ON)
+	endif()
+	set(
+		HAVE_TRADITIONAL_FACCESSAT ON CACHE
+		BOOL "Define if your faccessat tells root all files are executable"
+	)
+endif()
+
+if(ENABLE_FNMATCH)
+	check_symbol_exists(fnmatch "fnmatch.h" HAVE_FNMATCH)
+endif()
+
+if(HAVE_FNMATCH AND ENABLE_GLOB)
+	check_symbol_exists(glob "glob.h" HAVE_GLOB)
+endif()
+
+# Check for klibc signal.
+check_symbol_exists(bsd_signal "signal.h" HAVE_BSD_SIGNAL)
+if(HAVE_BSD_SIGNAL)
+	add_compile_definitions(signal=bsd_signal)
+endif()
+
+# Check for stat64 (dietlibc/klibc).
+check_symbol_exists(stat64 "sys/stat.h" HAVE_STAT64)
+if(NOT HAVE_STAT64)
+	add_compile_definitions(fstat64=fstat lstat64=lstat stat64=stat)
+endif()
+
+# OS X apparently has stat64 but not open64.
+check_symbol_exists(open64 "fcntl.h" HAVE_OPEN64)
+if(NOT HAVE_OPEN64)
+	add_compile_definitions(open64=open readdir64=readdir dirent64=dirent)
+endif()
+
+# Check if struct stat has st_mtim.
+check_struct_has_member(
+	"struct stat" "st_mtim.tv_sec" "sys/stat.h" HAVE_ST_MTIM
+)
+
+option(WITH_LIBEDIT "Compile with libedit support")
+if(WITH_LIBEDIT)
+	check_include_file("histedit.h" HAVE_HISTEDIT_H)
+	check_library_exists(edit history_init /usr/lib LIBEDIT_FOUND)
+	if(HAVE_HISTEDIT_H AND LIBEDIT_FOUND)
+		link_libraries(edit)
+	else()
+		message(SEND_ERROR "Can't find libedit.")
+	endif()
+else()
+	add_compile_definitions(SMALL)
+endif()
+
+option(WITH_LINENO "Enable LINENO support" ON)
+
+configure_file(config.h.in config.h)
+
+add_subdirectory(src)