2019-01-04 20:04:18 +00:00
|
|
|
# The following defines affect the environment configuration tests are run in:
|
|
|
|
# CMAKE_REQUIRED_DEFINITIONS, CMAKE_REQUIRED_FLAGS, CMAKE_REQUIRED_LIBRARIES,
|
|
|
|
# and CMAKE_REQUIRED_INCLUDES
|
|
|
|
# `wcstod_l` is a GNU-extension, sometimes hidden behind GNU-related defines.
|
|
|
|
# This is the case for at least Cygwin and Newlib.
|
2020-03-14 23:11:35 +00:00
|
|
|
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE=1)
|
2020-07-05 02:13:28 +00:00
|
|
|
include(CheckCXXCompilerFlag)
|
2020-03-14 23:11:35 +00:00
|
|
|
|
|
|
|
if(APPLE)
|
|
|
|
check_cxx_compiler_flag("-Werror=unguarded-availability" REQUIRES_UNGUARDED_AVAILABILITY)
|
|
|
|
if(REQUIRES_UNGUARDED_AVAILABILITY)
|
|
|
|
list(APPEND CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} "-Werror=unguarded-availability")
|
|
|
|
endif()
|
|
|
|
endif()
|
2019-01-04 20:04:18 +00:00
|
|
|
|
2020-07-05 18:31:21 +00:00
|
|
|
# An unrecognized flag is usually a warning and not an error, which CMake apparently does
|
|
|
|
# not pick up on. Combine it with -Werror to determine if it's actually supported.
|
2021-02-22 21:41:24 +00:00
|
|
|
# This is not bulletproof; old versions of GCC only emit a warning about unrecognized warning
|
|
|
|
# options when there are other warnings to emit :rolleyes:
|
|
|
|
# See https://github.com/fish-shell/fish-shell/commit/fe2da0a9#commitcomment-47431659
|
|
|
|
|
|
|
|
# GCC supports -Wno-redundant-move from GCC9 onwards
|
|
|
|
check_cxx_compiler_flag("-Werror=no-redundant-move" HAS_NO_REDUNDANT_MOVE)
|
2020-07-05 02:13:28 +00:00
|
|
|
if (HAS_NO_REDUNDANT_MOVE)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-redundant-move")
|
|
|
|
endif()
|
2021-02-22 21:41:24 +00:00
|
|
|
# Clang once supported -Wno-redundant-move but replaced it with a Wredundant-move option instead
|
|
|
|
# (and it is functionally different from its older version of GCC's Wno-redundant-move).
|
|
|
|
check_cxx_compiler_flag("-Werror=redundant-move" HAS_REDUNDANT_MOVE)
|
|
|
|
if (HAS_REDUNDANT_MOVE)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wredundant-move")
|
|
|
|
endif()
|
2020-07-05 02:13:28 +00:00
|
|
|
|
2022-04-02 19:42:04 +00:00
|
|
|
# Disable static destructors if we can.
|
|
|
|
check_cxx_compiler_flag("-fno-c++-static-destructors" DISABLE_STATIC_DESTRUCTORS)
|
|
|
|
if (DISABLE_STATIC_DESTRUCTORS)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-c++-static-destructors")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2019-01-03 00:38:55 +00:00
|
|
|
# Try using CMake's own logic to locate curses/ncurses
|
2020-03-14 23:11:35 +00:00
|
|
|
find_package(Curses)
|
|
|
|
if(NOT ${CURSES_FOUND})
|
2019-01-03 00:38:55 +00:00
|
|
|
# CMake has trouble finding platform-specific system libraries
|
|
|
|
# installed to multiarch paths (e.g. /usr/lib/x86_64-linux-gnu)
|
|
|
|
# if not symlinked or passed in as a manual define.
|
2020-03-14 23:11:35 +00:00
|
|
|
message("Falling back to pkg-config for (n)curses detection")
|
|
|
|
include(FindPkgConfig)
|
|
|
|
pkg_search_module(CURSES REQUIRED ncurses curses)
|
|
|
|
set(CURSES_CURSES_LIBRARY ${CURSES_LIBRARIES})
|
|
|
|
set(CURSES_LIBRARY ${CURSES_LIBRARIES})
|
|
|
|
endif()
|
2020-07-22 03:56:12 +00:00
|
|
|
# Set up extra include directories for CheckIncludeFile
|
|
|
|
list(APPEND CMAKE_REQUIRED_INCLUDES ${CURSES_INCLUDE_DIRS})
|
2017-08-31 20:24:20 +00:00
|
|
|
|
2020-07-08 15:56:20 +00:00
|
|
|
# Fix undefined reference to tparm on RHEL 6 and potentially others
|
|
|
|
# If curses is found via CMake, it also links against tinfo if it exists. But if we use our
|
|
|
|
# fallback pkg-config logic above, we need to do this manually.
|
|
|
|
find_library(CURSES_TINFO tinfo)
|
|
|
|
if (CURSES_TINFO)
|
|
|
|
set(CURSES_LIBRARY ${CURSES_LIBRARY} ${CURSES_TINFO})
|
|
|
|
endif()
|
|
|
|
|
2017-08-31 20:24:20 +00:00
|
|
|
# Get threads.
|
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
2020-03-14 23:11:35 +00:00
|
|
|
find_package(Threads REQUIRED)
|
2017-08-31 20:24:20 +00:00
|
|
|
|
2018-03-05 03:13:31 +00:00
|
|
|
# Detect WSL. Does not match against native Windows/WIN32.
|
|
|
|
if (CMAKE_HOST_SYSTEM_VERSION MATCHES ".*-Microsoft")
|
2020-03-14 23:11:35 +00:00
|
|
|
set(WSL 1)
|
2018-03-05 03:13:31 +00:00
|
|
|
endif()
|
|
|
|
|
2017-08-31 20:24:20 +00:00
|
|
|
# Set up the config.h file.
|
2020-03-14 23:11:35 +00:00
|
|
|
set(PACKAGE_NAME "fish")
|
|
|
|
set(PACKAGE_TARNAME "fish")
|
|
|
|
include(CheckCXXSymbolExists)
|
|
|
|
include(CheckIncludeFileCXX)
|
|
|
|
include(CheckIncludeFiles)
|
|
|
|
include(CheckStructHasMember)
|
|
|
|
include(CheckCXXSourceCompiles)
|
|
|
|
include(CheckTypeSize)
|
|
|
|
include(CMakePushCheckState)
|
|
|
|
check_cxx_symbol_exists(backtrace_symbols execinfo.h HAVE_BACKTRACE_SYMBOLS)
|
2021-10-02 23:47:17 +00:00
|
|
|
|
|
|
|
# workaround for lousy mtime precision on a Linux kernel
|
|
|
|
if (CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
|
|
|
|
check_cxx_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
|
|
|
|
check_cxx_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS)
|
|
|
|
if ((HAVE_CLOCK_GETTIME) AND (HAVE_FUTIMENS))
|
|
|
|
set(UVAR_FILE_SET_MTIME_HACK 1)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2020-03-14 23:11:35 +00:00
|
|
|
check_cxx_symbol_exists(ctermid_r stdio.h HAVE_CTERMID_R)
|
|
|
|
check_struct_has_member("struct dirent" d_type dirent.h HAVE_STRUCT_DIRENT_D_TYPE LANGUAGE CXX)
|
|
|
|
check_cxx_symbol_exists(dirfd "sys/types.h;dirent.h" HAVE_DIRFD)
|
|
|
|
check_include_file_cxx(execinfo.h HAVE_EXECINFO_H)
|
|
|
|
check_cxx_symbol_exists(flock sys/file.h HAVE_FLOCK)
|
|
|
|
check_cxx_symbol_exists(getpwent pwd.h HAVE_GETPWENT)
|
|
|
|
check_cxx_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
|
|
|
|
check_cxx_symbol_exists(gettext libintl.h HAVE_GETTEXT)
|
|
|
|
check_cxx_symbol_exists(killpg "sys/types.h;signal.h" HAVE_KILLPG)
|
2018-01-30 13:58:13 +00:00
|
|
|
# mkostemp is in stdlib in glibc and FreeBSD, but unistd on macOS
|
2020-03-14 23:11:35 +00:00
|
|
|
check_cxx_symbol_exists(mkostemp "stdlib.h;unistd.h" HAVE_MKOSTEMP)
|
|
|
|
set(HAVE_CURSES_H ${CURSES_HAVE_CURSES_H})
|
|
|
|
set(HAVE_NCURSES_CURSES_H ${CURSES_HAVE_NCURSES_CURSES_H})
|
|
|
|
set(HAVE_NCURSES_H ${CURSES_HAVE_NCURSES_H})
|
|
|
|
if(HAVE_CURSES_H)
|
|
|
|
check_include_files("curses.h;term.h" HAVE_TERM_H)
|
|
|
|
endif()
|
|
|
|
if(NOT HAVE_TERM_H)
|
|
|
|
check_include_file_cxx("ncurses/term.h" HAVE_NCURSES_TERM_H)
|
|
|
|
endif()
|
|
|
|
check_include_file_cxx(siginfo.h HAVE_SIGINFO_H)
|
|
|
|
check_include_file_cxx(spawn.h HAVE_SPAWN_H)
|
|
|
|
check_struct_has_member("struct stat" st_ctime_nsec "sys/stat.h" HAVE_STRUCT_STAT_ST_CTIME_NSEC
|
2017-11-07 02:13:49 +00:00
|
|
|
LANGUAGE CXX)
|
2020-03-14 23:11:35 +00:00
|
|
|
check_struct_has_member("struct stat" st_mtimespec.tv_nsec "sys/stat.h"
|
2017-11-07 02:13:49 +00:00
|
|
|
HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC LANGUAGE CXX)
|
2020-03-14 23:11:35 +00:00
|
|
|
check_struct_has_member("struct stat" st_mtim.tv_nsec "sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
|
2017-11-07 02:13:49 +00:00
|
|
|
LANGUAGE CXX)
|
2020-03-14 23:11:35 +00:00
|
|
|
check_include_file_cxx(sys/ioctl.h HAVE_SYS_IOCTL_H)
|
|
|
|
check_include_file_cxx(sys/select.h HAVE_SYS_SELECT_H)
|
2022-01-20 17:04:40 +00:00
|
|
|
|
|
|
|
# glibc 2.30 deprecated <sys/sysctl.h> because that's what glibc does.
|
|
|
|
# Checking for that here rather than hardcoding a check on the glibc
|
|
|
|
# version in the C++ sources at point of use makes more sense.
|
|
|
|
SET(OLD_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
|
|
|
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
|
2020-03-14 23:11:35 +00:00
|
|
|
check_include_files("sys/types.h;sys/sysctl.h" HAVE_SYS_SYSCTL_H)
|
2022-01-20 17:04:40 +00:00
|
|
|
SET(CMAKE_C_FLAGS "${OLD_CMAKE_C_FLAGS}")
|
2020-03-14 23:11:35 +00:00
|
|
|
|
2021-02-07 01:44:40 +00:00
|
|
|
check_cxx_symbol_exists(eventfd sys/eventfd.h HAVE_EVENTFD)
|
2021-02-05 19:32:32 +00:00
|
|
|
check_cxx_symbol_exists(pipe2 unistd.h HAVE_PIPE2)
|
2020-03-14 23:11:35 +00:00
|
|
|
check_cxx_symbol_exists(wcscasecmp wchar.h HAVE_WCSCASECMP)
|
|
|
|
check_cxx_symbol_exists(wcsncasecmp wchar.h HAVE_WCSNCASECMP)
|
2019-01-02 20:05:06 +00:00
|
|
|
|
2019-01-04 20:46:36 +00:00
|
|
|
# These are for compatibility with Solaris 10, which places the following
|
|
|
|
# in the std namespace.
|
2020-03-14 23:11:35 +00:00
|
|
|
if(NOT HAVE_WCSNCASECMP)
|
|
|
|
check_cxx_symbol_exists(std::wcscasecmp wchar.h HAVE_STD__WCSCASECMP)
|
|
|
|
check_cxx_symbol_exists(std::wcsncasecmp wchar.h HAVE_STD__WCSNCASECMP)
|
|
|
|
endif()
|
2019-01-04 20:46:36 +00:00
|
|
|
|
2019-01-04 20:04:18 +00:00
|
|
|
# `xlocale.h` is required to find `wcstod_l` in `wchar.h` under FreeBSD,
|
|
|
|
# but it's not present under Linux.
|
2020-03-14 23:11:35 +00:00
|
|
|
check_include_files("xlocale.h" HAVE_XLOCALE_H)
|
|
|
|
if(HAVE_XLOCALE_H)
|
|
|
|
list(APPEND WCSTOD_L_INCLUDES "xlocale.h")
|
|
|
|
endif()
|
|
|
|
list(APPEND WCSTOD_L_INCLUDES "wchar.h")
|
|
|
|
check_cxx_symbol_exists(wcstod_l "${WCSTOD_L_INCLUDES}" HAVE_WCSTOD_L)
|
|
|
|
|
2021-10-13 19:09:40 +00:00
|
|
|
check_cxx_symbol_exists(uselocale "locale.h;xlocale.h" HAVE_USELOCALE)
|
|
|
|
|
2020-03-14 23:11:35 +00:00
|
|
|
cmake_push_check_state()
|
|
|
|
set(CMAKE_EXTRA_INCLUDE_FILES termios.h sys/ioctl.h)
|
|
|
|
check_type_size("struct winsize" STRUCT_WINSIZE LANGUAGE CXX)
|
|
|
|
check_cxx_symbol_exists("TIOCGWINSZ" "termios.h;sys/ioctl.h" HAVE_TIOCGWINSZ)
|
|
|
|
if(STRUCT_WINSIZE GREATER -1 AND HAVE_TIOCGWINSZ EQUAL 1)
|
|
|
|
set(HAVE_WINSIZE 1)
|
|
|
|
endif()
|
|
|
|
cmake_pop_check_state()
|
|
|
|
|
|
|
|
check_type_size("wchar_t[8]" WCHAR_T_BITS LANGUAGE CXX)
|
|
|
|
|
|
|
|
set(TPARM_INCLUDES)
|
|
|
|
if(HAVE_NCURSES_H)
|
|
|
|
set(TPARM_INCLUDES "${TPARM_INCLUDES}#include <ncurses.h>\n")
|
|
|
|
elseif(HAVE_NCURSES_CURSES_H)
|
|
|
|
set(TPARM_INCLUDES "${TPARM_INCLUDES}#include <ncurses/curses.h>\n")
|
|
|
|
else()
|
|
|
|
set(TPARM_INCLUDES "${TPARM_INCLUDES}#include <curses.h>\n")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(HAVE_TERM_H)
|
|
|
|
set(TPARM_INCLUDES "${TPARM_INCLUDES}#include <term.h>\n")
|
|
|
|
elseif(HAVE_NCURSES_TERM_H)
|
|
|
|
set(TPARM_INCLUDES "${TPARM_INCLUDES}#include <ncurses/term.h>\n")
|
|
|
|
endif()
|
2017-11-17 08:21:15 +00:00
|
|
|
|
2020-03-14 23:11:35 +00:00
|
|
|
cmake_push_check_state()
|
|
|
|
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CURSES_LIBRARY})
|
2021-09-23 07:53:38 +00:00
|
|
|
# Solaris and X/Open-conforming systems have a fixed-args tparm
|
2020-03-14 23:11:35 +00:00
|
|
|
check_cxx_source_compiles("
|
2020-02-18 22:04:35 +00:00
|
|
|
#define TPARM_VARARGS
|
2017-11-17 08:21:15 +00:00
|
|
|
${TPARM_INCLUDES}
|
|
|
|
|
|
|
|
int main () {
|
|
|
|
tparm( \"\" );
|
|
|
|
}
|
|
|
|
"
|
|
|
|
TPARM_TAKES_VARARGS
|
|
|
|
)
|
2018-12-11 20:30:38 +00:00
|
|
|
|
2021-09-23 07:53:38 +00:00
|
|
|
|
|
|
|
# Check if tputs needs a function reading an int or char.
|
|
|
|
# The only curses I can find that needs a char is OpenIndiana.
|
|
|
|
check_cxx_source_compiles("
|
|
|
|
#include <curses.h>
|
|
|
|
#include <term.h>
|
|
|
|
|
|
|
|
static int writer(int b) {
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
return tputs(\"foo\", 5, writer);
|
|
|
|
}"
|
|
|
|
TPUTS_USES_INT_ARG
|
|
|
|
)
|
|
|
|
|
2020-03-14 23:11:35 +00:00
|
|
|
if(TPARM_TAKES_VARARGS)
|
|
|
|
set(TPARM_VARARGS 1)
|
|
|
|
else()
|
|
|
|
set(TPARM_SOLARIS_KLUDGE 1)
|
|
|
|
endif()
|
|
|
|
cmake_pop_check_state()
|
2017-11-28 13:37:42 +00:00
|
|
|
|
2019-12-22 20:31:14 +00:00
|
|
|
# Work around the fact that cmake does not propagate the language standard flag into
|
|
|
|
# the CHECK_CXX_SOURCE_COMPILES function. See CMake issue #16456.
|
|
|
|
# Ensure we do this after the FIND_PACKAGE calls which use C, and will error on a C++
|
|
|
|
# standards flag.
|
2019-12-23 14:10:30 +00:00
|
|
|
# Also see https://github.com/fish-shell/fish-shell/issues/5865
|
2020-03-14 23:11:35 +00:00
|
|
|
if(NOT POLICY CMP0067)
|
|
|
|
list(APPEND CMAKE_REQUIRED_FLAGS "${CMAKE_CXX${CMAKE_CXX_STANDARD}_EXTENSION_COMPILE_OPTION}")
|
|
|
|
endif()
|
2019-12-22 20:31:14 +00:00
|
|
|
|
2020-03-14 23:11:35 +00:00
|
|
|
check_cxx_source_compiles("
|
2018-01-31 05:43:05 +00:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
int main () {
|
|
|
|
std::unique_ptr<int> foo = std::make_unique<int>();
|
|
|
|
}
|
|
|
|
"
|
|
|
|
HAVE_STD__MAKE_UNIQUE
|
|
|
|
)
|
|
|
|
|
2020-05-22 20:31:25 +00:00
|
|
|
# Detect support for thread_local.
|
|
|
|
check_cxx_source_compiles("
|
|
|
|
int main () {
|
|
|
|
static thread_local int x = 3;
|
|
|
|
(void)x;
|
|
|
|
}
|
|
|
|
"
|
|
|
|
HAVE_CX11_THREAD_LOCAL
|
|
|
|
)
|
|
|
|
|
2020-03-14 23:11:35 +00:00
|
|
|
check_cxx_source_compiles("
|
2019-12-20 15:00:06 +00:00
|
|
|
#include <atomic>
|
2019-12-20 15:47:46 +00:00
|
|
|
#include <cstdint>
|
2022-04-03 06:01:15 +00:00
|
|
|
std::atomic<uint8_t> n8 (0);
|
2022-04-03 17:14:26 +00:00
|
|
|
std::atomic<uint64_t> n64 (0);
|
2019-12-20 15:00:06 +00:00
|
|
|
int main() {
|
2022-04-03 06:01:15 +00:00
|
|
|
uint8_t i = n8.load(std::memory_order_relaxed);
|
|
|
|
uint64_t j = n64.load(std::memory_order_relaxed);
|
|
|
|
return std::atomic_is_lock_free(&n8)
|
|
|
|
& std::atomic_is_lock_free(&n64);
|
2019-12-20 15:00:06 +00:00
|
|
|
}"
|
|
|
|
LIBATOMIC_NOT_NEEDED)
|
|
|
|
IF (NOT LIBATOMIC_NOT_NEEDED)
|
2020-03-14 23:11:35 +00:00
|
|
|
set(ATOMIC_LIBRARY "atomic")
|
|
|
|
endif()
|
2020-09-07 23:03:22 +00:00
|
|
|
|
2022-07-24 14:39:57 +00:00
|
|
|
check_cxx_source_compiles("
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
|
|
int main() {
|
2022-07-24 14:53:53 +00:00
|
|
|
static_assert(WEXITSTATUS(0x007f) == 0x7f, \"This is our message we need to add because C++ is terrible\");
|
2022-07-24 14:39:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
"
|
|
|
|
HAVE_WAITSTATUS_SIGNAL_RET)
|
|
|
|
|
2021-02-22 19:17:17 +00:00
|
|
|
IF (APPLE)
|
|
|
|
# Check if mbrtowc implementation attempts to encode invalid UTF-8 sequences
|
|
|
|
# Known culprits: at least some versions of macOS (confirmed Snow Leopard and Yosemite)
|
|
|
|
try_run(mbrtowc_invalid_utf8_exit mbrtowc_invalid_utf8_compiles ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/checks/mbrtowc_invalid_utf8.cpp")
|
|
|
|
IF ("${mbrtowc_invalid_utf8_compiles}" AND ("${mbrtowc_invalid_utf8_exit}" EQUAL 1))
|
|
|
|
SET(HAVE_BROKEN_MBRTOWC_UTF8 1)
|
|
|
|
ENDIF()
|
2020-09-07 23:03:22 +00:00
|
|
|
ENDIF()
|
2021-02-22 19:17:17 +00:00
|
|
|
|