From 1e006a2c35255ad02c913a48242a6557fb3eb8f1 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Fri, 27 Nov 2020 23:23:27 +0000 Subject: [PATCH] workaround some CMake and BSD issues Signed-off-by: Ivailo Monev --- CMakeLists.txt | 33 ++++++++++----------- cmake/modules/FindResolv.cmake | 12 ++++---- cmake/modules/KatieBuildMacros.cmake | 45 +++++++++++++++-------------- cmake/modules/katie_check_defined.cpp.cmake | 9 ------ 4 files changed, 45 insertions(+), 54 deletions(-) delete mode 100644 cmake/modules/katie_check_defined.cpp.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 55a53fa04..9e8f2f43a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,9 +39,11 @@ if(NOT CMAKE_VERSION VERSION_LESS "3.3.0") endif() # LLVM linker does not have a default library search path and only library names are received -# from pkg-config queries, add some directories known to contain system wide libraries +# from pkg-config queries, add some directories known to contain system wide libraries. the +# headers search path is also incomplete if(CMAKE_SYSTEM_NAME MATCHES "BSD") - link_directories(/usr/pkg/lib /usr/local/lib /usr/lib /lib) + include_directories(/usr/X11R7/include /usr/pkg/include /usr/local/include /usr/include /include) + link_directories(/usr/X11R7/lib /usr/pkg/lib /usr/local/lib /usr/lib /lib) endif() include(CheckIncludeFileCXX) @@ -353,7 +355,7 @@ check_include_file_cxx(cxxabi.h HAVE_CXXABI) # stored in qconfig.h.cmake check_type_size(size_t QT_POINTER_SIZE) -# POSIX.1-2001 +# used in components, tests and JavaScriptCore katie_check_function(getpwnam_r "pwd.h") katie_check_function(getpwuid_r "pwd.h") katie_check_function(getgrgid_r "grp.h") @@ -362,40 +364,35 @@ katie_check_function(getaddrinfo "netdb.h") katie_check_function(clock_gettime "time.h") katie_check_function(vsnprintf "stdio.h") katie_check_function(posix_memalign "stdlib.h") -# XSI/POSIX.1-2001 katie_check_function(strerror_r "string.h") -# SUSv2 katie_check_function(localtime_r "time.h") katie_check_function(gmtime_r "time.h") -# SVr2, removed in POSIX.1-2008 katie_check_function(fcvt "stdlib.h") katie_check_function(ecvt "stdlib.h") -# NetBSD 1.6 and FreeBSD 4.4 katie_check_function(getprogname "stdlib.h") -# FreeBSD 5.4 -katie_check_function(pthread_attr_get_np "pthread_np.h" "${CMAKE_THREAD_LIBS_INIT}") -# OpenBSD 2.1 katie_check_function(arc4random "stdlib.h") -# GNU katie_check_function(get_current_dir_name "unistd.h") katie_check_function(prctl "sys/prctl.h") -katie_check_function(pthread_setname_np "pthread.h" "${CMAKE_THREAD_LIBS_INIT}") -katie_check_function(timegm "time.h") -katie_check_struct(tm tm_gmtoff "time.h") -katie_check_struct(tm tm_zone "time.h") -# ISO/IEC 9899:1999 katie_check_function(fegetenv "fenv.h") katie_check_function(fesetenv "fenv.h") katie_check_function(feclearexcept "fenv.h") katie_check_function(feenableexcept "fenv.h") -# none -katie_check_function(pthread_stackseg_np "pthread_np.h" "${CMAKE_THREAD_LIBS_INIT}") katie_check_function(madvise "sys/mman.h") katie_check_function(getifaddrs "ifaddrs.h") +katie_check_function(timegm "time.h") +katie_check_struct(tm tm_gmtoff "time.h") +katie_check_struct(tm tm_zone "time.h") katie_check_struct(sockaddr_ll sll_addr "netpacket/packet.h") katie_check_struct(sockaddr_dl sdl_index "net/if_dl.h") katie_check_struct(dirent d_type "dirent.h") +cmake_reset_check_state() +set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) +katie_check_function(pthread_setname_np "pthread.h") +katie_check_function(pthread_stackseg_np "pthread_np.h") +katie_check_function(pthread_attr_get_np "pthread_np.h") +cmake_reset_check_state() + # 64-bit offset alternatives, if any of the functions is not found it will set # QT_LARGEFILE_SUPPORT to FALSE. QT_LARGEFILE_SUPPORT is used in qconfig.h set(QT_LARGEFILE_SUPPORT TRUE) diff --git a/cmake/modules/FindResolv.cmake b/cmake/modules/FindResolv.cmake index db4208b48..1fc095899 100644 --- a/cmake/modules/FindResolv.cmake +++ b/cmake/modules/FindResolv.cmake @@ -21,16 +21,18 @@ find_path(RESOLV_INCLUDES set(RESOLV_LIBRARIES) foreach(name ${RESOLV_NAMES}) - if(NOT HAVE_res_ninit AND NOT HAVE_res_init) + unset(HAVE_res_ninit CACHE) + unset(HAVE_res_init CACHE) + if(NOT RESOLV_LIBRARIES) cmake_reset_check_state() set(CMAKE_REQUIRED_LIBRARIES ${name}) - katie_check_function(res_ninit "resolv.h") - cmake_pop_check_state() + katie_check_defined(res_ninit "resolv.h") + cmake_reset_check_state() if(NOT HAVE_res_ninit) cmake_reset_check_state() set(CMAKE_REQUIRED_LIBRARIES ${name}) - katie_check_function(res_init "resolv.h") - cmake_pop_check_state() + katie_check_defined(res_init "resolv.h") + cmake_reset_check_state() endif() if(HAVE_res_ninit OR HAVE_res_init) find_library(RESOLV_LIBRARIES diff --git a/cmake/modules/KatieBuildMacros.cmake b/cmake/modules/KatieBuildMacros.cmake index 08fff5f33..f1c8b9494 100644 --- a/cmake/modules/KatieBuildMacros.cmake +++ b/cmake/modules/KatieBuildMacros.cmake @@ -11,31 +11,31 @@ include(CheckStructHasMember) # a function to check for C function/definition, works for external functions. function(KATIE_CHECK_DEFINED FORDEFINITION FROMHEADER) - set(compileout "${CMAKE_BINARY_DIR}/${FORDEFINITION}.cpp") - configure_file( - "${CMAKE_SOURCE_DIR}/cmake/modules/katie_check_defined.cpp.cmake" - "${compileout}" - @ONLY - ) - try_compile(${FORDEFINITION}_test - "${CMAKE_BINARY_DIR}" - "${compileout}" - COMPILE_DEFINITIONS ${ARGN} - OUTPUT_VARIABLE ${FORDEFINITION}_test_output + # see comment in top-level CMakeLists file + set(CMAKE_REQUIRED_FLAGS -I/usr/X11R7/include -I/usr/pkg/include -I/usr/local/include -I/usr/include -I/include) + set(CMAKE_REQUIRED_LINK_OPTIONS -I/usr/X11R7/lib -L/usr/pkg/lib -L/usr/local/lib -L/usr/lib -L/lib) + check_cxx_source_compiles( + " +#include +#include <${FROMHEADER}> + +static bool willprint = true; // bypass compiler/linker optimizations +int main() { + willprint = false; + if (willprint) { + return printf(\"%p\", &${FORDEFINITION}); + } + return 0; +} +" + HAVE_${FORDEFINITION} ) - if(${FORDEFINITION}_test) - message(STATUS "Found ${FORDEFINITION} in: <${FROMHEADER}>") - set(HAVE_${FORDEFINITION} TRUE PARENT_SCOPE) - else() - message(STATUS "Could not find ${FORDEFINITION} in: <${FROMHEADER}>") - set(HAVE_${FORDEFINITION} FALSE PARENT_SCOPE) - endif() endfunction() # a macro to check for C function presence in header, if function is found a # definition is added. macro(KATIE_CHECK_FUNCTION FORFUNCTION FROMHEADER) - katie_check_defined("${FORFUNCTION}" "${FROMHEADER}" ${ARGN}) + katie_check_defined("${FORFUNCTION}" "${FROMHEADER}") if(HAVE_${FORFUNCTION}) string(TOUPPER "${FORFUNCTION}" upperfunction) @@ -48,7 +48,10 @@ endmacro() # additional checks if one fails function(KATIE_CHECK_FUNCTION64 FORFUNCTION FROMHEADER) if(QT_LARGEFILE_SUPPORT) - katie_check_defined("${FORFUNCTION}" "${FROMHEADER}" -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE ${ARGN}) + cmake_reset_check_state() + set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE) + katie_check_defined("${FORFUNCTION}" "${FROMHEADER}") + cmake_reset_check_state() if(NOT HAVE_${FORFUNCTION}) set(QT_LARGEFILE_SUPPORT FALSE PARENT_SCOPE) @@ -59,9 +62,7 @@ endfunction() # a macro to check for C struct member presence in header, if member is found a # definition is added. function(KATIE_CHECK_STRUCT FORSTRUCT FORMEMBER FROMHEADER) - cmake_reset_check_state() check_struct_has_member("struct ${FORSTRUCT}" "${FORMEMBER}" "${FROMHEADER}" HAVE_${FORSTRUCT}_${FORMEMBER}) - cmake_pop_check_state() if(HAVE_${FORSTRUCT}_${FORMEMBER}) string(TOUPPER "${FORSTRUCT}_${FORMEMBER}" upperstructmember) diff --git a/cmake/modules/katie_check_defined.cpp.cmake b/cmake/modules/katie_check_defined.cpp.cmake deleted file mode 100644 index e9c46509c..000000000 --- a/cmake/modules/katie_check_defined.cpp.cmake +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include <@FROMHEADER@> - -int main() { - return 0; -#ifndef @FORDEFINITION@ - return printf("%p\n", &@FORDEFINITION@); -#endif -} -- 2.11.0