1 include(CheckIncludeFile)
2 include(CheckSymbolExists)
3 include(CheckFunctionExists)
4 include(CheckLibraryExists)
6 include(CheckStructHasMember)
7 include(CheckPrototypeDefinition)
10 set(PRIV_WRAPPER_PACKAGE ${PROJECT_NAME})
11 set(PRIV_WRAPPER_VERSION ${PROJECT_VERSION})
13 set(BINARYDIR ${CMAKE_BINARY_DIR})
14 set(SOURCEDIR ${CMAKE_SOURCE_DIR})
16 function(COMPILER_DUMPVERSION _OUTPUT_VERSION)
17 # Remove whitespaces from the argument.
18 # This is needed for CC="ccache gcc" cmake ..
19 string(REPLACE " " "" _C_COMPILER_ARG "${CMAKE_C_COMPILER_ARG1}")
23 ${CMAKE_C_COMPILER} ${_C_COMPILER_ARG} -dumpversion
24 OUTPUT_VARIABLE _COMPILER_VERSION
27 string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
28 _COMPILER_VERSION "${_COMPILER_VERSION}")
30 set(${_OUTPUT_VERSION} ${_COMPILER_VERSION} PARENT_SCOPE)
33 if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
34 compiler_dumpversion(GNUCC_VERSION)
35 if (NOT GNUCC_VERSION EQUAL 34)
36 set(CMAKE_REQUIRED_FLAGS "-fvisibility=hidden")
37 check_c_source_compiles(
38 "void __attribute__((visibility(\"default\"))) test() {}
39 int main(void){ return 0; }
40 " WITH_VISIBILITY_HIDDEN)
41 unset(CMAKE_REQUIRED_FLAGS)
42 endif (NOT GNUCC_VERSION EQUAL 34)
43 endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
46 check_include_file(sys/prctl.h HAVE_SYS_PRCTL_H)
47 check_include_file(sys/time.h HAVE_SYS_TIME_H)
48 check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
51 check_function_exists(chroot HAVE_CHROOT)
52 check_function_exists(prctl HAVE_PRCTL)
53 check_function_exists(pledge HAVE_PLEDGE)
54 check_function_exists(setrlimit HAVE_SETRLIMIT)
56 check_prototype_definition(setrlimit
57 "int setrlimit(__rlimit_resource_t resource, const struct rlimit *rlp)"
60 HAVE_SETRLIMIT_RLIMIT_RESOURCE_T)
63 find_library(DLFCN_LIBRARY dl)
65 list(APPEND _REQUIRED_LIBRARIES ${DLFCN_LIBRARY})
67 check_function_exists(dlopen HAVE_DLOPEN)
69 message(FATAL_ERROR "FATAL: No dlopen() function detected")
74 ###########################################################
75 # For detecting attributes we need to treat warnings as
77 set(CMAKE_REQUIRED_FLAGS "-Werror")
79 check_c_source_compiles("
80 void test_constructor_attribute(void) __attribute__ ((constructor));
82 void test_constructor_attribute(void)
89 }" HAVE_CONSTRUCTOR_ATTRIBUTE)
91 check_c_source_compiles("
92 void test_destructor_attribute(void) __attribute__ ((destructor));
94 void test_destructor_attribute(void)
101 }" HAVE_DESTRUCTOR_ATTRIBUTE)
103 check_c_source_compiles("
104 #define FALL_THROUGH __attribute__((fallthrough))
119 }" HAVE_FALLTHROUGH_ATTRIBUTE)
121 check_c_source_compiles("
122 void log_fn(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
126 }" HAVE_FUNCTION_ATTRIBUTE_FORMAT)
128 check_c_source_compiles("
129 void test_address_sanitizer_attribute(void) __attribute__((no_sanitize_address));
131 void test_address_sanitizer_attribute(void)
138 }" HAVE_ADDRESS_SANITIZER_ATTRIBUTE)
140 # Stop treating wanrings as errors
141 unset(CMAKE_REQUIRED_FLAGS)
142 ###########################################################
145 test_big_endian(WORDS_BIGENDIAN)
148 set(PWRAP_REQUIRED_LIBRARIES ${_REQUIRED_LIBRARIES} CACHE INTERNAL "priv_wrapper required system libraries")