unbound: import cmake build system

This commit is contained in:
Ben Boeckel 2014-10-21 18:39:15 -04:00
parent e59b5b7078
commit abbd5c0bdb
5 changed files with 1429 additions and 82 deletions

View file

@ -117,6 +117,7 @@ endif()
# Final setup for libunbound
include_directories(${UNBOUND_INCLUDE})
link_directories(${UNBOUND_LIBRARY_DIRS})
if(MSVC)
add_definitions("/bigobj /MP /W3 /GS- /D_CRT_SECURE_NO_WARNINGS /wd4996 /wd4345 /D_WIN32_WINNT=0x0600 /DWIN32_LEAN_AND_MEAN /DGTEST_HAS_TR1_TUPLE=0 /FIinline_c.h /D__SSE4_1__")

View file

@ -78,90 +78,13 @@ endif()
find_package(Unbound)
IF(!UNBOUND_INCLUDE_DIR OR STATIC)
if(STATIC)
message(STATUS "Using libunbound from local source tree for static build")
else()
message(STATUS "Using libunbound from local source tree (/external/unbound)")
endif()
INCLUDE(ExternalProject)
FIND_PACKAGE(OpenSSL QUIET)
IF(!OPENSSL_LIBRARIES)
die("Could not find the openssl library. Please make sure you have installed openssl or libssl-dev or the equivalent")
ELSE()
MESSAGE(STATUS "Found openssl libraries")
ENDIF()
FIND_PACKAGE(Expat QUIET)
IF(!EXPAT_LIBRARIES)
die("Could not find the expat library. Please make sure you have installed libexpat or libexpat-dev or the equivalent")
ELSE()
MESSAGE(STATUS "Found expat libraries")
ENDIF()
IF(MINGW)
set(ENV{USE_WINSOCK} 1)
set(ENV{CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
set(ENV{GCC_PREFIX} ${GCC_PREFIX})
set(ENV{CMAKE_FIND_ROOT_PATH} ${CMAKE_FIND_ROOT_PATH})
EXTERNALPROJECT_ADD(
libunbound
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/unbound
URL ${CMAKE_CURRENT_SOURCE_DIR}/unbound/
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/unbound/monero-config.sh
BUILD_COMMAND $(MAKE)
UPDATE_COMMAND ""
PATCH_COMMAND ""
INSTALL_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build/libtool --mode=install cp ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build/libunbound.la ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build
LOG_DOWNLOAD 1
LOG_UPDATE 1
LOG_CONFIGURE 1
LOG_BUILD 1
LOG_TEST 1
LOG_INSTALL 1
)
ELSEIF(APPLE)
execute_process(COMMAND brew --prefix OUTPUT_VARIABLE BREW_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
EXTERNALPROJECT_ADD(
libunbound
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/unbound
URL ${CMAKE_CURRENT_SOURCE_DIR}/unbound/
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/unbound/configure --prefix=${BREW_PREFIX} --enable-shared --enable-static --disable-gost --disable-rpath --with-libevent=no --without-pyunbound --without-pythonmodule --without-pthreads --with-libunbound-only
BUILD_COMMAND $(MAKE)
UPDATE_COMMAND ""
PATCH_COMMAND ""
INSTALL_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build/libtool --mode=install cp ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build/libunbound.la ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build
LOG_DOWNLOAD 1
LOG_UPDATE 1
LOG_CONFIGURE 1
LOG_BUILD 1
LOG_TEST 1
LOG_INSTALL 1
)
ELSE()
EXTERNALPROJECT_ADD(
libunbound
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/unbound
URL ${CMAKE_CURRENT_SOURCE_DIR}/unbound/
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/unbound/configure --disable-shared --enable-static --disable-gost --disable-rpath --with-libevent=no --without-pyunbound --without-pythonmodule --without-pthreads --with-libunbound-only
BUILD_COMMAND $(MAKE)
UPDATE_COMMAND ""
PATCH_COMMAND ""
INSTALL_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build/libtool --mode=install cp ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build/libunbound.la ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build
LOG_DOWNLOAD 1
LOG_UPDATE 1
LOG_CONFIGURE 1
LOG_BUILD 1
LOG_TEST 1
LOG_INSTALL 1
)
ENDIF()
IF(NOT UNBOUND_INCLUDE_DIR OR STATIC)
add_subdirectory(unbound)
set(UNBOUND_STATIC true PARENT_SCOPE)
set(UNBOUND_INCLUDE "${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build" PARENT_SCOPE)
set(UNBOUND_LIBRARY "${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build/libunbound.a;${OPENSSL_LIBRARIES}" PARENT_SCOPE)
set(UNBOUND_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/unbound/libunbound" PARENT_SCOPE)
set(UNBOUND_LIBRARY "unbound" PARENT_SCOPE)
set(UNBOUND_LIBRARY_DIRS "${LIBEVENT2_LIBRARY_DIRS}" PARENT_SCOPE)
ELSE()
MESSAGE(STATUS "Found libunbound include (unbound.h) in ${UNBOUND_INCLUDE_DIR}")
IF(UNBOUND_LIBRARIES)
@ -169,6 +92,7 @@ ELSE()
set(UNBOUND_STATIC false PARENT_SCOPE)
set(UNBOUND_INCLUDE ${UNBOUND_INCLUDE_DIR} PARENT_SCOPE)
set(UNBOUND_LIBRARY ${UNBOUND_LIBRARIES} PARENT_SCOPE)
set(UNBOUND_LIBRARY_DIRS "" PARENT_SCOPE)
ELSE()
die("Found libunbound includes, but could not find libunbound library. Please make sure you have installed libunbound or libunbound-dev or the equivalent")
ENDIF()

180
external/unbound/CMakeLists.txt vendored Normal file
View file

@ -0,0 +1,180 @@
cmake_minimum_required(VERSION 2.8.8)
project(unbound C)
find_package(OpenSSL REQUIRED)
find_package(Threads)
include(configure_checks.cmake)
if (WIN32)
set(USE_MINI_EVENT 1)
set(USE_WINSOCK 1)
else ()
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBEVENT2 REQUIRED libevent)
endif ()
set(RETSIGTYPE void)
add_definitions(-D_GNU_SOURCE)
option(USE_ECDSA "Use ECDSA algorithms" ON)
option(USE_SHA2 "Enable SHA2 support" ON)
set(ENABLE_DNSTAP 0)
set(HAVE_SSL 1)
if (CMAKE_USE_PTHREADS_INIT AND NOT CMAKE_USE_WIN32_THREADS_INIT)
set(HAVE_PTHREAD 1)
else ()
set(HAVE_PTHREAD 0)
endif ()
if (CMAKE_USE_WIN32_THREADS_INIT)
set(HAVE_WINDOWS_THREADS 1)
else ()
set(HAVE_WINDOWS_THREADS 0)
endif ()
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/config.h")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/dnstap/dnstap_config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/dnstap/dnstap_config.h")
set(common_src
services/cache/dns.c
services/cache/infra.c
services/cache/rrset.c
util/data/dname.c
util/data/msgencode.c
util/data/msgparse.c
util/data/msgreply.c
util/data/packed_rrset.c
iterator/iterator.c
iterator/iter_delegpt.c
iterator/iter_donotq.c
iterator/iter_fwd.c
iterator/iter_hints.c
iterator/iter_priv.c
iterator/iter_resptype.c
iterator/iter_scrub.c
iterator/iter_utils.c
services/listen_dnsport.c
services/localzone.c
services/mesh.c
services/modstack.c
services/outbound_list.c
services/outside_network.c
util/alloc.c
util/config_file.c
util/configlexer.c
util/configparser.c
util/fptr_wlist.c
util/locks.c
util/log.c
util/mini_event.c
util/module.c
util/netevent.c
util/net_help.c
util/random.c
util/rbtree.c
util/regional.c
util/rtt.c
util/storage/dnstree.c
util/storage/lookup3.c
util/storage/lruhash.c
util/storage/slabhash.c
util/timehist.c
util/tube.c
util/winsock_event.c
validator/autotrust.c
validator/val_anchor.c
validator/validator.c
validator/val_kcache.c
validator/val_kentry.c
validator/val_neg.c
validator/val_nsec3.c
validator/val_nsec.c
validator/val_secalgo.c
validator/val_sigcrypt.c
validator/val_utils.c
dns64/dns64.c
#$(CHECKLOCK_SRC)
testcode/checklocks.c)
set(compat_src)
foreach (symbol IN ITEMS ctime_r gmtime_r inet_aton inet_ntop inet_pton malloc memcmp memmove snprintf strlcat strlcpy strptime explicit_bzero arc4random arc4random_uniform sha512)
string(TOUPPER "${symbol}" upper_sym)
if (NOT HAVE_${upper_sym})
list(APPEND compat_src
compat/${symbol}.c)
endif ()
endforeach ()
if (NOT HAVE_ARC4RANDOM)
list(APPEND compat_src
compat/arc4_lock.c)
endif ()
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
list(APPEND compat_src
compat/getentropy_linux.c)
elseif (APPLE)
list(APPEND compat_src
compat/getentropy_osx.c)
#elseif (SunOS)
# list(APPEND compat_src
# compat/getentropy_solaris.c)
elseif (WIN32)
list(APPEND compat_src
compat/getentropy_win.c)
endif ()
if (NOT HAVE_GETADDRINFO)
list(APPEND compat_src
compat/fake-rfc2553.c)
endif ()
set(sldns_src
ldns/keyraw.c
ldns/sbuffer.c
ldns/wire2str.c
ldns/parse.c
ldns/parseutil.c
ldns/rrdef.c
ldns/str2wire.c)
set(libunbound_src
libunbound/context.c
libunbound/libunbound.c
libunbound/libworker.c)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
include_directories(SYSTEM ${OPENSSL_INCLUDE_DIR})
if (LIBEVENT2_FOUND)
include_directories(SYSTEM ${LIBEVENT2_INCLUDE_DIRS})
link_directories(${LIBEVENT2_LIBRARY_DIRS})
endif ()
add_library(unbound
${common_src}
${sldns_src}
${compat_src}
${libunbound_src})
target_link_libraries(unbound
PRIVATE
${OPENSSL_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT})
if (LIBEVENT2_FOUND)
target_link_libraries(unbound
PRIVATE
${LIBEVENT2_LIBRARIES})
endif ()
if (WIN32)
target_link_libraries(unbound
PRIVATE
iphlpapi
ws2_32)
endif ()

1034
external/unbound/config.h.cmake.in vendored Normal file

File diff suppressed because it is too large Load diff

208
external/unbound/configure_checks.cmake vendored Normal file
View file

@ -0,0 +1,208 @@
include(CheckIncludeFile)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckTypeSize)
# Need expat.
check_include_file(arpa/inet.h HAVE_ARPA_INET_H)
check_include_file(endian.h HAVE_ENDIAN_H)
check_include_file(dlfcn.h HAVE_DLFCN_H)
check_include_file(event.h HAVE_EVENT_H)
check_include_file(getopt.h HAVE_GETOPT_H)
check_include_file(glob.h HAVE_GLOB_H)
check_include_file(grp.h HAVE_GRP_H)
check_include_file(inttypes.h HAVE_INTTYPES_H)
check_include_file(iphlpapi.h HAVE_IPHLPAPI_H)
check_include_file(login_cap.h HAVE_LOGIN_CAP_H)
check_include_file(memory.h HAVE_MEMORY_H)
check_include_file(netdb.h HAVE_NETDB_H)
check_include_file(netinet/in.h HAVE_NETINET_IN_H)
check_include_file(pwd.h HAVE_PWD_H)
check_include_file(stdarg.h HAVE_STDARG_H)
check_include_file(stdbool.h HAVE_STDBOOL_H)
check_include_file(stdint.h HAVE_STDINT_H)
check_include_file(stdlib.h HAVE_STDLIB_H)
check_include_file(strings.h HAVE_STRINGS_H)
check_include_file(string.h HAVE_STRING_H)
check_include_file(sys/param.h HAVE_SYS_PARAM_H)
check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
check_include_file(sys/sha2.h HAVE_SYS_SHA2_H)
check_include_file(sys/socket.h HAVE_SYS_SOCKET_H)
check_include_file(sys/stat.h HAVE_SYS_STAT_H)
check_include_file(sys/sysctl.h HAVE_SYS_SYSCTL_H)
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
check_include_file(sys/uio.h HAVE_SYS_UIO_H)
check_include_file(sys/wait.h HAVE_SYS_WAIT_H)
check_include_file(syslog.h HAVE_SYSLOG_H)
check_include_file(time.h HAVE_TIME_H)
check_include_file(unistd.h HAVE_UNISTD_H)
check_include_file(vfork.h HAVE_VFORK_H)
check_include_file(windows.h HAVE_WINDOWS_H)
check_include_file(winsock2.h HAVE_WINSOCK2_H)
check_include_file(ws2tcpip.h HAVE_WS2TCPIP_H)
if (WIN32)
set(CMAKE_REQUIRED_LIBRARIES
iphlpapi
ws2_32)
endif ()
check_function_exists(arc4random HAVE_ARC4RANDOM)
check_function_exists(arc4random_uniform HAVE_ARC4RANDOM_UNIFORM)
check_function_exists(chown HAVE_CHOWN)
check_function_exists(chroot HAVE_CHROOT)
check_function_exists(ctime_r HAVE_CTIME_R)
check_function_exists(daemon HAVE_DAEMON)
check_function_exists(endprotoent HAVE_ENDPROTOENT)
check_function_exists(endservent HAVE_ENDSERVENT)
check_function_exists(fnctl HAVE_FNCTL)
check_function_exists(fork HAVE_FORK)
check_function_exists(fseeko HAVE_FSEEKO)
check_function_exists(getaddrinfo HAVE_GETADDRINFO)
check_function_exists(getentropy HAVE_GETENTROPY)
check_function_exists(getpwnam HAVE_GETPWNAM)
check_function_exists(getrlimit HAVE_GETRLIMIT)
check_function_exists(glob HAVE_GLOB)
check_function_exists(gmtime_r HAVE_GMTIME_R)
check_function_exists(inet_aton HAVE_INET_ATON)
check_function_exists(inet_ntop HAVE_INET_NTOP)
check_function_exists(inet_pton HAVE_INET_PTON)
check_function_exists(initgroups HAVE_INITGROUPS)
check_function_exists(ioctlsocket HAVE_IOCTLSOCKET)
check_function_exists(kill HAVE_KILL)
check_function_exists(localtime_r HAVE_LOCALTIME_R)
check_function_exists(malloc HAVE_MALLOC)
check_function_exists(memmove HAVE_MEMMOVE)
check_function_exists(random HAVE_RANDOM)
check_function_exists(recvmsg HAVE_RECVMSG)
check_function_exists(sbrk HAVE_SBRK)
check_function_exists(sendmsg HAVE_SENDMSG)
check_function_exists(setregid HAVE_SETREGID)
check_function_exists(setresgid HAVE_SETRESGID)
check_function_exists(setresuid HAVE_SETRESUID)
check_function_exists(setreuid HAVE_SETREUID)
check_function_exists(setrlimit HAVE_SETRLIMIT)
check_function_exists(setsid HAVE_SETSID)
check_function_exists(setusercontent HAVE_SETUSERCONTENT)
check_function_exists(sigprocmask HAVE_SIGPROCMASK)
check_function_exists(sleep HAVE_SLEEP)
check_function_exists(snprintf HAVE_SNPRINTF)
check_function_exists(socketpair HAVE_SOCKETPAIR)
check_function_exists(srandom HAVE_SRANDOM)
check_function_exists(strftime HAVE_STRFTIME)
check_function_exists(strlcat HAVE_STRLCAT)
check_function_exists(strlcpy HAVE_STRLCPY)
check_function_exists(strptime HAVE_STRPTIME)
check_function_exists(strlcpy HAVE_STRLCPY)
check_function_exists(tzset HAVE_TZSET)
check_function_exists(usleep HAVE_USLEEP)
check_function_exists(writev HAVE_WRITEV)
check_function_exists(_beginthreadex HAVE__BEGINTHREADEX)
function (check_type_exists type variable header default)
set(CMAKE_EXTRA_INCLUDE_FILES "${header}")
check_type_size("${type}" "${variable}")
if (${variable} STREQUAL "")
set("${variable}" "${default}" PARENT_SCOPE)
else ()
set("${variable}" "" PARENT_SCOPE)
endif ()
endfunction ()
set(CMAKE_EXTRA_INCLUDE_FILES "time.h")
check_type_size(time_t SIZEOF_TIME_T)
set(CMAKE_EXTRA_INCLUDE_FILES)
check_type_exists(gid_t gid_t "sys/types.h" int)
check_type_exists(in_addr_t in_addr_t "netinet/in.h" uint32_t)
check_type_exists(in_port_t in_port_t "netinet/in.h" uint16_t)
check_type_exists(int16_t int16_t "sys/types.h" short)
check_type_exists(int32_t int32_t "sys/types.h" int)
check_type_exists(int64_t int64_t "sys/types.h" __int64)
check_type_exists(int8_t int8_t "sys/types.h" char)
check_type_exists(pid_t pid_t "sys/types.h" int)
check_type_exists(rlim_t rlim_t "sys/resource.h" "unsigned long")
check_type_exists(ssize_t ssize_t "sys/types.h" int)
check_type_exists(uid_t uid_t "sys/types.h" int)
check_type_exists(uint16_t uint16_t "sys/types.h" "unsigned short")
check_type_exists(uint32_t uint32_t "sys/types.h" "unsigned int")
check_type_exists(uint64_t uint64_t "sys/types.h" "unsigned long long")
check_type_exists(uint8_t uint8_t "sys/types.h" "unsigned char")
if (WIN32)
set(UB_ON_WINDOWS 1)
endif ()
if (MSVC)
set(inline __inline)
set(__func__ __FUNCTION__)
endif ()
if (NOT HAVE_VFORK)
set(vfork fork)
endif ()
# XXX: Check for broken malloc()?
# XXX: Check for broken memcmp()?
# XXX: Check for broken vfork()?
# XXX: Check for one-arg mkdir?
check_symbol_exists(PTHREAD_PRIO_INHERIT "pthread.h" HAVE_PTHREAD_PRIO_INHERIT)
check_symbol_exists(pthread_rwlock_t "pthread.h" HAVE_PTHREAD_RWLOCK_T)
check_symbol_exists(pthread_spinlock_t "pthread.h" HAVE_PTHREAD_SPINLOCK_T)
# openssl
set(CMAKE_REQUIRED_INCLUDES
${OPENSSL_INCLUDE_DIR})
check_include_file(openssl/conf.h HAVE_OPENSSL_CONF_H)
check_include_file(openssl/engine.h HAVE_OPENSSL_ENGINE_H)
check_include_file(openssl/err.h HAVE_OPENSSL_ERR_H)
check_include_file(openssl/rand.h HAVE_OPENSSL_RAND_H)
check_include_file(openssl/ssl.h HAVE_OPENSSL_SSL_H)
set(CMAKE_REQUIRED_INCLUDES)
check_symbol_exists(NID_secp384r1 "openssl/evp.h" HAVE_DECL_NID_SECP384R1)
check_symbol_exists(NID_X9_62_prime256v1 "openssl/evp.h" HAVE_DECL_NID_X9_62_PRIME256V1)
check_symbol_exists(sk_SSL_COMP_pop_free "openssl/ssl.h" HAVE_DECL_SK_SSL_COMP_POP_FREE)
check_symbol_exists(SSL_COMP_get_compression_methods "openssl/ssl.h" HAVE_DECL_SSL_COMP_GET_COMPRESSION_METHODS)
set(CMAKE_REQUIRED_LIBRARIES
${OPENSSL_LIBRARIES})
check_function_exists(EVP_sha1 HAVE_EVP_SHA1)
check_function_exists(EVP_sha256 HAVE_EVP_SHA256)
check_function_exists(EVP_sha512 HAVE_EVP_SHA512)
check_function_exists(FIPS_mode HAVE_FIPS_MODE)
check_function_exists(HMAC_CTX_init HAVE_HMAC_CTX_INIT)
check_function_exists(OPENSSL_config HAVE_OPENSSL_CONFIG)
check_function_exists(SHA512_Update HAVE_SHA512_UPDATE)
set(CMAKE_REQUIRED_LIBRARIES)
set(UNBOUND_CONFIGFILE "${CMAKE_INSTALL_PREFIX}/etc/unbound/unbound.conf"
CACHE STRING "default configuration file")
set(UNBOUND_USERNAME "unbound"
CACHE STRING "default user that unbound changes to")
set(UNBOUND_CHROOT_DIR "${CMAKE_INSTALL_PREFIX}/etc/unbound"
CACHE STRING "default directory to chroot to")
set(UNBOUND_RUN_DIR "${CMAKE_INSTALL_PREFIX}/etc/unbound"
CACHE STRING "default directory to chroot to")
set(UNBOUND_SHARE_DIR "${CMAKE_INSTALL_PREFIX}/etc/unbound"
CACHE STRING "default directory with shared data")
set(UNBOUND_PIDFILE "${CMAKE_INSTALL_PREFIX}/etc/unbound/unbound.pid"
CACHE STRING "default pathname to the pidfile")
# Copied from configure.ac.
set(WINVER 0x0502)
set(PACKAGE_VERSION "1.4.23")
set(PACKAGE_NAME "${PROJECT_NAME}")
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(MAXSYSLOGMSGLEN 10240)
# Make assumptions.
set(HAVE_WORKING_FORK ${HAVE_FORK})
set(HAVE_WORKING_VFORK ${HAVE_VFORK})