aboutsummaryrefslogtreecommitdiff
path: root/cmake.config/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'cmake.config/CMakeLists.txt')
-rw-r--r--cmake.config/CMakeLists.txt100
1 files changed, 34 insertions, 66 deletions
diff --git a/cmake.config/CMakeLists.txt b/cmake.config/CMakeLists.txt
index 6de86cbaf2..ed405c602e 100644
--- a/cmake.config/CMakeLists.txt
+++ b/cmake.config/CMakeLists.txt
@@ -4,6 +4,7 @@ include(CheckFunctionExists)
include(CheckIncludeFiles)
include(CheckCSourceRuns)
include(CheckCSourceCompiles)
+include(TestBigEndian)
check_c_source_compiles("
#include <execinfo.h>
@@ -28,34 +29,26 @@ int main(void)
check_type_size("int" SIZEOF_INT LANGUAGE C)
check_type_size("long" SIZEOF_LONG LANGUAGE C)
check_type_size("intmax_t" SIZEOF_INTMAX_T LANGUAGE C)
-check_type_size("int32_t" SIZEOF_INT32_T LANGUAGE C)
check_type_size("size_t" SIZEOF_SIZE_T LANGUAGE C)
-check_type_size("long long" SIZEOF_LONG_LONG LANGUAGE C)
check_type_size("void *" SIZEOF_VOID_PTR LANGUAGE C)
check_symbol_exists(_NSGetEnviron crt_externs.h HAVE__NSGETENVIRON)
# Headers
check_include_files(langinfo.h HAVE_LANGINFO_H)
-check_include_files(locale.h HAVE_LOCALE_H)
-check_include_files(pwd.h HAVE_PWD_H)
check_include_files(strings.h HAVE_STRINGS_H)
check_include_files(sys/utsname.h HAVE_SYS_UTSNAME_H)
check_include_files(termios.h HAVE_TERMIOS_H)
check_include_files(sys/uio.h HAVE_SYS_UIO_H)
check_include_files(sys/sdt.h HAVE_SYS_SDT_H)
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ check_include_files(sys/xattr.h HAVE_XATTR)
+endif()
# Functions
check_function_exists(fseeko HAVE_FSEEKO)
-check_function_exists(getpwent HAVE_GETPWENT)
-check_function_exists(getpwnam HAVE_GETPWNAM)
-check_function_exists(getpwuid HAVE_GETPWUID)
check_function_exists(readv HAVE_READV)
-check_function_exists(opendir HAVE_OPENDIR)
check_function_exists(readlink HAVE_READLINK)
-check_function_exists(setpgid HAVE_SETPGID)
-check_function_exists(setsid HAVE_SETSID)
-check_function_exists(sigaction HAVE_SIGACTION)
check_function_exists(strnlen HAVE_STRNLEN)
check_function_exists(strcasecmp HAVE_STRCASECMP)
check_function_exists(strncasecmp HAVE_STRNCASECMP)
@@ -64,22 +57,28 @@ check_function_exists(strptime HAVE_STRPTIME)
check_c_source_compiles("
#include <sys/types.h>
#include <dirent.h>
+#include <sys/file.h>
int main(void)
{
DIR *dir = opendir(\"dirname\");
dirfd(dir);
+ flock(10, LOCK_SH);
return 0;
}
-" HAVE_DIRFD)
+" HAVE_DIRFD_AND_FLOCK)
+
check_c_source_compiles("
-#include <sys/file.h>
+#include <pwd.h>
int main(void)
{
- flock(10, LOCK_SH);
+ getpwent();
+ getpwuid(0);
+ getpwnam(\"root\");
return 0;
}
-" HAVE_FLOCK)
+" HAVE_PWD_FUNCS)
+
if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
check_c_source_compiles("
@@ -101,11 +100,13 @@ if(HAVE_LANGINFO_H)
endif()
check_include_files("endian.h" HAVE_ENDIAN_H)
-check_include_files("sys/endian.h" HAVE_SYS_ENDIAN_H)
set(ENDIAN_INCLUDE_FILE "endian.h")
-if(HAVE_SYS_ENDIAN_H AND NOT HAVE_ENDIAN_H)
- set(ENDIAN_INCLUDE_FILE "sys/endian.h")
+if(NOT HAVE_ENDIAN_H)
+ check_include_files("sys/endian.h" HAVE_SYS_ENDIAN_H)
+ if (HAVE_SYS_ENDIAN_H)
+ set(ENDIAN_INCLUDE_FILE "sys/endian.h")
+ endif()
endif()
set(SI "#include <stdint.h>\n")
@@ -130,63 +131,30 @@ endif()
if("${HAVE_BE64TOH_MACROS}" OR "${HAVE_BE64TOH_FUNC}")
set(HAVE_BE64TOH 1)
endif()
-if (NOT "${HAVE_BE64TOH}")
- if (NOT "${CMAKE_CROSSCOMPILING}")
- # It is safe to make ORDER_BIG_ENDIAN not defined if
- # - HAVE_BE64TOH is true. In this case be64toh will be used unconditionally in
- # any case and ORDER_BIG_ENDIAN will not be examined.
- # - CMAKE_CROSSCOMPILING *and* HAVE_BE64TOH are both false. In this case
- # be64toh function which uses cycle and arithmetic operations is used which
- # will work regardless of endianness. Function is sub-optimal though.
- check_c_source_runs("
- ${SI}
- ${MS}
- char *s = (char *) &i;
- return (
- s[0] == 0x01
- && s[1] == 0x02
- && s[2] == 0x03
- && s[3] == 0x04
- && s[4] == 0x05
- && s[5] == 0x06
- && s[6] == 0x07
- && s[7] == 0x08) ? 0 : 1;
- ${ME}"
- ORDER_BIG_ENDIAN)
- endif()
-endif()
-# generate configuration header and update include directories
+test_big_endian(ORDER_BIG_ENDIAN)
+
configure_file (
"${PROJECT_SOURCE_DIR}/cmake.config/config.h.in"
"${PROJECT_BINARY_DIR}/cmake.config/auto/config.h"
)
-# generate version definitions
-configure_file (
- "${PROJECT_SOURCE_DIR}/cmake.config/versiondef.h.in"
- "${PROJECT_BINARY_DIR}/cmake.config/auto/versiondef.h"
- )
-
-# generate pathdef.c
-find_program(WHOAMI_PROG whoami)
-find_program(HOSTNAME_PROG hostname)
-
-if (DEFINED ENV{USERNAME})
- set(USERNAME $ENV{USERNAME})
-elseif (NOT DEFINED USERNAME AND EXISTS ${WHOAMI_PROG})
- execute_process(COMMAND ${WHOAMI_PROG}
- OUTPUT_STRIP_TRAILING_WHITESPACE
- OUTPUT_VARIABLE USERNAME)
+# Prevent double space in --version output if CMAKE_C_FLAGS is empty
+set(C_FLAGS_VERSION_OUTPUT ${CMAKE_C_FLAGS})
+if(C_FLAGS_VERSION_OUTPUT)
+ string(PREPEND C_FLAGS_VERSION_OUTPUT " ")
endif()
-if (DEFINED ENV{HOSTNAME})
- set(HOSTNAME $ENV{HOSTNAME})
-elseif (EXISTS ${HOSTNAME_PROG})
- execute_process(COMMAND ${HOSTNAME_PROG}
- OUTPUT_STRIP_TRAILING_WHITESPACE
- OUTPUT_VARIABLE HOSTNAME)
+
+if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.15)
+ configure_file(versiondef.h.in auto/versiondef.h.gen)
+else()
+ configure_file(versiondef_old.h.in auto/versiondef.h.gen)
endif()
+file(GENERATE
+ OUTPUT "${PROJECT_BINARY_DIR}/cmake.config/auto/versiondef-$<CONFIG>.h"
+ INPUT "${PROJECT_BINARY_DIR}/cmake.config/auto/versiondef.h.gen")
+
configure_file (
"${PROJECT_SOURCE_DIR}/cmake.config/pathdef.c.in"
"${PROJECT_BINARY_DIR}/cmake.config/auto/pathdef.c"