From 8bbe69f83f000a56ed8a1ce14af7f2a290c94141 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Tue, 16 Aug 2016 15:24:16 +0530 Subject: [PATCH 01/51] Uses JPEG CMake Module --- CMakeLists.txt | 9 ++++----- src/onion/extras/CMakeLists.txt | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index da0c7fe2..88de5cb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,14 +155,13 @@ if (${ONION_USE_PNG}) endif (${ONION_USE_PNG}) if (${ONION_USE_JPEG}) - find_library(JPEG_LIB NAMES jpeg PATH ${LIBPATH}) - if (JPEG_LIB) + find_package(JPEG) + if (JPEG_FOUND) set(JPEG_ENABLED true) - set(JPEG_LIB ${JPEG_LIB}) message(STATUS "libjpeg found. jpeg support is compiled in at extras.") - else (JPEG_LIB) + else (JPEG_FOUND) message("libjpeg not found. No jpeg support.") - endif (JPEG_LIB) + endif (JPEG_FOUND) endif (${ONION_USE_JPEG}) if (${ONION_USE_GC}) diff --git a/src/onion/extras/CMakeLists.txt b/src/onion/extras/CMakeLists.txt index 4cd3d145..1cc1f3bc 100644 --- a/src/onion/extras/CMakeLists.txt +++ b/src/onion/extras/CMakeLists.txt @@ -21,7 +21,7 @@ target_link_libraries(onion_extras ${PNG_LIB}) endif (${PNG_ENABLED}) if (${JPEG_ENABLED}) -target_link_libraries(onion_extras ${JPEG_LIB}) +target_link_libraries(onion_extras ${JPEG_LIBRARIES}) endif (${JPEG_ENABLED}) SET(INCLUDES_EXTRAS png.h jpeg.h) From b40b91b2f2bfa85b3fbb3536d0cd8a1c4bf35b5e Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Tue, 16 Aug 2016 15:55:53 +0530 Subject: [PATCH 02/51] Uses PNG cmake module --- CMakeLists.txt | 9 ++++----- src/onion/extras/CMakeLists.txt | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 88de5cb6..4ba87f23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,10 +135,9 @@ if (${ONION_USE_PAM}) endif (${ONION_USE_PAM}) if (${ONION_USE_PNG}) - find_library(PNG_LIB NAMES png PATH ${LIBPATH}) - if (PNG_LIB) + find_package(PNG) + if (PNG_FOUND) set(PNG_ENABLED true) - set(PNG_LIB ${PNG_LIB}) message(STATUS "libpng found. png support is compiled in at extras.") find_library(CAIRO_LIB NAMES cairo PATH ${LIBPATH}) find_file(CAIRO_HEADER cairo/cairo.h ${INCLUDE_PATH}) @@ -149,9 +148,9 @@ if (${ONION_USE_PNG}) else (CAIRO_HEADER) message(STATUS "libcairo NOT found.") endif (CAIRO_HEADER) - else (PNG_LIB) + else (PNG_FOUND) message("libpng not found. No png support.") - endif (PNG_LIB) + endif (PNG_FOUND) endif (${ONION_USE_PNG}) if (${ONION_USE_JPEG}) diff --git a/src/onion/extras/CMakeLists.txt b/src/onion/extras/CMakeLists.txt index 1cc1f3bc..87dfb600 100644 --- a/src/onion/extras/CMakeLists.txt +++ b/src/onion/extras/CMakeLists.txt @@ -17,7 +17,7 @@ endif (${JPEG_ENABLED}) add_library(onion_extras STATIC ${PNG} ${JPEG}) if (${PNG_ENABLED}) -target_link_libraries(onion_extras ${PNG_LIB}) +target_link_libraries(onion_extras ${PNG_LIBRARIES}) endif (${PNG_ENABLED}) if (${JPEG_ENABLED}) From b367b70ea9a3f7dd30e4561e373c8e1bcb298fff Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 01:28:58 +0530 Subject: [PATCH 03/51] Uses XML2 CMake module --- CMakeLists.txt | 12 +++++------- src/onion/CMakeLists.txt | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ba87f23..1c30d0f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,15 +113,13 @@ if (${ONION_USE_PTHREADS}) endif(${ONION_USE_PTHREADS}) if (${ONION_USE_XML2}) - find_library(XML2_LIB NAMES xml2 PATH ${LIBPATH}) - find_library(Z_LIB NAMES z PATH ${LIBPATH}) - find_path(XML2_HEADERS NAMES libxml/xmlwriter.h HINTS ${INCLUDE_PATH} PATH_SUFFIXES libxml2) - if(XML2_HEADERS) + find_package(LIBXML2) + if(LIBXML2_FOUND) message(STATUS "libxml2 found. WebDAV support is compiled in.") set(XML2_ENABLED true) - else(XML2_HEADERS) - message("libxml2 not found. WebDAV is not supported. ${XML2_HEADERS} ${XML2_LIB}") - endif(XML2_HEADERS) + else(LIBXML2_FOUND) + message("libxml2 not found. WebDAV is not supported.") + endif(LIBXML2_FOUND) endif(${ONION_USE_XML2}) if (${ONION_USE_PAM}) diff --git a/src/onion/CMakeLists.txt b/src/onion/CMakeLists.txt index c8322897..217f4dfc 100644 --- a/src/onion/CMakeLists.txt +++ b/src/onion/CMakeLists.txt @@ -34,9 +34,9 @@ else(${GNUTLS_ENABLED}) endif(${GNUTLS_ENABLED}) if (${XML2_ENABLED}) MESSAGE(STATUS "Compiling WebDAV support") - include_directories(${XML2_HEADERS}) + include_directories(${LIBXML2_INCLUDE_DIR}) LIST(APPEND SOURCES handlers/webdav.c) - LIST(APPEND LIBRARIES ${XML2_LIB}) + LIST(APPEND LIBRARIES ${LIBXML2_LIBRARIES}) endif (${XML2_ENABLED}) if (${PAM_ENABLED}) LIST(APPEND SOURCES handlers/auth_pam.c) From 2578d4c0947e63ed98a92c1461a2efc8aee8d694 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 01:45:31 +0530 Subject: [PATCH 04/51] Uses CURL CMake module --- CMakeLists.txt | 8 ++++---- tests/01-internal/CMakeLists.txt | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c30d0f0..6c3b193a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,13 +173,13 @@ if (${ONION_USE_GC}) endif (${ONION_USE_GC}) -find_library(CURL_LIB NAMES curl PATH ${LIBPATH}) -if(CURL_LIB) +find_package(CURL) +if(CURL_FOUND) message(STATUS "curl found. Some extra test are compiled.") set(CURL true) -else(CURL_LIB) +else(CURL_FOUND) message("curl not found. Some examples wil not be built.") -endif(CURL_LIB) +endif(CURL_FOUND) if (${ONION_USE_SYSTEMD}) find_library(SD_DAEMON_LIB NAMES systemd PATH ${LIBPATH}) diff --git a/tests/01-internal/CMakeLists.txt b/tests/01-internal/CMakeLists.txt index cdfb89bf..4c1c210f 100644 --- a/tests/01-internal/CMakeLists.txt +++ b/tests/01-internal/CMakeLists.txt @@ -36,7 +36,7 @@ add_custom_command( if(PTHREADS) add_executable(06-onion 06-onion.c utils.c mycert.pem) - target_link_libraries(06-onion onion curl) + target_link_libraries(06-onion onion ${CURL_LIBRARIES}) add_test(internal-onion 06-onion) endif(PTHREADS) @@ -68,7 +68,7 @@ add_test(internal-sessions 11-sessions) IF (CURL) add_executable(12-cloexec 12-cloexec.c) -target_link_libraries(12-cloexec onion curl) +target_link_libraries(12-cloexec onion ${CURL_LIBRARIES}) add_test(internal-cloexec 12-cloexec) ENDIF (CURL) From 9a36bac34cc8ec523b4e39f28a189c497598d58f Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 01:56:59 +0530 Subject: [PATCH 05/51] Corrects include extras path for png and jpeg header files --- src/onion/extras/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/onion/extras/CMakeLists.txt b/src/onion/extras/CMakeLists.txt index 4fdf7224..87dfb600 100644 --- a/src/onion/extras/CMakeLists.txt +++ b/src/onion/extras/CMakeLists.txt @@ -24,7 +24,7 @@ if (${JPEG_ENABLED}) target_link_libraries(onion_extras ${JPEG_LIBRARIES}) endif (${JPEG_ENABLED}) -SET(INCLUDES_EXTRAS ${PNG_HEADER} ${JPEG_HEADER}) +SET(INCLUDES_EXTRAS png.h jpeg.h) MESSAGE(STATUS "Found include files ${INCLUDES_EXTRAS}") From fd699a836fa6c2b997b31f255cd2753ea92cbd61 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 02:21:35 +0530 Subject: [PATCH 06/51] Uses GNUTLS CMakeModule and adds GCrypt CMakeModule --- CMakeLists.txt | 12 +++-- CMakeModules/COPYING-CMAKE-SCRIPTS | 22 +++++++++ CMakeModules/FindGCrypt.cmake | 75 ++++++++++++++++++++++++++++++ src/onion/CMakeLists.txt | 2 +- tools/opack/CMakeLists.txt | 2 +- 5 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 CMakeModules/COPYING-CMAKE-SCRIPTS create mode 100644 CMakeModules/FindGCrypt.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c3b193a..839326f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,8 @@ SET(ONION_USE_BINDINGS_CPP true CACHE BOOL "Compile the CPP bindings") SET(ONION_POLLER default CACHE string "Default poller to use: default | epoll | libev | libevent") ######## +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules") + execute_process( COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/git-version-gen" "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE ONION_VERSION) @@ -72,14 +74,14 @@ message(STATUS "Using ${ONION_POLLER} as poller") if (${ONION_USE_SSL}) - find_library(GNUTLS_LIB NAMES gnutls PATH ${LIBPATH}) - find_library(GCRYPT_LIB NAMES gcrypt PATH ${LIBPATH}) - if (GNUTLS_LIB AND GCRYPT_LIB) + find_package(GNUTLS) + find_package(GCrypt) + if (GNUTLS_FOUND AND GCRYPT_FOUND) set(GNUTLS_ENABLED true) message(STATUS "Gnutls found. SSL support is compiled in.") - else(GNUTLS_LIB AND GCRYPT_LIB) + else(GNUTLS_FOUND AND GCRYPT_FOUND) message("Gnutls or gcrypt not found. SSL support is not compiled in.") - endif(GNUTLS_LIB AND GCRYPT_LIB) + endif(GNUTLS_FOUND AND GCRYPT_FOUND) endif(${ONION_USE_SSL}) if (${ONION_USE_SQLITE3}) diff --git a/CMakeModules/COPYING-CMAKE-SCRIPTS b/CMakeModules/COPYING-CMAKE-SCRIPTS new file mode 100644 index 00000000..4b417765 --- /dev/null +++ b/CMakeModules/COPYING-CMAKE-SCRIPTS @@ -0,0 +1,22 @@ +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/CMakeModules/FindGCrypt.cmake b/CMakeModules/FindGCrypt.cmake new file mode 100644 index 00000000..762a59c3 --- /dev/null +++ b/CMakeModules/FindGCrypt.cmake @@ -0,0 +1,75 @@ +# - Try to find GCrypt +# Once done this will define +# +# GCRYPT_FOUND - system has GCrypt +# GCRYPT_INCLUDE_DIRS - the GCrypt include directory +# GCRYPT_LIBRARIES - Link these to use GCrypt +# GCRYPT_DEFINITIONS - Compiler switches required for using GCrypt +# +#============================================================================= +# Copyright (c) 2009-2011 Andreas Schneider +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# + +set(_GCRYPT_ROOT_HINTS + $ENV{GCRYTPT_ROOT_DIR} + ${GCRYPT_ROOT_DIR}) + +set(_GCRYPT_ROOT_PATHS + "$ENV{PROGRAMFILES}/libgcrypt") + +set(_GCRYPT_ROOT_HINTS_AND_PATHS + HINTS ${_GCRYPT_ROOT_HINTS} + PATHS ${_GCRYPT_ROOT_PATHS}) + + +find_path(GCRYPT_INCLUDE_DIR + NAMES + gcrypt.h + HINTS + ${_GCRYPT_ROOT_HINTS_AND_PATHS} +) + +find_library(GCRYPT_LIBRARY + NAMES + gcrypt + gcrypt11 + libgcrypt-11 + HINTS + ${_GCRYPT_ROOT_HINTS_AND_PATHS} +) +set(GCRYPT_LIBRARIES ${GCRYPT_LIBRARY}) + +if (GCRYPT_INCLUDE_DIR) + file(STRINGS "${GCRYPT_INCLUDE_DIR}/gcrypt.h" _gcrypt_version_str REGEX "^#define GCRYPT_VERSION \"[0-9]+.[0-9]+.[0-9]+\"") + + string(REGEX REPLACE "^.*GCRYPT_VERSION.*([0-9]+.[0-9]+.[0-9]+).*" "\\1" GCRYPT_VERSION "${_gcrypt_version_str}") +endif (GCRYPT_INCLUDE_DIR) + +include(FindPackageHandleStandardArgs) +if (GCRYPT_VERSION) + find_package_handle_standard_args(GCrypt + REQUIRED_VARS + GCRYPT_INCLUDE_DIR + GCRYPT_LIBRARIES + VERSION_VAR + GCRYPT_VERSION + FAIL_MESSAGE + "Could NOT find GCrypt, try to set the path to GCrypt root folder in the system variable GCRYPT_ROOT_DIR" + ) +else (GCRYPT_VERSION) + find_package_handle_standard_args(GCrypt + "Could NOT find GCrypt, try to set the path to GCrypt root folder in the system variable GCRYPT_ROOT_DIR" + GCRYPT_INCLUDE_DIR + GCRYPT_LIBRARIES) +endif (GCRYPT_VERSION) + +# show the GCRYPT_INCLUDE_DIRS and GCRYPT_LIBRARIES variables only in the advanced view +mark_as_advanced(GCRYPT_INCLUDE_DIR GCRYPT_LIBRARIES) diff --git a/src/onion/CMakeLists.txt b/src/onion/CMakeLists.txt index 217f4dfc..7c5d39b8 100644 --- a/src/onion/CMakeLists.txt +++ b/src/onion/CMakeLists.txt @@ -43,7 +43,7 @@ if (${PAM_ENABLED}) LIST(APPEND LIBRARIES pam pam_misc) endif (${PAM_ENABLED}) if (GNUTLS_ENABLED) - LIST(APPEND LIBRARIES gcrypt gnutls) + LIST(APPEND LIBRARIES ${GCRYPT_LIBRARIES} ${GNUTLS_LIBRARIES}) endif(GNUTLS_ENABLED) if (PTHREADS) LIST(APPEND LIBRARIES pthread) diff --git a/tools/opack/CMakeLists.txt b/tools/opack/CMakeLists.txt index f595881b..8cc37e50 100644 --- a/tools/opack/CMakeLists.txt +++ b/tools/opack/CMakeLists.txt @@ -4,7 +4,7 @@ add_executable(opack opack.c ../common/updateassets.c ../../src/onion/log.c ../. target_link_libraries(opack ${PTHREADS_LIB}) if(GNUTLS_ENABLED) - target_link_libraries(opack ${GNUTLS_LIB}) + target_link_libraries(opack ${GNUTLS_LIBRARIES}) endif(GNUTLS_ENABLED) install(TARGETS opack DESTINATION ${CMAKE_INSTALL_BINDIR}) From cea5f665bd76e29b28c51b3e2ecb86ede3c86f09 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 02:24:14 +0530 Subject: [PATCH 07/51] Removes repetative found messages from cmake --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 839326f4..60a2d1dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,7 +78,7 @@ if (${ONION_USE_SSL}) find_package(GCrypt) if (GNUTLS_FOUND AND GCRYPT_FOUND) set(GNUTLS_ENABLED true) - message(STATUS "Gnutls found. SSL support is compiled in.") + message(STATUS "SSL support is compiled in.") else(GNUTLS_FOUND AND GCRYPT_FOUND) message("Gnutls or gcrypt not found. SSL support is not compiled in.") endif(GNUTLS_FOUND AND GCRYPT_FOUND) @@ -117,7 +117,7 @@ endif(${ONION_USE_PTHREADS}) if (${ONION_USE_XML2}) find_package(LIBXML2) if(LIBXML2_FOUND) - message(STATUS "libxml2 found. WebDAV support is compiled in.") + message(STATUS "WebDAV support is compiled in.") set(XML2_ENABLED true) else(LIBXML2_FOUND) message("libxml2 not found. WebDAV is not supported.") @@ -138,7 +138,7 @@ if (${ONION_USE_PNG}) find_package(PNG) if (PNG_FOUND) set(PNG_ENABLED true) - message(STATUS "libpng found. png support is compiled in at extras.") + message(STATUS "png support is compiled in at extras.") find_library(CAIRO_LIB NAMES cairo PATH ${LIBPATH}) find_file(CAIRO_HEADER cairo/cairo.h ${INCLUDE_PATH}) if (CAIRO_HEADER) @@ -157,7 +157,7 @@ if (${ONION_USE_JPEG}) find_package(JPEG) if (JPEG_FOUND) set(JPEG_ENABLED true) - message(STATUS "libjpeg found. jpeg support is compiled in at extras.") + message(STATUS "jpeg support is compiled in at extras.") else (JPEG_FOUND) message("libjpeg not found. No jpeg support.") endif (JPEG_FOUND) @@ -177,7 +177,7 @@ endif (${ONION_USE_GC}) find_package(CURL) if(CURL_FOUND) - message(STATUS "curl found. Some extra test are compiled.") + message(STATUS "Some extra test are compiled.") set(CURL true) else(CURL_FOUND) message("curl not found. Some examples wil not be built.") From 5aab575e44c5fb31ef47c6f31de34c3b7837873a Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 02:46:57 +0530 Subject: [PATCH 08/51] Adds SQlite3 CMake Module and uses it --- CMakeLists.txt | 12 ++--- CMakeModules/FindSQLite3.cmake | 86 ++++++++++++++++++++++++++++++++++ src/onion/CMakeLists.txt | 2 +- 3 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 CMakeModules/FindSQLite3.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 60a2d1dd..97ec0b3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,13 +85,13 @@ if (${ONION_USE_SSL}) endif(${ONION_USE_SSL}) if (${ONION_USE_SQLITE3}) - find_library(SQLITE3_LIB NAMES sqlite3 PATH ${LIBPATH}) - if (SQLITE3_LIB) + find_package(SQLite3) + if (SQLITE3_FOUND) set(SQLITE3_ENABLED true) - message(STATUS "SQLite found. Sqlite session support is compiled in.") - else(SQLITE3_LIB) - message("SQLite not found. Sqlite session support is not compiled in.") - endif(SQLITE3_LIB) + message(STATUS "SQLite session support is compiled in.") + else(SQLITE3_FOUND) + message("SQLite session support is not compiled in.") + endif(SQLITE3_FOUND) endif(${ONION_USE_SQLITE3}) if (${ONION_USE_REDIS}) diff --git a/CMakeModules/FindSQLite3.cmake b/CMakeModules/FindSQLite3.cmake new file mode 100644 index 00000000..77b8eb4e --- /dev/null +++ b/CMakeModules/FindSQLite3.cmake @@ -0,0 +1,86 @@ +# - Try to find Sqlite3 +# Once done this will define +# +# SQLITE3_FOUND - system has Sqlite3 +# SQLITE3_INCLUDE_DIRS - the Sqlite3 include directory +# SQLITE3_LIBRARIES - Link these to use Sqlite3 +# SQLITE3_DEFINITIONS - Compiler switches required for using Sqlite3 +# +# Copyright (c) 2008 Andreas Schneider +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + + +if (SQLITE3_LIBRARIES AND SQLITE3_INCLUDE_DIRS) + # in cache already + set(SQLITE3_FOUND TRUE) +else (SQLITE3_LIBRARIES AND SQLITE3_INCLUDE_DIRS) + # use pkg-config to get the directories and then use these values + # in the FIND_PATH() and FIND_LIBRARY() calls + if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + include(UsePkgConfig) + pkgconfig(sqlite3 _SQLITE3_INCLUDEDIR _SQLITE3_LIBDIR _SQLITE3_LDFLAGS _SQLITE3_CFLAGS) + else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + find_package(PkgConfig) + if (PKG_CONFIG_FOUND) + pkg_check_modules(_SQLITE3 sqlite3) + endif (PKG_CONFIG_FOUND) + endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + find_path(SQLITE3_INCLUDE_DIR + NAMES + sqlite3.h + PATHS + ${_SQLITE3_INCLUDEDIR} + /usr/include + /usr/local/include + /opt/local/include + /sw/include + ) + + find_library(SQLITE3_LIBRARY + NAMES + sqlite3 + PATHS + ${_SQLITE3_LIBDIR} + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ) + + if (SQLITE3_LIBRARY) + set(SQLITE3_FOUND TRUE) + endif (SQLITE3_LIBRARY) + + set(SQLITE3_INCLUDE_DIRS + ${SQLITE3_INCLUDE_DIR} + ) + + if (SQLITE3_FOUND) + set(SQLITE3_LIBRARIES + ${SQLITE3_LIBRARIES} + ${SQLITE3_LIBRARY} + ) + endif (SQLITE3_FOUND) + + if (SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES) + set(SQLITE3_FOUND TRUE) + endif (SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES) + + if (SQLITE3_FOUND) + if (NOT Sqlite3_FIND_QUIETLY) + message(STATUS "Found Sqlite3: ${SQLITE3_LIBRARIES}") + endif (NOT Sqlite3_FIND_QUIETLY) + else (SQLITE3_FOUND) + if (Sqlite3_FIND_REQUIRED) + message(FATAL_ERROR "Could not find Sqlite3") + endif (Sqlite3_FIND_REQUIRED) + endif (SQLITE3_FOUND) + + # show the SQLITE3_INCLUDE_DIRS and SQLITE3_LIBRARIES variables only in the advanced view + mark_as_advanced(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES) + +endif (SQLITE3_LIBRARIES AND SQLITE3_INCLUDE_DIRS) diff --git a/src/onion/CMakeLists.txt b/src/onion/CMakeLists.txt index 7c5d39b8..f38a57b9 100644 --- a/src/onion/CMakeLists.txt +++ b/src/onion/CMakeLists.txt @@ -49,7 +49,7 @@ if (PTHREADS) LIST(APPEND LIBRARIES pthread) endif(PTHREADS) if (SQLITE3_ENABLED) - LIST(APPEND LIBRARIES ${SQLITE3_LIB}) + LIST(APPEND LIBRARIES ${SQLITE3_LIBRARIES}) endif(SQLITE3_ENABLED) if (REDIS_ENABLED) LIST(APPEND LIBRARIES ${REDIS_LIB}) From 46f8eea0bb8f2168e98b2e1b555483022352a791 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 03:01:49 +0530 Subject: [PATCH 09/51] Adds HiRedis CMake Module and uses it --- CMakeLists.txt | 10 ++++----- CMakeModules/FindHiRedis.cmake | 41 ++++++++++++++++++++++++++++++++++ src/onion/CMakeLists.txt | 2 +- 3 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 CMakeModules/FindHiRedis.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 97ec0b3d..b427b119 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,13 +95,13 @@ if (${ONION_USE_SQLITE3}) endif(${ONION_USE_SQLITE3}) if (${ONION_USE_REDIS}) - find_library(REDIS_LIB NAMES hiredis PATH ${LIBPATH}) - if(REDIS_LIB) + find_package(HiRedis) + if(HIREDIS_FOUND) set(REDIS_ENABLED true) - message(STATUS "Hiredis found. Redis session support is compiled in.") - else(REDIS_LIB) + message(STATUS "Redis session support is compiled in.") + else(HIREDIS_FOUND) message("Hiredis not found. Redis session support is not compiled in.") - endif(REDIS_LIB) + endif(HIREDIS_FOUND) endif(${ONION_USE_REDIS}) if (${ONION_USE_PTHREADS}) diff --git a/CMakeModules/FindHiRedis.cmake b/CMakeModules/FindHiRedis.cmake new file mode 100644 index 00000000..757baa7d --- /dev/null +++ b/CMakeModules/FindHiRedis.cmake @@ -0,0 +1,41 @@ +# - Find Redis client db (hiredis from https://github.com/antirez/hiredis) +# Find the hiredis includes and client library +# This module defines +# HIREDIS_INCLUDE_DIR, where to find hiredis/hiredis.h +# HIREDIS_LIBRARIES, the libraries needed to use redis. +# HIREDIS_FOUND, If false, do not try to use redis. +# +# Copyright (c) 2012, Lothar Braun, +# + +# Add the redis include paths here +IF (HIREDIS_INCLUDE_DIR AND HIREDIS_LIBRARIES) + SET (HIREDIS_FOUND TRUE) +ELSE(HIREDIS_INCLUDE_DIR AND HIREDIS_LIBRARIES) + FIND_PATH(HIREDIS_INCLUDE_DIR hiredis/hiredis.h + /usr/include/ + /usr/include/hiredis + /usr/local/include/ + /usr/local/include/hiredis + /opt/local/include/ + /opt/local/include/hiredis + ) + + FIND_LIBRARY(HIREDIS_LIBRARIES NAMES hiredis libhiredis + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + ) + + IF(HIREDIS_INCLUDE_DIR AND HIREDIS_LIBRARIES) + SET(HIREDIS_FOUND TRUE) + MESSAGE(STATUS "Found hiredis: ${HIREDIS_INCLUDE_DIR}, ${HIREDIS_LIBRARIES}") + INCLUDE_DIRECTORIES(${HIREDIS_INCLUDE_DIR}) + ELSE(HIREDIS_INCLUDE_DIR AND HIREDIS_LIBRARIES) + SET(HIREDIS_FOUND FALSE) + MESSAGE(STATUS "hiredis client library not found.") + ENDIF(HIREDIS_INCLUDE_DIR AND HIREDIS_LIBRARIES) + + MARK_AS_ADVANCED(HIREDIS_INCLUDE_DIR HIREDIS_LIBRARIES) +ENDIF(HIREDIS_INCLUDE_DIR AND HIREDIS_LIBRARIES) diff --git a/src/onion/CMakeLists.txt b/src/onion/CMakeLists.txt index f38a57b9..bad9ba83 100644 --- a/src/onion/CMakeLists.txt +++ b/src/onion/CMakeLists.txt @@ -52,7 +52,7 @@ if (SQLITE3_ENABLED) LIST(APPEND LIBRARIES ${SQLITE3_LIBRARIES}) endif(SQLITE3_ENABLED) if (REDIS_ENABLED) - LIST(APPEND LIBRARIES ${REDIS_LIB}) + LIST(APPEND LIBRARIES ${HIREDIS_LIBRARIES}) endif(REDIS_ENABLED) if (${ONION_POLLER} STREQUAL libevent) LIST(APPEND LIBRARIES event_core event_pthreads) From b7ab9d567488246c883fd345a8f14b6a17da3745 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 04:11:59 +0530 Subject: [PATCH 10/51] Adds Cairo CMake Module and uses it --- CMakeLists.txt | 12 +++---- CMakeModules/FindCairo.cmake | 65 ++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 CMakeModules/FindCairo.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b427b119..44c5a00b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,15 +139,11 @@ if (${ONION_USE_PNG}) if (PNG_FOUND) set(PNG_ENABLED true) message(STATUS "png support is compiled in at extras.") - find_library(CAIRO_LIB NAMES cairo PATH ${LIBPATH}) - find_file(CAIRO_HEADER cairo/cairo.h ${INCLUDE_PATH}) - if (CAIRO_HEADER) + find_package(Cairo) + if (CAIRO_FOUND) set(CAIRO_ENABLED true) - set(CAIRO_LIB ${CAIRO_LIB}) - message(STATUS "libcairo found. Adding cairo examples. ${CAIRO_LIB}") - else (CAIRO_HEADER) - message(STATUS "libcairo NOT found.") - endif (CAIRO_HEADER) + message(STATUS "Adding cairo examples.") + endif (CAIRO_FOUND) else (PNG_FOUND) message("libpng not found. No png support.") endif (PNG_FOUND) diff --git a/CMakeModules/FindCairo.cmake b/CMakeModules/FindCairo.cmake new file mode 100644 index 00000000..cea95b9f --- /dev/null +++ b/CMakeModules/FindCairo.cmake @@ -0,0 +1,65 @@ +# - Try to find Cairo +# Once done, this will define +# +# CAIRO_FOUND - system has Cairo +# CAIRO_INCLUDE_DIRS - the Cairo include directories +# CAIRO_LIBRARIES - link these to use Cairo +# +# Copyright (C) 2012 Raphael Kubo da Costa +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS +# IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +FIND_PACKAGE(PkgConfig) +PKG_CHECK_MODULES(PC_CAIRO cairo QUIET) + +FIND_PATH(CAIRO_INCLUDE_DIRS + NAMES cairo.h + HINTS ${PC_CAIRO_INCLUDEDIR} + ${PC_CAIRO_INCLUDE_DIRS} + PATH_SUFFIXES cairo +) + +FIND_LIBRARY(CAIRO_LIBRARIES + NAMES cairo + HINTS ${PC_CAIRO_LIBDIR} + ${PC_CAIRO_LIBRARY_DIRS} +) + +IF (CAIRO_INCLUDE_DIRS) + IF (EXISTS "${CAIRO_INCLUDE_DIRS}/cairo-version.h") + FILE(READ "${CAIRO_INCLUDE_DIRS}/cairo-version.h" CAIRO_VERSION_CONTENT) + + STRING(REGEX MATCH "#define +CAIRO_VERSION_MAJOR +([0-9]+)" _dummy "${CAIRO_VERSION_CONTENT}") + SET(CAIRO_VERSION_MAJOR "${CMAKE_MATCH_1}") + + STRING(REGEX MATCH "#define +CAIRO_VERSION_MINOR +([0-9]+)" _dummy "${CAIRO_VERSION_CONTENT}") + SET(CAIRO_VERSION_MINOR "${CMAKE_MATCH_1}") + + STRING(REGEX MATCH "#define +CAIRO_VERSION_MICRO +([0-9]+)" _dummy "${CAIRO_VERSION_CONTENT}") + SET(CAIRO_VERSION_MICRO "${CMAKE_MATCH_1}") + + SET(CAIRO_VERSION "${CAIRO_VERSION_MAJOR}.${CAIRO_VERSION_MINOR}.${CAIRO_VERSION_MICRO}") + ENDIF () +ENDIF () + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cairo DEFAULT_MSG CAIRO_INCLUDE_DIRS CAIRO_LIBRARIES) From 60eb9d9c6552e5e1ee32bf4b51e0a84b53cef6cb Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 04:23:50 +0530 Subject: [PATCH 11/51] Adds Systemd CMake Module and uses it --- CMakeLists.txt | 12 +++++----- CMakeModules/FindSystemd.cmake | 40 ++++++++++++++++++++++++++++++++++ src/onion/CMakeLists.txt | 2 +- 3 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 CMakeModules/FindSystemd.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 44c5a00b..65d4c097 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,13 +180,13 @@ else(CURL_FOUND) endif(CURL_FOUND) if (${ONION_USE_SYSTEMD}) - find_library(SD_DAEMON_LIB NAMES systemd PATH ${LIBPATH}) - if (SD_DAEMON_LIB) + find_package(Systemd) + if (SYSTEMD_FOUND) set(SYSTEMD_ENABLED true) - message(STATUS "libsystemd found. Systemd support compiled in.") - else(SD_DAEMON_LIB) - message("libsystemd not found. Systemd support is not compiled in. Install libsystemd-dev | systemd-devel") - endif(SD_DAEMON_LIB) + message(STATUS "Systemd support compiled in.") + else(SYSTEMD_FOUND) + message("Systemd support is not compiled in. Install libsystemd-dev | systemd-devel") + endif(SYSTEMD_FOUND) endif(${ONION_USE_SYSTEMD}) FIND_PROGRAM(MD2MAN md2man-roff) diff --git a/CMakeModules/FindSystemd.cmake b/CMakeModules/FindSystemd.cmake new file mode 100644 index 00000000..09d60115 --- /dev/null +++ b/CMakeModules/FindSystemd.cmake @@ -0,0 +1,40 @@ +#.rst: +# FindSystemd +# ------- +# +# Find Systemd library +# +# Try to find Systemd library on UNIX systems. The following values are defined +# +# :: +# +# SYSTEMD_FOUND - True if Systemd is available +# SYSTEMD_INCLUDE_DIRS - Include directories for Systemd +# SYSTEMD_LIBRARIES - List of libraries for Systemd +# SYSTEMD_DEFINITIONS - List of definitions for Systemd +# +#============================================================================= +# Copyright (c) 2015 Jari Vetoniemi +# +# Distributed under the OSI-approved BSD License (the "License"); +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= + +include(FeatureSummary) +set_package_properties(Systemd PROPERTIES + URL "http://freedesktop.org/wiki/Software/systemd/" + DESCRIPTION "System and Service Manager") + +find_package(PkgConfig) +pkg_check_modules(PC_SYSTEMD QUIET libsystemd) +find_library(SYSTEMD_LIBRARIES NAMES systemd ${PC_SYSTEMD_LIBRARY_DIRS}) +find_path(SYSTEMD_INCLUDE_DIRS systemd/sd-login.h HINTS ${PC_SYSTEMD_INCLUDE_DIRS}) + +set(SYSTEMD_DEFINITIONS ${PC_SYSTEMD_CFLAGS_OTHER}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SYSTEMD DEFAULT_MSG SYSTEMD_INCLUDE_DIRS SYSTEMD_LIBRARIES) +mark_as_advanced(SYSTEMD_INCLUDE_DIRS SYSTEMD_LIBRARIES SYSTEMD_DEFINITIONS) diff --git a/src/onion/CMakeLists.txt b/src/onion/CMakeLists.txt index bad9ba83..bb0c4cdc 100644 --- a/src/onion/CMakeLists.txt +++ b/src/onion/CMakeLists.txt @@ -61,7 +61,7 @@ if (${ONION_POLLER} STREQUAL libev) LIST(APPEND LIBRARIES ${LIBEV_LIB}) endif (${ONION_POLLER} STREQUAL libev) if (SYSTEMD_ENABLED) - LIST(APPEND LIBRARIES ${SD_DAEMON_LIB}) + LIST(APPEND LIBRARIES ${SYSTEMD_LIBRARIES}) endif(SYSTEMD_ENABLED) From 09d8d19a0afc6328f52f07271ab6e8b130c2f489 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 11:38:52 +0530 Subject: [PATCH 12/51] Adds defination of different CMakeModules used --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65d4c097..b9297e1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,6 +200,7 @@ endif(MD2MAN) # defines if (GNUTLS_ENABLED) add_definitions(-DHAVE_GNUTLS) + add_definitions(${GNUTLS_DEFINITIONS}) endif(GNUTLS_ENABLED) if (PTHREADS) add_definitions(-DHAVE_PTHREADS) @@ -209,12 +210,15 @@ if (PAM_ENABLED) endif(PAM_ENABLED) if (XML2_ENABLED) add_definitions(-DHAVE_WEBDAV) + add_definitions(${LIBXML2_DEFINITIONS}) endif(XML2_ENABLED) if (SYSTEMD_ENABLED) add_definitions(-DHAVE_SYSTEMD) + add_definitions(${SYSTEMD_DEFINITIONS}) endif (SYSTEMD_ENABLED) if (SQLITE3_ENABLED) add_definitions(-DHAVE_SQLITE3) + add_definitions(${SQLITE3_DEFINITIONS}) endif (SQLITE3_ENABLED) if (REDIS_ENABLED) add_definitions(-DHAVE_REDIS) @@ -225,6 +229,7 @@ add_definitions(-D_POSIX_C_SOURCE=200112L) add_definitions(-D_ISOC99_SOURCE) if(PNG_ENABLED) add_definitions(-DPNG_ENABLED) + add_definitions(${PNG_DEFINITIONS}) endif(PNG_ENABLED) if(JPEG_ENABLED) add_definitions(-DJPEG_ENABLED) From bc1e358b0403df29d3d83fa9a04cd64f460227ff Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 12:21:04 +0530 Subject: [PATCH 13/51] Adds Bohem GC CMake Module and uses it --- CMakeLists.txt | 13 ++-- CMakeModules/FindBohemGC.cmake | 108 +++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 CMakeModules/FindBohemGC.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b9297e1e..4733fbd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,14 +160,13 @@ if (${ONION_USE_JPEG}) endif (${ONION_USE_JPEG}) if (${ONION_USE_GC}) - find_library(GC_LIB NAMES gc PATH ${LIBPATH}) - find_file(GC_HEADER gc.h ${INCLUDE_PATH}) - if (GC_LIB AND GC_HEADER) - message(STATUS "libgc found, compiling Boehm GC examples") + find_package(BohemGC) + if (BOEHM_GC_FOUND) + message(STATUS "compiling Boehm GC examples") set(GC_ENABLED true) - else (GC_LIB AND GC_HEADER) - message(STATUS "libgc not found, NOT compiling Boehm GC examples") - endif (GC_LIB AND GC_HEADER) + else (BOEHM_GC_FOUND) + message(STATUS "NOT compiling Boehm GC examples") + endif (BOEHM_GC_FOUND) endif (${ONION_USE_GC}) diff --git a/CMakeModules/FindBohemGC.cmake b/CMakeModules/FindBohemGC.cmake new file mode 100644 index 00000000..a5082b0c --- /dev/null +++ b/CMakeModules/FindBohemGC.cmake @@ -0,0 +1,108 @@ +# - Try to find Cairo +# Once done, this will define +# +# BOEHM_GC_FOUND - system has Cairo +# BOEHM_GC_INCLUDE_DIR - the Bohem GC include directories +# BOEHM_GC_LIBRARIES - link these to use Bohem GC +# +# Copyright (c) 2010-2015 Takashi Kato +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# $Id: $ +# + +# CMake module to find Boehm GC + +# use pkg-config if available +FIND_PACKAGE(PkgConfig) +PKG_CHECK_MODULES(PC_BDW_GC QUIET bdw-gc) + +# try newer one first in case of gc.h is overwritten. +FIND_PATH(BOEHM_GC_INCLUDE_DIR gc/gc.h + HINTS ${PC_BDW_GC_INCLUDEDIR} ${PC_BDW_GC_INCLUDE_DIRS}) + +IF (NOT BOEHM_GC_INCLUDE_DIR) + FIND_PATH(BOEHM_GC_INCLUDE_DIR gc.h + HINTS ${PC_BDW_GC_INCLUDEDIR} ${PC_BDW_GC_INCLUDE_DIRS}) + IF (BOEHM_GC_INCLUDE_DIR) + SET(HAVE_GC_H TRUE) + ENDIF() +ELSE() + SET(HAVE_GC_GC_H TRUE) +ENDIF() + +# For FreeBSD we need to use gc-threaded +IF (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") + # checks if 'gc' supports 'GC_get_parallel' and if it does + # then use it + INCLUDE(${CMAKE_ROOT}/Modules/CheckCSourceCompiles.cmake) + # not sure if this links properly... + FIND_LIBRARY(BOEHM_GC_LIBRARIES NAMES gc + HINTS ${PC_BDW_GC_LIBDIR} ${PC_BDW_GC_LIBRARY_DIRS}) + MESSAGE(STATUS "GC library ${BOEHM_GC_LIBRARIES}") + SET(CMAKE_REQUIRED_LIBRARIES "gc") + SET(CMAKE_REQUIRED_DEFINITIONS "-DGC_THREADS") + SET(CMAKE_REQUIRED_INCLUDES "${BOEHM_GC_INCLUDE_DIR}") + SET(CMAKE_REQUIRED_FLAGS "-L${PC_BDW_GC_LIBRARY_DIRS}") + MESSAGE(STATUS "Boehm GC include dir: ${CMAKE_REQUIRED_INCLUDES}") + CHECK_C_SOURCE_RUNS( + "#include +int main() { +int i= GC_get_parallel(); +return 0; +} +" GC_GET_PARALLEL_WORKS) + IF (NOT GC_GET_PARALLEL_WORKS) + MESSAGE(STATUS "Try gc-threaded") + + # bdw-gc-threaded is the proper name for FreeBSD pkg-config + PKG_CHECK_MODULES(PC_BDW_GC_THREADED bdw-gc-threaded) + FIND_LIBRARY(BOEHM_GC_THREADED_LIBRARIES NAMES gc-threaded + HINTS ${PC_BDW_GC_THREADED_LIBDIR} ${PC_BDW_GC_THREADED_THREADED_DIRS}) + + MESSAGE(STATUS "GC threaded library ${BOEHM_GC_THREADED_LIBRARIES}") + IF (BOEHM_GC_THREADED_LIBRARIES) + # OK just use it + SET(BOEHM_GC_LIBRARIES "${BOEHM_GC_THREADED_LIBRARIES}") + ENDIF() + ENDIF() +ELSE() + FIND_LIBRARY(BOEHM_GC_LIBRARIES NAMES gc + HINTS ${PC_BDW_GC_LIBDIR} ${PC_BDW_GC_LIBRARY_DIRS}) + # OpenSolaris uses bgc as Boehm GC runtime in its package manager. + # so try it + IF (NOT BOEHM_GC_LIBRARIES) + FIND_LIBRARY(BOEHM_GC_LIBRARIES NAMES bgc + HINTS ${PC_BDW_GC_LIBDIR} ${PC_BDW_GC_LIBRARY_DIRS}) + ENDIF() +ENDIF() + +MESSAGE(STATUS "Found GC library: ${BOEHM_GC_LIBRARIES}") + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Boehm_GC DEFAULT_MSG + BOEHM_GC_LIBRARIES BOEHM_GC_INCLUDE_DIR) + +MARK_AS_ADVANCED(BOEHM_GC_LIBRARIES BOEHM_GC_INCLUDE_DIR) From 45ed577812ba2450794567488a1fc2af6565617a Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 12:40:17 +0530 Subject: [PATCH 14/51] Uses Intl CMakeModule for GetText --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e97beaa..1227ed31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -198,13 +198,13 @@ if (${ONION_USE_SYSTEMD}) endif(SYSTEMD_FOUND) endif(${ONION_USE_SYSTEMD}) -find_library(GETTEXT_LIB NAMES gettext PATH ${LIBPATH}) -if (GETTEXT_LIB) +find_package(Intl) +if (Intl_FOUND) set(GETTEXT_ENABLED true) - message(STATUS "gettext found. gettext support is compiled in otemplate.") -else (GETTEXT_LIB) - message(STATUS "gettext not found. No gettext support.") -endif (GETTEXT_LIB) + message(STATUS "gettext support is compiled in otemplate.") +else (Intl_FOUND) + message(STATUS "No gettext support.") +endif (Intl_FOUND) FIND_PROGRAM(MD2MAN md2man-roff) if(MD2MAN) From e06346c757dc99a492a63764eae12741f66cf727 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 13:11:32 +0530 Subject: [PATCH 15/51] Fixes #194, removes pam_misc --- CMakeLists.txt | 2 +- src/onion/CMakeLists.txt | 2 +- src/onion/handlers/auth_pam.c | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index da0c7fe2..36334749 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,7 +125,7 @@ if (${ONION_USE_XML2}) endif(${ONION_USE_XML2}) if (${ONION_USE_PAM}) - find_library(PAM_LIB NAMES pam pam_misc PATH ${LIBPATH}) + find_library(PAM_LIB NAMES pam PATH ${LIBPATH}) if (PAM_LIB) set(PAM_ENABLED true) message(STATUS "pam found. PAM support is compiled in in handlers.") diff --git a/src/onion/CMakeLists.txt b/src/onion/CMakeLists.txt index c8322897..e486382b 100644 --- a/src/onion/CMakeLists.txt +++ b/src/onion/CMakeLists.txt @@ -40,7 +40,7 @@ if (${XML2_ENABLED}) endif (${XML2_ENABLED}) if (${PAM_ENABLED}) LIST(APPEND SOURCES handlers/auth_pam.c) - LIST(APPEND LIBRARIES pam pam_misc) + LIST(APPEND LIBRARIES pam) endif (${PAM_ENABLED}) if (GNUTLS_ENABLED) LIST(APPEND LIBRARIES gcrypt gnutls) diff --git a/src/onion/handlers/auth_pam.c b/src/onion/handlers/auth_pam.c index ba367532..97477e67 100644 --- a/src/onion/handlers/auth_pam.c +++ b/src/onion/handlers/auth_pam.c @@ -26,7 +26,6 @@ #include #include -#include #include #include From d59e298d16c9fbc917a303d91da477b74ab5c1a8 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 13:19:26 +0530 Subject: [PATCH 16/51] Fixes #195, Removes dependency of PNG for Cairo --- CMakeLists.txt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 36334749..df91d0a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,20 +140,21 @@ if (${ONION_USE_PNG}) set(PNG_ENABLED true) set(PNG_LIB ${PNG_LIB}) message(STATUS "libpng found. png support is compiled in at extras.") - find_library(CAIRO_LIB NAMES cairo PATH ${LIBPATH}) - find_file(CAIRO_HEADER cairo/cairo.h ${INCLUDE_PATH}) - if (CAIRO_HEADER) - set(CAIRO_ENABLED true) - set(CAIRO_LIB ${CAIRO_LIB}) - message(STATUS "libcairo found. Adding cairo examples. ${CAIRO_LIB}") - else (CAIRO_HEADER) - message(STATUS "libcairo NOT found.") - endif (CAIRO_HEADER) else (PNG_LIB) message("libpng not found. No png support.") endif (PNG_LIB) endif (${ONION_USE_PNG}) +find_library(CAIRO_LIB NAMES cairo PATH ${LIBPATH}) +find_file(CAIRO_HEADER cairo/cairo.h ${INCLUDE_PATH}) +if (CAIRO_HEADER) + set(CAIRO_ENABLED true) + set(CAIRO_LIB ${CAIRO_LIB}) + message(STATUS "libcairo found. Adding cairo examples. ${CAIRO_LIB}") +else (CAIRO_HEADER) + message(STATUS "libcairo NOT found.") +endif (CAIRO_HEADER) + if (${ONION_USE_JPEG}) find_library(JPEG_LIB NAMES jpeg PATH ${LIBPATH}) if (JPEG_LIB) From cd4a5d64acd5557fc6912e13d1fb4e401a27dbbd Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 13:33:33 +0530 Subject: [PATCH 17/51] Adds PAM CMake Module and uses it --- CMakeLists.txt | 12 +++---- CMakeModules/FindPAM.cmake | 71 ++++++++++++++++++++++++++++++++++++++ src/onion/CMakeLists.txt | 2 +- 3 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 CMakeModules/FindPAM.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 32a87fb8..97fd69cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,13 +125,13 @@ if (${ONION_USE_XML2}) endif(${ONION_USE_XML2}) if (${ONION_USE_PAM}) - find_library(PAM_LIB NAMES pam PATH ${LIBPATH}) - if (PAM_LIB) + find_package(PAM) + if (PAM_FOUND) set(PAM_ENABLED true) - message(STATUS "pam found. PAM support is compiled in in handlers.") - else (PAM_LIB) - message("pam not found. No PAM support.") - endif (PAM_LIB) + message(STATUS "PAM support is compiled in handlers.") + else (PAM_FOUND) + message("No PAM support.") + endif (PAM_FOUND) endif (${ONION_USE_PAM}) if (${ONION_USE_PNG}) diff --git a/CMakeModules/FindPAM.cmake b/CMakeModules/FindPAM.cmake new file mode 100644 index 00000000..25307bd3 --- /dev/null +++ b/CMakeModules/FindPAM.cmake @@ -0,0 +1,71 @@ +# - Try to find the PAM libraries +# Once done this will define +# +# PAM_FOUND - system has pam +# PAM_INCLUDE_DIR - the pam include directory +# PAM_LIBRARIES - libpam library + +if (PAM_INCLUDE_DIR AND PAM_LIBRARY) + # Already in cache, be silent + set(PAM_FIND_QUIETLY TRUE) +endif (PAM_INCLUDE_DIR AND PAM_LIBRARY) + +find_path(PAM_INCLUDE_DIR NAMES security/pam_appl.h pam/pam_appl.h) +find_library(PAM_LIBRARY pam) +find_library(DL_LIBRARY dl) + +if (PAM_INCLUDE_DIR AND PAM_LIBRARY) + set(PAM_FOUND TRUE) + if (DL_LIBRARY) + set(PAM_LIBRARIES ${PAM_LIBRARY} ${DL_LIBRARY}) + else (DL_LIBRARY) + set(PAM_LIBRARIES ${PAM_LIBRARY}) + endif (DL_LIBRARY) + + if (EXISTS ${PAM_INCLUDE_DIR}/pam/pam_appl.h) + # darwin claims to be something special + set(HAVE_PAM_PAM_APPL_H 1) + endif (EXISTS ${PAM_INCLUDE_DIR}/pam/pam_appl.h) + + if (NOT DEFINED PAM_MESSAGE_CONST) + include(CheckCXXSourceCompiles) + # XXX does this work with plain c? + check_cxx_source_compiles(" +#if ${HAVE_PAM_PAM_APPL_H}+0 +# include +#else +# include +#endif +static int PAM_conv( + int num_msg, + const struct pam_message **msg, /* this is the culprit */ + struct pam_response **resp, + void *ctx) +{ + return 0; +} +int main(void) +{ + struct pam_conv PAM_conversation = { + &PAM_conv, /* this bombs out if the above does not match */ + 0 + }; + return 0; +} +" PAM_MESSAGE_CONST) + endif (NOT DEFINED PAM_MESSAGE_CONST) + set(PAM_MESSAGE_CONST ${PAM_MESSAGE_CONST} CACHE BOOL "PAM expects a conversation function with const pam_message") + +endif (PAM_INCLUDE_DIR AND PAM_LIBRARY) + +if (PAM_FOUND) + if (NOT PAM_FIND_QUIETLY) + message(STATUS "Found PAM: ${PAM_LIBRARIES}") + endif (NOT PAM_FIND_QUIETLY) +else (PAM_FOUND) + if (PAM_FIND_REQUIRED) + message(FATAL_ERROR "PAM was not found") + endif(PAM_FIND_REQUIRED) +endif (PAM_FOUND) + +mark_as_advanced(PAM_INCLUDE_DIR PAM_LIBRARY DL_LIBRARY PAM_MESSAGE_CONST) diff --git a/src/onion/CMakeLists.txt b/src/onion/CMakeLists.txt index ee68eb49..82c08e65 100644 --- a/src/onion/CMakeLists.txt +++ b/src/onion/CMakeLists.txt @@ -40,7 +40,7 @@ if (${XML2_ENABLED}) endif (${XML2_ENABLED}) if (${PAM_ENABLED}) LIST(APPEND SOURCES handlers/auth_pam.c) - LIST(APPEND LIBRARIES pam) + LIST(APPEND LIBRARIES ${PAM_LIBRARY}) endif (${PAM_ENABLED}) if (GNUTLS_ENABLED) LIST(APPEND LIBRARIES ${GCRYPT_LIBRARIES} ${GNUTLS_LIBRARIES}) From 8575ea39878e8652b65db2001515f036781897a3 Mon Sep 17 00:00:00 2001 From: David Moreno Date: Wed, 17 Aug 2016 11:20:10 +0200 Subject: [PATCH 18/51] Added missing Find*.cmake files. Also updated find package names at main to use proper case sensitivity required in Linux. The new Find*.cmake files are required at least in Fedora; other distros, and Mac OSX may have them system wide. Anyway this way they are always available. --- CMakeLists.txt | 4 +- CMakeModules/CMakeParseArguments.cmake | 21 + CMakeModules/FindGnuTLS.cmake | 77 ++++ CMakeModules/FindLibXml2.cmake | 73 ++++ .../FindPackageHandleStandardArgs.cmake | 396 ++++++++++++++++++ CMakeModules/FindPackageMessage.cmake | 57 +++ 6 files changed, 626 insertions(+), 2 deletions(-) create mode 100644 CMakeModules/CMakeParseArguments.cmake create mode 100644 CMakeModules/FindGnuTLS.cmake create mode 100644 CMakeModules/FindLibXml2.cmake create mode 100644 CMakeModules/FindPackageHandleStandardArgs.cmake create mode 100644 CMakeModules/FindPackageMessage.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 4733fbd1..e1248b73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,7 +74,7 @@ message(STATUS "Using ${ONION_POLLER} as poller") if (${ONION_USE_SSL}) - find_package(GNUTLS) + find_package(GnuTLS) find_package(GCrypt) if (GNUTLS_FOUND AND GCRYPT_FOUND) set(GNUTLS_ENABLED true) @@ -115,7 +115,7 @@ if (${ONION_USE_PTHREADS}) endif(${ONION_USE_PTHREADS}) if (${ONION_USE_XML2}) - find_package(LIBXML2) + find_package(LibXml2) if(LIBXML2_FOUND) message(STATUS "WebDAV support is compiled in.") set(XML2_ENABLED true) diff --git a/CMakeModules/CMakeParseArguments.cmake b/CMakeModules/CMakeParseArguments.cmake new file mode 100644 index 00000000..fc64ab9a --- /dev/null +++ b/CMakeModules/CMakeParseArguments.cmake @@ -0,0 +1,21 @@ +#.rst: +# CMakeParseArguments +# ------------------- +# +# This module once implemented the :command:`cmake_parse_arguments` command +# that is now implemented natively by CMake. It is now an empty placeholder +# for compatibility with projects that include it to get the command from +# CMake 3.4 and lower. + +#============================================================================= +# Copyright 2010 Alexander Neundorf +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) diff --git a/CMakeModules/FindGnuTLS.cmake b/CMakeModules/FindGnuTLS.cmake new file mode 100644 index 00000000..4d94ffc5 --- /dev/null +++ b/CMakeModules/FindGnuTLS.cmake @@ -0,0 +1,77 @@ +#.rst: +# FindGnuTLS +# ---------- +# +# Try to find the GNU Transport Layer Security library (gnutls) +# +# +# +# Once done this will define +# +# :: +# +# GNUTLS_FOUND - System has gnutls +# GNUTLS_INCLUDE_DIR - The gnutls include directory +# GNUTLS_LIBRARIES - The libraries needed to use gnutls +# GNUTLS_DEFINITIONS - Compiler switches required for using gnutls + +#============================================================================= +# Copyright 2009 Kitware, Inc. +# Copyright 2009 Philip Lowman +# Copyright 2009 Brad Hards +# Copyright 2006 Alexander Neundorf +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# Note that this doesn't try to find the gnutls-extra package. + + +if (GNUTLS_INCLUDE_DIR AND GNUTLS_LIBRARY) + # in cache already + set(gnutls_FIND_QUIETLY TRUE) +endif () + +if (NOT WIN32) + # try using pkg-config to get the directories and then use these values + # in the find_path() and find_library() calls + # also fills in GNUTLS_DEFINITIONS, although that isn't normally useful + find_package(PkgConfig QUIET) + PKG_CHECK_MODULES(PC_GNUTLS QUIET gnutls) + set(GNUTLS_DEFINITIONS ${PC_GNUTLS_CFLAGS_OTHER}) + set(GNUTLS_VERSION_STRING ${PC_GNUTLS_VERSION}) +endif () + +find_path(GNUTLS_INCLUDE_DIR gnutls/gnutls.h + HINTS + ${PC_GNUTLS_INCLUDEDIR} + ${PC_GNUTLS_INCLUDE_DIRS} + ) + +find_library(GNUTLS_LIBRARY NAMES gnutls libgnutls + HINTS + ${PC_GNUTLS_LIBDIR} + ${PC_GNUTLS_LIBRARY_DIRS} + ) + +mark_as_advanced(GNUTLS_INCLUDE_DIR GNUTLS_LIBRARY) + +# handle the QUIETLY and REQUIRED arguments and set GNUTLS_FOUND to TRUE if +# all listed variables are TRUE +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GnuTLS + REQUIRED_VARS GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR + VERSION_VAR GNUTLS_VERSION_STRING) + +if(GNUTLS_FOUND) + set(GNUTLS_LIBRARIES ${GNUTLS_LIBRARY}) + set(GNUTLS_INCLUDE_DIRS ${GNUTLS_INCLUDE_DIR}) +endif() + diff --git a/CMakeModules/FindLibXml2.cmake b/CMakeModules/FindLibXml2.cmake new file mode 100644 index 00000000..73224286 --- /dev/null +++ b/CMakeModules/FindLibXml2.cmake @@ -0,0 +1,73 @@ +#.rst: +# FindLibXml2 +# ----------- +# +# Try to find the LibXml2 xml processing library +# +# Once done this will define +# +# :: +# +# LIBXML2_FOUND - System has LibXml2 +# LIBXML2_INCLUDE_DIR - The LibXml2 include directory +# LIBXML2_LIBRARIES - The libraries needed to use LibXml2 +# LIBXML2_DEFINITIONS - Compiler switches required for using LibXml2 +# LIBXML2_XMLLINT_EXECUTABLE - The XML checking tool xmllint coming with LibXml2 +# LIBXML2_VERSION_STRING - the version of LibXml2 found (since CMake 2.8.8) + +#============================================================================= +# Copyright 2006-2009 Kitware, Inc. +# Copyright 2006 Alexander Neundorf +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# use pkg-config to get the directories and then use these values +# in the find_path() and find_library() calls +find_package(PkgConfig QUIET) +PKG_CHECK_MODULES(PC_LIBXML QUIET libxml-2.0) +set(LIBXML2_DEFINITIONS ${PC_LIBXML_CFLAGS_OTHER}) + +find_path(LIBXML2_INCLUDE_DIR NAMES libxml/xpath.h + HINTS + ${PC_LIBXML_INCLUDEDIR} + ${PC_LIBXML_INCLUDE_DIRS} + PATH_SUFFIXES libxml2 + ) + +find_library(LIBXML2_LIBRARIES NAMES xml2 libxml2 + HINTS + ${PC_LIBXML_LIBDIR} + ${PC_LIBXML_LIBRARY_DIRS} + ) + +find_program(LIBXML2_XMLLINT_EXECUTABLE xmllint) +# for backwards compat. with KDE 4.0.x: +set(XMLLINT_EXECUTABLE "${LIBXML2_XMLLINT_EXECUTABLE}") + +if(PC_LIBXML_VERSION) + set(LIBXML2_VERSION_STRING ${PC_LIBXML_VERSION}) +elseif(LIBXML2_INCLUDE_DIR AND EXISTS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h") + file(STRINGS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h" libxml2_version_str + REGEX "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\".*\"") + + string(REGEX REPLACE "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\"([^\"]*)\".*" "\\1" + LIBXML2_VERSION_STRING "${libxml2_version_str}") + unset(libxml2_version_str) +endif() + +# handle the QUIETLY and REQUIRED arguments and set LIBXML2_FOUND to TRUE if +# all listed variables are TRUE +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 + REQUIRED_VARS LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR + VERSION_VAR LIBXML2_VERSION_STRING) + +mark_as_advanced(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARIES LIBXML2_XMLLINT_EXECUTABLE) diff --git a/CMakeModules/FindPackageHandleStandardArgs.cmake b/CMakeModules/FindPackageHandleStandardArgs.cmake new file mode 100644 index 00000000..fe2dbeaa --- /dev/null +++ b/CMakeModules/FindPackageHandleStandardArgs.cmake @@ -0,0 +1,396 @@ +#[=======================================================================[.rst: +FindPackageHandleStandardArgs +----------------------------- + +This module provides a function intended to be used in :ref:`Find Modules` +implementing :command:`find_package()` calls. It handles the +``REQUIRED``, ``QUIET`` and version-related arguments of ``find_package``. +It also sets the ``_FOUND`` variable. The package is +considered found if all variables listed contain valid results, e.g. +valid filepaths. + +.. command:: find_package_handle_standard_args + + There are two signatures:: + + find_package_handle_standard_args( + (DEFAULT_MSG|) + ... + ) + + find_package_handle_standard_args( + [FOUND_VAR ] + [REQUIRED_VARS ...] + [VERSION_VAR ] + [HANDLE_COMPONENTS] + [CONFIG_MODE] + [FAIL_MESSAGE ] + ) + + The ``_FOUND`` variable will be set to ``TRUE`` if all + the variables ``...`` are valid and any optional + constraints are satisfied, and ``FALSE`` otherwise. A success or + failure message may be displayed based on the results and on + whether the ``REQUIRED`` and/or ``QUIET`` option was given to + the :command:`find_package` call. + + The options are: + + ``(DEFAULT_MSG|)`` + In the simple signature this specifies the failure message. + Use ``DEFAULT_MSG`` to ask for a default message to be computed + (recommended). Not valid in the full signature. + + ``FOUND_VAR `` + Obsolete. Specifies either ``_FOUND`` or + ``_FOUND`` as the result variable. This exists only + for compatibility with older versions of CMake and is now ignored. + Result variables of both names are always set for compatibility. + + ``REQUIRED_VARS ...`` + Specify the variables which are required for this package. + These may be named in the generated failure message asking the + user to set the missing variable values. Therefore these should + typically be cache entries such as ``FOO_LIBRARY`` and not output + variables like ``FOO_LIBRARIES``. + + ``VERSION_VAR `` + Specify the name of a variable that holds the version of the package + that has been found. This version will be checked against the + (potentially) specified required version given to the + :command:`find_package` call, including its ``EXACT`` option. + The default messages include information about the required + version and the version which has been actually found, both + if the version is ok or not. + + ``HANDLE_COMPONENTS`` + Enable handling of package components. In this case, the command + will report which components have been found and which are missing, + and the ``_FOUND`` variable will be set to ``FALSE`` + if any of the required components (i.e. not the ones listed after + the ``OPTIONAL_COMPONENTS`` option of :command:`find_package`) are + missing. + + ``CONFIG_MODE`` + Specify that the calling find module is a wrapper around a + call to ``find_package( NO_MODULE)``. This implies + a ``VERSION_VAR`` value of ``_VERSION``. The command + will automatically check whether the package configuration file + was found. + + ``FAIL_MESSAGE `` + Specify a custom failure message instead of using the default + generated message. Not recommended. + +Example for the simple signature: + +.. code-block:: cmake + + find_package_handle_standard_args(LibXml2 DEFAULT_MSG + LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR) + +The ``LibXml2`` package is considered to be found if both +``LIBXML2_LIBRARY`` and ``LIBXML2_INCLUDE_DIR`` are valid. +Then also ``LibXml2_FOUND`` is set to ``TRUE``. If it is not found +and ``REQUIRED`` was used, it fails with a +:command:`message(FATAL_ERROR)`, independent whether ``QUIET`` was +used or not. If it is found, success will be reported, including +the content of the first ````. On repeated CMake runs, +the same message will not be printed again. + +Example for the full signature: + +.. code-block:: cmake + + find_package_handle_standard_args(LibArchive + REQUIRED_VARS LibArchive_LIBRARY LibArchive_INCLUDE_DIR + VERSION_VAR LibArchive_VERSION) + +In this case, the ``LibArchive`` package is considered to be found if +both ``LibArchive_LIBRARY`` and ``LibArchive_INCLUDE_DIR`` are valid. +Also the version of ``LibArchive`` will be checked by using the version +contained in ``LibArchive_VERSION``. Since no ``FAIL_MESSAGE`` is given, +the default messages will be printed. + +Another example for the full signature: + +.. code-block:: cmake + + find_package(Automoc4 QUIET NO_MODULE HINTS /opt/automoc4) + find_package_handle_standard_args(Automoc4 CONFIG_MODE) + +In this case, a ``FindAutmoc4.cmake`` module wraps a call to +``find_package(Automoc4 NO_MODULE)`` and adds an additional search +directory for ``automoc4``. Then the call to +``find_package_handle_standard_args`` produces a proper success/failure +message. +#]=======================================================================] + +#============================================================================= +# Copyright 2007-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageMessage.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake) + +# internal helper macro +macro(_FPHSA_FAILURE_MESSAGE _msg) + if (${_NAME}_FIND_REQUIRED) + message(FATAL_ERROR "${_msg}") + else () + if (NOT ${_NAME}_FIND_QUIETLY) + message(STATUS "${_msg}") + endif () + endif () +endmacro() + + +# internal helper macro to generate the failure message when used in CONFIG_MODE: +macro(_FPHSA_HANDLE_FAILURE_CONFIG_MODE) + # _CONFIG is set, but FOUND is false, this means that some other of the REQUIRED_VARS was not found: + if(${_NAME}_CONFIG) + _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: missing: ${MISSING_VARS} (found ${${_NAME}_CONFIG} ${VERSION_MSG})") + else() + # If _CONSIDERED_CONFIGS is set, the config-file has been found, but no suitable version. + # List them all in the error message: + if(${_NAME}_CONSIDERED_CONFIGS) + set(configsText "") + list(LENGTH ${_NAME}_CONSIDERED_CONFIGS configsCount) + math(EXPR configsCount "${configsCount} - 1") + foreach(currentConfigIndex RANGE ${configsCount}) + list(GET ${_NAME}_CONSIDERED_CONFIGS ${currentConfigIndex} filename) + list(GET ${_NAME}_CONSIDERED_VERSIONS ${currentConfigIndex} version) + set(configsText "${configsText} ${filename} (version ${version})\n") + endforeach() + if (${_NAME}_NOT_FOUND_MESSAGE) + set(configsText "${configsText} Reason given by package: ${${_NAME}_NOT_FOUND_MESSAGE}\n") + endif() + _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} ${VERSION_MSG}, checked the following files:\n${configsText}") + + else() + # Simple case: No Config-file was found at all: + _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: found neither ${_NAME}Config.cmake nor ${_NAME_LOWER}-config.cmake ${VERSION_MSG}") + endif() + endif() +endmacro() + + +function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) + +# set up the arguments for CMAKE_PARSE_ARGUMENTS and check whether we are in +# new extended or in the "old" mode: + set(options CONFIG_MODE HANDLE_COMPONENTS) + set(oneValueArgs FAIL_MESSAGE VERSION_VAR FOUND_VAR) + set(multiValueArgs REQUIRED_VARS) + set(_KEYWORDS_FOR_EXTENDED_MODE ${options} ${oneValueArgs} ${multiValueArgs} ) + list(FIND _KEYWORDS_FOR_EXTENDED_MODE "${_FIRST_ARG}" INDEX) + + if(${INDEX} EQUAL -1) + set(FPHSA_FAIL_MESSAGE ${_FIRST_ARG}) + set(FPHSA_REQUIRED_VARS ${ARGN}) + set(FPHSA_VERSION_VAR) + else() + + CMAKE_PARSE_ARGUMENTS(FPHSA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN}) + + if(FPHSA_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "Unknown keywords given to FIND_PACKAGE_HANDLE_STANDARD_ARGS(): \"${FPHSA_UNPARSED_ARGUMENTS}\"") + endif() + + if(NOT FPHSA_FAIL_MESSAGE) + set(FPHSA_FAIL_MESSAGE "DEFAULT_MSG") + endif() + endif() + +# now that we collected all arguments, process them + + if("x${FPHSA_FAIL_MESSAGE}" STREQUAL "xDEFAULT_MSG") + set(FPHSA_FAIL_MESSAGE "Could NOT find ${_NAME}") + endif() + + # In config-mode, we rely on the variable _CONFIG, which is set by find_package() + # when it successfully found the config-file, including version checking: + if(FPHSA_CONFIG_MODE) + list(INSERT FPHSA_REQUIRED_VARS 0 ${_NAME}_CONFIG) + list(REMOVE_DUPLICATES FPHSA_REQUIRED_VARS) + set(FPHSA_VERSION_VAR ${_NAME}_VERSION) + endif() + + if(NOT FPHSA_REQUIRED_VARS) + message(FATAL_ERROR "No REQUIRED_VARS specified for FIND_PACKAGE_HANDLE_STANDARD_ARGS()") + endif() + + list(GET FPHSA_REQUIRED_VARS 0 _FIRST_REQUIRED_VAR) + + string(TOUPPER ${_NAME} _NAME_UPPER) + string(TOLOWER ${_NAME} _NAME_LOWER) + + if(FPHSA_FOUND_VAR) + if(FPHSA_FOUND_VAR MATCHES "^${_NAME}_FOUND$" OR FPHSA_FOUND_VAR MATCHES "^${_NAME_UPPER}_FOUND$") + set(_FOUND_VAR ${FPHSA_FOUND_VAR}) + else() + message(FATAL_ERROR "The argument for FOUND_VAR is \"${FPHSA_FOUND_VAR}\", but only \"${_NAME}_FOUND\" and \"${_NAME_UPPER}_FOUND\" are valid names.") + endif() + else() + set(_FOUND_VAR ${_NAME_UPPER}_FOUND) + endif() + + # collect all variables which were not found, so they can be printed, so the + # user knows better what went wrong (#6375) + set(MISSING_VARS "") + set(DETAILS "") + # check if all passed variables are valid + set(FPHSA_FOUND_${_NAME} TRUE) + foreach(_CURRENT_VAR ${FPHSA_REQUIRED_VARS}) + if(NOT ${_CURRENT_VAR}) + set(FPHSA_FOUND_${_NAME} FALSE) + set(MISSING_VARS "${MISSING_VARS} ${_CURRENT_VAR}") + else() + set(DETAILS "${DETAILS}[${${_CURRENT_VAR}}]") + endif() + endforeach() + if(FPHSA_FOUND_${_NAME}) + set(${_NAME}_FOUND TRUE) + set(${_NAME_UPPER}_FOUND TRUE) + else() + set(${_NAME}_FOUND FALSE) + set(${_NAME_UPPER}_FOUND FALSE) + endif() + + # component handling + unset(FOUND_COMPONENTS_MSG) + unset(MISSING_COMPONENTS_MSG) + + if(FPHSA_HANDLE_COMPONENTS) + foreach(comp ${${_NAME}_FIND_COMPONENTS}) + if(${_NAME}_${comp}_FOUND) + + if(NOT DEFINED FOUND_COMPONENTS_MSG) + set(FOUND_COMPONENTS_MSG "found components: ") + endif() + set(FOUND_COMPONENTS_MSG "${FOUND_COMPONENTS_MSG} ${comp}") + + else() + + if(NOT DEFINED MISSING_COMPONENTS_MSG) + set(MISSING_COMPONENTS_MSG "missing components: ") + endif() + set(MISSING_COMPONENTS_MSG "${MISSING_COMPONENTS_MSG} ${comp}") + + if(${_NAME}_FIND_REQUIRED_${comp}) + set(${_NAME}_FOUND FALSE) + set(MISSING_VARS "${MISSING_VARS} ${comp}") + endif() + + endif() + endforeach() + set(COMPONENT_MSG "${FOUND_COMPONENTS_MSG} ${MISSING_COMPONENTS_MSG}") + set(DETAILS "${DETAILS}[c${COMPONENT_MSG}]") + endif() + + # version handling: + set(VERSION_MSG "") + set(VERSION_OK TRUE) + set(VERSION ${${FPHSA_VERSION_VAR}}) + + # check with DEFINED here as the requested or found version may be "0" + if (DEFINED ${_NAME}_FIND_VERSION) + if(DEFINED ${FPHSA_VERSION_VAR}) + + if(${_NAME}_FIND_VERSION_EXACT) # exact version required + # count the dots in the version string + string(REGEX REPLACE "[^.]" "" _VERSION_DOTS "${VERSION}") + # add one dot because there is one dot more than there are components + string(LENGTH "${_VERSION_DOTS}." _VERSION_DOTS) + if (_VERSION_DOTS GREATER ${_NAME}_FIND_VERSION_COUNT) + # Because of the C++ implementation of find_package() ${_NAME}_FIND_VERSION_COUNT + # is at most 4 here. Therefore a simple lookup table is used. + if (${_NAME}_FIND_VERSION_COUNT EQUAL 1) + set(_VERSION_REGEX "[^.]*") + elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 2) + set(_VERSION_REGEX "[^.]*\\.[^.]*") + elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 3) + set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*") + else () + set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*\\.[^.]*") + endif () + string(REGEX REPLACE "^(${_VERSION_REGEX})\\..*" "\\1" _VERSION_HEAD "${VERSION}") + unset(_VERSION_REGEX) + if (NOT ${_NAME}_FIND_VERSION VERSION_EQUAL _VERSION_HEAD) + set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"") + set(VERSION_OK FALSE) + else () + set(VERSION_MSG "(found suitable exact version \"${VERSION}\")") + endif () + unset(_VERSION_HEAD) + else () + if (NOT ${_NAME}_FIND_VERSION VERSION_EQUAL VERSION) + set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"") + set(VERSION_OK FALSE) + else () + set(VERSION_MSG "(found suitable exact version \"${VERSION}\")") + endif () + endif () + unset(_VERSION_DOTS) + + else() # minimum version specified: + if (${_NAME}_FIND_VERSION VERSION_GREATER VERSION) + set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is at least \"${${_NAME}_FIND_VERSION}\"") + set(VERSION_OK FALSE) + else () + set(VERSION_MSG "(found suitable version \"${VERSION}\", minimum required is \"${${_NAME}_FIND_VERSION}\")") + endif () + endif() + + else() + + # if the package was not found, but a version was given, add that to the output: + if(${_NAME}_FIND_VERSION_EXACT) + set(VERSION_MSG "(Required is exact version \"${${_NAME}_FIND_VERSION}\")") + else() + set(VERSION_MSG "(Required is at least version \"${${_NAME}_FIND_VERSION}\")") + endif() + + endif() + else () + if(VERSION) + set(VERSION_MSG "(found version \"${VERSION}\")") + endif() + endif () + + if(VERSION_OK) + set(DETAILS "${DETAILS}[v${VERSION}(${${_NAME}_FIND_VERSION})]") + else() + set(${_NAME}_FOUND FALSE) + endif() + + + # print the result: + if (${_NAME}_FOUND) + FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG} ${COMPONENT_MSG}" "${DETAILS}") + else () + + if(FPHSA_CONFIG_MODE) + _FPHSA_HANDLE_FAILURE_CONFIG_MODE() + else() + if(NOT VERSION_OK) + _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_FIRST_REQUIRED_VAR}})") + else() + _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} (missing: ${MISSING_VARS}) ${VERSION_MSG}") + endif() + endif() + + endif () + + set(${_NAME}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE) + set(${_NAME_UPPER}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE) +endfunction() diff --git a/CMakeModules/FindPackageMessage.cmake b/CMakeModules/FindPackageMessage.cmake new file mode 100644 index 00000000..a0349d3d --- /dev/null +++ b/CMakeModules/FindPackageMessage.cmake @@ -0,0 +1,57 @@ +#.rst: +# FindPackageMessage +# ------------------ +# +# +# +# FIND_PACKAGE_MESSAGE( "message for user" "find result details") +# +# This macro is intended to be used in FindXXX.cmake modules files. It +# will print a message once for each unique find result. This is useful +# for telling the user where a package was found. The first argument +# specifies the name (XXX) of the package. The second argument +# specifies the message to display. The third argument lists details +# about the find result so that if they change the message will be +# displayed again. The macro also obeys the QUIET argument to the +# find_package command. +# +# Example: +# +# :: +# +# if(X11_FOUND) +# FIND_PACKAGE_MESSAGE(X11 "Found X11: ${X11_X11_LIB}" +# "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]") +# else() +# ... +# endif() + +#============================================================================= +# Copyright 2008-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +function(FIND_PACKAGE_MESSAGE pkg msg details) + # Avoid printing a message repeatedly for the same find result. + if(NOT ${pkg}_FIND_QUIETLY) + string(REPLACE "\n" "" details "${details}") + set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg}) + if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}") + # The message has not yet been printed. + message(STATUS "${msg}") + + # Save the find details in the cache to avoid printing the same + # message again. + set("${DETAILS_VAR}" "${details}" + CACHE INTERNAL "Details about finding ${pkg}") + endif() + endif() +endfunction() From ee5596235e9a96995f33e7b3d6819fec2e85600e Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 15:26:15 +0530 Subject: [PATCH 19/51] Adds LibEv CMake Module and uses it. Fixes #198 --- CMakeLists.txt | 30 +++++++++++++---------- CMakeModules/FindLibEv.cmake | 46 ++++++++++++++++++++++++++++++++++++ examples/otop/CMakeLists.txt | 2 +- src/onion/CMakeLists.txt | 36 +++++++++++----------------- 4 files changed, 78 insertions(+), 36 deletions(-) create mode 100644 CMakeModules/FindLibEv.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 97fd69cb..43ff7c3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,7 +72,6 @@ endif (${ONION_POLLER} STREQUAL "default") message(STATUS "Using ${ONION_POLLER} as poller") - if (${ONION_USE_SSL}) find_package(GNUTLS) find_package(GCrypt) @@ -125,30 +124,35 @@ if (${ONION_USE_XML2}) endif(${ONION_USE_XML2}) if (${ONION_USE_PAM}) - find_package(PAM) - if (PAM_FOUND) + find_library(PAM_LIB NAMES pam PATH ${LIBPATH}) + if (PAM_LIB) set(PAM_ENABLED true) - message(STATUS "PAM support is compiled in handlers.") - else (PAM_FOUND) - message("No PAM support.") - endif (PAM_FOUND) + message(STATUS "pam found. PAM support is compiled in in handlers.") + else (PAM_LIB) + message("pam not found. No PAM support.") + endif (PAM_LIB) endif (${ONION_USE_PAM}) if (${ONION_USE_PNG}) find_package(PNG) if (PNG_FOUND) set(PNG_ENABLED true) - message(STATUS "png support is compiled in at extras.") - else (PNG_FOUND) + set(PNG_LIB ${PNG_LIB}) + message(STATUS "libpng found. png support is compiled in at extras.") + else (PNG_LIB) message("libpng not found. No png support.") endif (PNG_FOUND) endif (${ONION_USE_PNG}) -find_package(Cairo) -if (CAIRO_FOUND) +find_library(CAIRO_LIB NAMES cairo PATH ${LIBPATH}) +find_file(CAIRO_HEADER cairo/cairo.h ${INCLUDE_PATH}) +if (CAIRO_HEADER) set(CAIRO_ENABLED true) - message(STATUS "Adding cairo examples.") -endif (CAIRO_FOUND) + set(CAIRO_LIB ${CAIRO_LIB}) + message(STATUS "libcairo found. Adding cairo examples. ${CAIRO_LIB}") +else (CAIRO_HEADER) + message(STATUS "libcairo NOT found.") +endif (CAIRO_HEADER) if (${ONION_USE_JPEG}) find_package(JPEG) diff --git a/CMakeModules/FindLibEv.cmake b/CMakeModules/FindLibEv.cmake new file mode 100644 index 00000000..712251c7 --- /dev/null +++ b/CMakeModules/FindLibEv.cmake @@ -0,0 +1,46 @@ +# - Try to find LibEv +# Once done this will define +# +# LIBEV_FOUND - system has libev +# LIBEV_INCLUDE_DIR - the libev include directory +# LIBEV_LIBRARIES - Link these to use libev +# + +set(_LIBEV_ROOT_HINTS + $ENV{GCRYTPT_ROOT_DIR} + ${LIBEV_ROOT_DIR}) + +set(_LIBEV_ROOT_PATHS + "$ENV{PROGRAMFILES}/libev") + +set(_LIBEV_ROOT_HINTS_AND_PATHS + HINTS ${_LIBEV_ROOT_HINTS} + PATHS ${_LIBEV_ROOT_PATHS}) + + +find_path(LIBEV_INCLUDE_DIR + NAMES + ev.h + HINTS + ${_LIBEV_ROOT_HINTS_AND_PATHS} +) + +find_library(LIBEV_LIBRARY + NAMES + ev + HINTS + ${_LIBEV_ROOT_HINTS_AND_PATHS} +) +set(LIBEV_LIBRARIES ${LIBEV_LIBRARY}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(LibEv + REQUIRED_VARS + LIBEV_INCLUDE_DIR + LIBEV_LIBRARIES + FAIL_MESSAGE + "Could NOT find LibEv, try to set the path to LibEv root folder in the system variable LIBEV_ROOT_DIR" +) + +# show the LIBEV_INCLUDE_DIRS and LIBEV_LIBRARIES variables only in the advanced view +mark_as_advanced(LIBEV_INCLUDE_DIR LIBEV_LIBRARIES) diff --git a/examples/otop/CMakeLists.txt b/examples/otop/CMakeLists.txt index 3c6b5f4c..7712a926 100644 --- a/examples/otop/CMakeLists.txt +++ b/examples/otop/CMakeLists.txt @@ -10,7 +10,7 @@ add_executable(otop otop.c otop_data.c) target_link_libraries(otop onion ) if(${ONION_POLLER} STREQUAL "libev") - target_link_libraries(otop -lev) + target_link_libraries(otop ${LIBEV_LIBRARIES}) endif() install(TARGETS otop DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/onion/CMakeLists.txt b/src/onion/CMakeLists.txt index 82c08e65..87e03d3f 100644 --- a/src/onion/CMakeLists.txt +++ b/src/onion/CMakeLists.txt @@ -17,6 +17,19 @@ LIST(APPEND LIBRARIES rt) ## optional add sources and libraries depeding on features +# Poller can be a bit more complex, but basically the same. +if (${ONION_POLLER} STREQUAL libevent) + LIST(APPEND SOURCES poller_libevent.c) +endif (${ONION_POLLER} STREQUAL libevent) +if (${ONION_POLLER} STREQUAL libev) + find_package(LibEv REQUIRED) + LIST(APPEND SOURCES poller_libev.c) + include_directories(${LIBEV_INCLUDE_DIR}) +endif (${ONION_POLLER} STREQUAL libev) +if (${ONION_POLLER} STREQUAL epoll) + LIST(APPEND SOURCES poller.c) +endif (${ONION_POLLER} STREQUAL epoll) + # library dependencies if (${SQLITE3_ENABLED}) LIST(APPEND SOURCES sessions_sqlite3.c) @@ -58,33 +71,12 @@ if (${ONION_POLLER} STREQUAL libevent) LIST(APPEND LIBRARIES event_core event_pthreads) endif (${ONION_POLLER} STREQUAL libevent) if (${ONION_POLLER} STREQUAL libev) - LIST(APPEND LIBRARIES ${LIBEV_LIB}) + LIST(APPEND LIBRARIES ${LIBEV_LIBRARIES}) endif (${ONION_POLLER} STREQUAL libev) if (SYSTEMD_ENABLED) LIST(APPEND LIBRARIES ${SYSTEMD_LIBRARIES}) endif(SYSTEMD_ENABLED) - -# Poller can be a bit more complex, but basically the same. -if (${ONION_POLLER} STREQUAL libevent) - LIST(APPEND SOURCES poller_libevent.c) -endif (${ONION_POLLER} STREQUAL libevent) -if (${ONION_POLLER} STREQUAL libev) - LIST(APPEND SOURCES poller_libev.c) - find_path(LIBEV_HEADER ev.h ${CMAKE_INCLUDE_PATH} /usr/local/include/) - find_library(LIBEV_LIB NAMES ev PATH /usr/local/lib/) - if (LIBEV_LIB) - message(STATUS "libev found at ${LIBEV_LIB}") - else (LIBEV_LIB) - message(FATAL_ERROR "libev not found. Cant compile. ${LIBEV_HEADER} ${LIBEV_LIB}") - endif (LIBEV_LIB) - include_directories(${LIBEV_HEADER}) -endif (${ONION_POLLER} STREQUAL libev) -if (${ONION_POLLER} STREQUAL epoll) - LIST(APPEND SOURCES poller.c) -endif (${ONION_POLLER} STREQUAL epoll) - - IF (${CMAKE_BUILD_TYPE} MATCHES "Fast") add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/all-onion.c From 6aac73c7c70ffc6551d8ee11886b32bdb1a5b066 Mon Sep 17 00:00:00 2001 From: David Moreno Date: Wed, 17 Aug 2016 12:05:42 +0200 Subject: [PATCH 20/51] Fix compile on ubuntu precise. Can use cmake 2.8 Reverted some Find*.cmake packages and use system wide others, so that it compiles on Ubuntu 12.04 Precise, the one we have set at Travis. Works ok on CMake 3.5.2 too (Fedora 24). --- CMakeModules/CMakeParseArguments.cmake | 21 - CMakeModules/FindGnuTLS.cmake | 18 +- .../FindPackageHandleStandardArgs.cmake | 538 +++++++----------- CMakeModules/FindPackageMessage.cmake | 57 -- 4 files changed, 206 insertions(+), 428 deletions(-) delete mode 100644 CMakeModules/CMakeParseArguments.cmake delete mode 100644 CMakeModules/FindPackageMessage.cmake diff --git a/CMakeModules/CMakeParseArguments.cmake b/CMakeModules/CMakeParseArguments.cmake deleted file mode 100644 index fc64ab9a..00000000 --- a/CMakeModules/CMakeParseArguments.cmake +++ /dev/null @@ -1,21 +0,0 @@ -#.rst: -# CMakeParseArguments -# ------------------- -# -# This module once implemented the :command:`cmake_parse_arguments` command -# that is now implemented natively by CMake. It is now an empty placeholder -# for compatibility with projects that include it to get the command from -# CMake 3.4 and lower. - -#============================================================================= -# Copyright 2010 Alexander Neundorf -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) diff --git a/CMakeModules/FindGnuTLS.cmake b/CMakeModules/FindGnuTLS.cmake index 4d94ffc5..7315f1dd 100644 --- a/CMakeModules/FindGnuTLS.cmake +++ b/CMakeModules/FindGnuTLS.cmake @@ -1,19 +1,11 @@ -#.rst: -# FindGnuTLS -# ---------- -# -# Try to find the GNU Transport Layer Security library (gnutls) -# -# +# - Try to find the GNU Transport Layer Security library (gnutls) # # Once done this will define # -# :: -# -# GNUTLS_FOUND - System has gnutls -# GNUTLS_INCLUDE_DIR - The gnutls include directory -# GNUTLS_LIBRARIES - The libraries needed to use gnutls -# GNUTLS_DEFINITIONS - Compiler switches required for using gnutls +# GNUTLS_FOUND - System has gnutls +# GNUTLS_INCLUDE_DIR - The gnutls include directory +# GNUTLS_LIBRARIES - The libraries needed to use gnutls +# GNUTLS_DEFINITIONS - Compiler switches required for using gnutls #============================================================================= # Copyright 2009 Kitware, Inc. diff --git a/CMakeModules/FindPackageHandleStandardArgs.cmake b/CMakeModules/FindPackageHandleStandardArgs.cmake index fe2dbeaa..1acb021e 100644 --- a/CMakeModules/FindPackageHandleStandardArgs.cmake +++ b/CMakeModules/FindPackageHandleStandardArgs.cmake @@ -1,130 +1,73 @@ -#[=======================================================================[.rst: -FindPackageHandleStandardArgs ------------------------------ - -This module provides a function intended to be used in :ref:`Find Modules` -implementing :command:`find_package()` calls. It handles the -``REQUIRED``, ``QUIET`` and version-related arguments of ``find_package``. -It also sets the ``_FOUND`` variable. The package is -considered found if all variables listed contain valid results, e.g. -valid filepaths. - -.. command:: find_package_handle_standard_args - - There are two signatures:: - - find_package_handle_standard_args( - (DEFAULT_MSG|) - ... - ) - - find_package_handle_standard_args( - [FOUND_VAR ] - [REQUIRED_VARS ...] - [VERSION_VAR ] - [HANDLE_COMPONENTS] - [CONFIG_MODE] - [FAIL_MESSAGE ] - ) - - The ``_FOUND`` variable will be set to ``TRUE`` if all - the variables ``...`` are valid and any optional - constraints are satisfied, and ``FALSE`` otherwise. A success or - failure message may be displayed based on the results and on - whether the ``REQUIRED`` and/or ``QUIET`` option was given to - the :command:`find_package` call. - - The options are: - - ``(DEFAULT_MSG|)`` - In the simple signature this specifies the failure message. - Use ``DEFAULT_MSG`` to ask for a default message to be computed - (recommended). Not valid in the full signature. - - ``FOUND_VAR `` - Obsolete. Specifies either ``_FOUND`` or - ``_FOUND`` as the result variable. This exists only - for compatibility with older versions of CMake and is now ignored. - Result variables of both names are always set for compatibility. - - ``REQUIRED_VARS ...`` - Specify the variables which are required for this package. - These may be named in the generated failure message asking the - user to set the missing variable values. Therefore these should - typically be cache entries such as ``FOO_LIBRARY`` and not output - variables like ``FOO_LIBRARIES``. - - ``VERSION_VAR `` - Specify the name of a variable that holds the version of the package - that has been found. This version will be checked against the - (potentially) specified required version given to the - :command:`find_package` call, including its ``EXACT`` option. - The default messages include information about the required - version and the version which has been actually found, both - if the version is ok or not. - - ``HANDLE_COMPONENTS`` - Enable handling of package components. In this case, the command - will report which components have been found and which are missing, - and the ``_FOUND`` variable will be set to ``FALSE`` - if any of the required components (i.e. not the ones listed after - the ``OPTIONAL_COMPONENTS`` option of :command:`find_package`) are - missing. - - ``CONFIG_MODE`` - Specify that the calling find module is a wrapper around a - call to ``find_package( NO_MODULE)``. This implies - a ``VERSION_VAR`` value of ``_VERSION``. The command - will automatically check whether the package configuration file - was found. - - ``FAIL_MESSAGE `` - Specify a custom failure message instead of using the default - generated message. Not recommended. - -Example for the simple signature: - -.. code-block:: cmake - - find_package_handle_standard_args(LibXml2 DEFAULT_MSG - LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR) - -The ``LibXml2`` package is considered to be found if both -``LIBXML2_LIBRARY`` and ``LIBXML2_INCLUDE_DIR`` are valid. -Then also ``LibXml2_FOUND`` is set to ``TRUE``. If it is not found -and ``REQUIRED`` was used, it fails with a -:command:`message(FATAL_ERROR)`, independent whether ``QUIET`` was -used or not. If it is found, success will be reported, including -the content of the first ````. On repeated CMake runs, -the same message will not be printed again. - -Example for the full signature: - -.. code-block:: cmake - - find_package_handle_standard_args(LibArchive - REQUIRED_VARS LibArchive_LIBRARY LibArchive_INCLUDE_DIR - VERSION_VAR LibArchive_VERSION) - -In this case, the ``LibArchive`` package is considered to be found if -both ``LibArchive_LIBRARY`` and ``LibArchive_INCLUDE_DIR`` are valid. -Also the version of ``LibArchive`` will be checked by using the version -contained in ``LibArchive_VERSION``. Since no ``FAIL_MESSAGE`` is given, -the default messages will be printed. - -Another example for the full signature: - -.. code-block:: cmake - - find_package(Automoc4 QUIET NO_MODULE HINTS /opt/automoc4) - find_package_handle_standard_args(Automoc4 CONFIG_MODE) - -In this case, a ``FindAutmoc4.cmake`` module wraps a call to -``find_package(Automoc4 NO_MODULE)`` and adds an additional search -directory for ``automoc4``. Then the call to -``find_package_handle_standard_args`` produces a proper success/failure -message. -#]=======================================================================] +# FIND_PACKAGE_HANDLE_STANDARD_ARGS( ... ) +# +# This function is intended to be used in FindXXX.cmake modules files. +# It handles the REQUIRED, QUIET and version-related arguments to FIND_PACKAGE(). +# It also sets the _FOUND variable. +# The package is considered found if all variables ... listed contain +# valid results, e.g. valid filepaths. +# +# There are two modes of this function. The first argument in both modes is +# the name of the Find-module where it is called (in original casing). +# +# The first simple mode looks like this: +# FIND_PACKAGE_HANDLE_STANDARD_ARGS( (DEFAULT_MSG|"Custom failure message") ... ) +# If the variables to are all valid, then _FOUND +# will be set to TRUE. +# If DEFAULT_MSG is given as second argument, then the function will generate +# itself useful success and error messages. You can also supply a custom error message +# for the failure case. This is not recommended. +# +# The second mode is more powerful and also supports version checking: +# FIND_PACKAGE_HANDLE_STANDARD_ARGS(NAME [REQUIRED_VARS ...] +# [VERSION_VAR +# [CONFIG_MODE] +# [FAIL_MESSAGE "Custom failure message"] ) +# +# As above, if through are all valid, _FOUND +# will be set to TRUE. +# After REQUIRED_VARS the variables which are required for this package are listed. +# Following VERSION_VAR the name of the variable can be specified which holds +# the version of the package which has been found. If this is done, this version +# will be checked against the (potentially) specified required version used +# in the find_package() call. The EXACT keyword is also handled. The default +# messages include information about the required version and the version +# which has been actually found, both if the version is ok or not. +# Use the option CONFIG_MODE if your FindXXX.cmake module is a wrapper for +# a find_package(... NO_MODULE) call, in this case all the information +# provided by the config-mode of find_package() will be evaluated +# automatically. +# Via FAIL_MESSAGE a custom failure message can be specified, if this is not +# used, the default message will be displayed. +# +# Example for mode 1: +# +# FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 DEFAULT_MSG LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR) +# +# LibXml2 is considered to be found, if both LIBXML2_LIBRARY and +# LIBXML2_INCLUDE_DIR are valid. Then also LIBXML2_FOUND is set to TRUE. +# If it is not found and REQUIRED was used, it fails with FATAL_ERROR, +# independent whether QUIET was used or not. +# If it is found, success will be reported, including the content of . +# On repeated Cmake runs, the same message won't be printed again. +# +# Example for mode 2: +# +# FIND_PACKAGE_HANDLE_STANDARD_ARGS(BISON REQUIRED_VARS BISON_EXECUTABLE +# VERSION_VAR BISON_VERSION) +# In this case, BISON is considered to be found if the variable(s) listed +# after REQUIRED_VAR are all valid, i.e. BISON_EXECUTABLE in this case. +# Also the version of BISON will be checked by using the version contained +# in BISON_VERSION. +# Since no FAIL_MESSAGE is given, the default messages will be printed. +# +# Another example for mode 2: +# +# FIND_PACKAGE(Automoc4 QUIET NO_MODULE HINTS /opt/automoc4) +# FIND_PACKAGE_HANDLE_STANDARD_ARGS(Automoc4 CONFIG_MODE) +# In this case, FindAutmoc4.cmake wraps a call to FIND_PACKAGE(Automoc4 NO_MODULE) +# and adds an additional search directory for automoc4. +# The following FIND_PACKAGE_HANDLE_STANDARD_ARGS() call produces a proper +# success/error message. #============================================================================= # Copyright 2007-2009 Kitware, Inc. @@ -139,258 +82,179 @@ message. # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageMessage.cmake) -include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake) +INCLUDE(FindPackageMessage) +INCLUDE(CMakeParseArguments) # internal helper macro -macro(_FPHSA_FAILURE_MESSAGE _msg) - if (${_NAME}_FIND_REQUIRED) - message(FATAL_ERROR "${_msg}") - else () - if (NOT ${_NAME}_FIND_QUIETLY) - message(STATUS "${_msg}") - endif () - endif () -endmacro() +MACRO(_FPHSA_FAILURE_MESSAGE _msg) + IF (${_NAME}_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "${_msg}") + ELSE (${_NAME}_FIND_REQUIRED) + IF (NOT ${_NAME}_FIND_QUIETLY) + MESSAGE(STATUS "${_msg}") + ENDIF (NOT ${_NAME}_FIND_QUIETLY) + ENDIF (${_NAME}_FIND_REQUIRED) +ENDMACRO(_FPHSA_FAILURE_MESSAGE _msg) # internal helper macro to generate the failure message when used in CONFIG_MODE: -macro(_FPHSA_HANDLE_FAILURE_CONFIG_MODE) +MACRO(_FPHSA_HANDLE_FAILURE_CONFIG_MODE) # _CONFIG is set, but FOUND is false, this means that some other of the REQUIRED_VARS was not found: - if(${_NAME}_CONFIG) + IF(${_NAME}_CONFIG) _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: missing: ${MISSING_VARS} (found ${${_NAME}_CONFIG} ${VERSION_MSG})") - else() + ELSE(${_NAME}_CONFIG) # If _CONSIDERED_CONFIGS is set, the config-file has been found, but no suitable version. # List them all in the error message: - if(${_NAME}_CONSIDERED_CONFIGS) - set(configsText "") - list(LENGTH ${_NAME}_CONSIDERED_CONFIGS configsCount) - math(EXPR configsCount "${configsCount} - 1") - foreach(currentConfigIndex RANGE ${configsCount}) - list(GET ${_NAME}_CONSIDERED_CONFIGS ${currentConfigIndex} filename) - list(GET ${_NAME}_CONSIDERED_VERSIONS ${currentConfigIndex} version) - set(configsText "${configsText} ${filename} (version ${version})\n") - endforeach() - if (${_NAME}_NOT_FOUND_MESSAGE) - set(configsText "${configsText} Reason given by package: ${${_NAME}_NOT_FOUND_MESSAGE}\n") - endif() + IF(${_NAME}_CONSIDERED_CONFIGS) + SET(configsText "") + LIST(LENGTH ${_NAME}_CONSIDERED_CONFIGS configsCount) + MATH(EXPR configsCount "${configsCount} - 1") + FOREACH(currentConfigIndex RANGE ${configsCount}) + LIST(GET ${_NAME}_CONSIDERED_CONFIGS ${currentConfigIndex} filename) + LIST(GET ${_NAME}_CONSIDERED_VERSIONS ${currentConfigIndex} version) + SET(configsText "${configsText} ${filename} (version ${version})\n") + ENDFOREACH(currentConfigIndex) _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} ${VERSION_MSG}, checked the following files:\n${configsText}") - else() + ELSE(${_NAME}_CONSIDERED_CONFIGS) # Simple case: No Config-file was found at all: _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: found neither ${_NAME}Config.cmake nor ${_NAME_LOWER}-config.cmake ${VERSION_MSG}") - endif() - endif() -endmacro() + ENDIF(${_NAME}_CONSIDERED_CONFIGS) + ENDIF(${_NAME}_CONFIG) +ENDMACRO(_FPHSA_HANDLE_FAILURE_CONFIG_MODE) -function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) +FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) # set up the arguments for CMAKE_PARSE_ARGUMENTS and check whether we are in # new extended or in the "old" mode: - set(options CONFIG_MODE HANDLE_COMPONENTS) - set(oneValueArgs FAIL_MESSAGE VERSION_VAR FOUND_VAR) - set(multiValueArgs REQUIRED_VARS) - set(_KEYWORDS_FOR_EXTENDED_MODE ${options} ${oneValueArgs} ${multiValueArgs} ) - list(FIND _KEYWORDS_FOR_EXTENDED_MODE "${_FIRST_ARG}" INDEX) - - if(${INDEX} EQUAL -1) - set(FPHSA_FAIL_MESSAGE ${_FIRST_ARG}) - set(FPHSA_REQUIRED_VARS ${ARGN}) - set(FPHSA_VERSION_VAR) - else() + SET(options CONFIG_MODE) + SET(oneValueArgs FAIL_MESSAGE VERSION_VAR) + SET(multiValueArgs REQUIRED_VARS) + SET(_KEYWORDS_FOR_EXTENDED_MODE ${options} ${oneValueArgs} ${multiValueArgs} ) + LIST(FIND _KEYWORDS_FOR_EXTENDED_MODE "${_FIRST_ARG}" INDEX) + + IF(${INDEX} EQUAL -1) + SET(FPHSA_FAIL_MESSAGE ${_FIRST_ARG}) + SET(FPHSA_REQUIRED_VARS ${ARGN}) + SET(FPHSA_VERSION_VAR) + ELSE(${INDEX} EQUAL -1) CMAKE_PARSE_ARGUMENTS(FPHSA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN}) - if(FPHSA_UNPARSED_ARGUMENTS) - message(FATAL_ERROR "Unknown keywords given to FIND_PACKAGE_HANDLE_STANDARD_ARGS(): \"${FPHSA_UNPARSED_ARGUMENTS}\"") - endif() + IF(FPHSA_UNPARSED_ARGUMENTS) + MESSAGE(FATAL_ERROR "Unknown keywords given to FIND_PACKAGE_HANDLE_STANDARD_ARGS(): \"${FPHSA_UNPARSED_ARGUMENTS}\"") + ENDIF(FPHSA_UNPARSED_ARGUMENTS) - if(NOT FPHSA_FAIL_MESSAGE) - set(FPHSA_FAIL_MESSAGE "DEFAULT_MSG") - endif() - endif() + IF(NOT FPHSA_FAIL_MESSAGE) + SET(FPHSA_FAIL_MESSAGE "DEFAULT_MSG") + ENDIF(NOT FPHSA_FAIL_MESSAGE) + ENDIF(${INDEX} EQUAL -1) # now that we collected all arguments, process them - if("x${FPHSA_FAIL_MESSAGE}" STREQUAL "xDEFAULT_MSG") - set(FPHSA_FAIL_MESSAGE "Could NOT find ${_NAME}") - endif() + IF("${FPHSA_FAIL_MESSAGE}" STREQUAL "DEFAULT_MSG") + SET(FPHSA_FAIL_MESSAGE "Could NOT find ${_NAME}") + ENDIF("${FPHSA_FAIL_MESSAGE}" STREQUAL "DEFAULT_MSG") # In config-mode, we rely on the variable _CONFIG, which is set by find_package() # when it successfully found the config-file, including version checking: - if(FPHSA_CONFIG_MODE) - list(INSERT FPHSA_REQUIRED_VARS 0 ${_NAME}_CONFIG) - list(REMOVE_DUPLICATES FPHSA_REQUIRED_VARS) - set(FPHSA_VERSION_VAR ${_NAME}_VERSION) - endif() - - if(NOT FPHSA_REQUIRED_VARS) - message(FATAL_ERROR "No REQUIRED_VARS specified for FIND_PACKAGE_HANDLE_STANDARD_ARGS()") - endif() - - list(GET FPHSA_REQUIRED_VARS 0 _FIRST_REQUIRED_VAR) - - string(TOUPPER ${_NAME} _NAME_UPPER) - string(TOLOWER ${_NAME} _NAME_LOWER) - - if(FPHSA_FOUND_VAR) - if(FPHSA_FOUND_VAR MATCHES "^${_NAME}_FOUND$" OR FPHSA_FOUND_VAR MATCHES "^${_NAME_UPPER}_FOUND$") - set(_FOUND_VAR ${FPHSA_FOUND_VAR}) - else() - message(FATAL_ERROR "The argument for FOUND_VAR is \"${FPHSA_FOUND_VAR}\", but only \"${_NAME}_FOUND\" and \"${_NAME_UPPER}_FOUND\" are valid names.") - endif() - else() - set(_FOUND_VAR ${_NAME_UPPER}_FOUND) - endif() + IF(FPHSA_CONFIG_MODE) + LIST(INSERT FPHSA_REQUIRED_VARS 0 ${_NAME}_CONFIG) + LIST(REMOVE_DUPLICATES FPHSA_REQUIRED_VARS) + SET(FPHSA_VERSION_VAR ${_NAME}_VERSION) + ENDIF(FPHSA_CONFIG_MODE) + + IF(NOT FPHSA_REQUIRED_VARS) + MESSAGE(FATAL_ERROR "No REQUIRED_VARS specified for FIND_PACKAGE_HANDLE_STANDARD_ARGS()") + ENDIF(NOT FPHSA_REQUIRED_VARS) + + LIST(GET FPHSA_REQUIRED_VARS 0 _FIRST_REQUIRED_VAR) + + STRING(TOUPPER ${_NAME} _NAME_UPPER) + STRING(TOLOWER ${_NAME} _NAME_LOWER) # collect all variables which were not found, so they can be printed, so the # user knows better what went wrong (#6375) - set(MISSING_VARS "") - set(DETAILS "") + SET(MISSING_VARS "") + SET(DETAILS "") + SET(${_NAME_UPPER}_FOUND TRUE) # check if all passed variables are valid - set(FPHSA_FOUND_${_NAME} TRUE) - foreach(_CURRENT_VAR ${FPHSA_REQUIRED_VARS}) - if(NOT ${_CURRENT_VAR}) - set(FPHSA_FOUND_${_NAME} FALSE) - set(MISSING_VARS "${MISSING_VARS} ${_CURRENT_VAR}") - else() - set(DETAILS "${DETAILS}[${${_CURRENT_VAR}}]") - endif() - endforeach() - if(FPHSA_FOUND_${_NAME}) - set(${_NAME}_FOUND TRUE) - set(${_NAME_UPPER}_FOUND TRUE) - else() - set(${_NAME}_FOUND FALSE) - set(${_NAME_UPPER}_FOUND FALSE) - endif() - - # component handling - unset(FOUND_COMPONENTS_MSG) - unset(MISSING_COMPONENTS_MSG) - - if(FPHSA_HANDLE_COMPONENTS) - foreach(comp ${${_NAME}_FIND_COMPONENTS}) - if(${_NAME}_${comp}_FOUND) - - if(NOT DEFINED FOUND_COMPONENTS_MSG) - set(FOUND_COMPONENTS_MSG "found components: ") - endif() - set(FOUND_COMPONENTS_MSG "${FOUND_COMPONENTS_MSG} ${comp}") - - else() - - if(NOT DEFINED MISSING_COMPONENTS_MSG) - set(MISSING_COMPONENTS_MSG "missing components: ") - endif() - set(MISSING_COMPONENTS_MSG "${MISSING_COMPONENTS_MSG} ${comp}") - - if(${_NAME}_FIND_REQUIRED_${comp}) - set(${_NAME}_FOUND FALSE) - set(MISSING_VARS "${MISSING_VARS} ${comp}") - endif() - - endif() - endforeach() - set(COMPONENT_MSG "${FOUND_COMPONENTS_MSG} ${MISSING_COMPONENTS_MSG}") - set(DETAILS "${DETAILS}[c${COMPONENT_MSG}]") - endif() + FOREACH(_CURRENT_VAR ${FPHSA_REQUIRED_VARS}) + IF(NOT ${_CURRENT_VAR}) + SET(${_NAME_UPPER}_FOUND FALSE) + SET(MISSING_VARS "${MISSING_VARS} ${_CURRENT_VAR}") + ELSE(NOT ${_CURRENT_VAR}) + SET(DETAILS "${DETAILS}[${${_CURRENT_VAR}}]") + ENDIF(NOT ${_CURRENT_VAR}) + ENDFOREACH(_CURRENT_VAR) + # version handling: - set(VERSION_MSG "") - set(VERSION_OK TRUE) - set(VERSION ${${FPHSA_VERSION_VAR}}) - - # check with DEFINED here as the requested or found version may be "0" - if (DEFINED ${_NAME}_FIND_VERSION) - if(DEFINED ${FPHSA_VERSION_VAR}) - - if(${_NAME}_FIND_VERSION_EXACT) # exact version required - # count the dots in the version string - string(REGEX REPLACE "[^.]" "" _VERSION_DOTS "${VERSION}") - # add one dot because there is one dot more than there are components - string(LENGTH "${_VERSION_DOTS}." _VERSION_DOTS) - if (_VERSION_DOTS GREATER ${_NAME}_FIND_VERSION_COUNT) - # Because of the C++ implementation of find_package() ${_NAME}_FIND_VERSION_COUNT - # is at most 4 here. Therefore a simple lookup table is used. - if (${_NAME}_FIND_VERSION_COUNT EQUAL 1) - set(_VERSION_REGEX "[^.]*") - elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 2) - set(_VERSION_REGEX "[^.]*\\.[^.]*") - elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 3) - set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*") - else () - set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*\\.[^.]*") - endif () - string(REGEX REPLACE "^(${_VERSION_REGEX})\\..*" "\\1" _VERSION_HEAD "${VERSION}") - unset(_VERSION_REGEX) - if (NOT ${_NAME}_FIND_VERSION VERSION_EQUAL _VERSION_HEAD) - set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"") - set(VERSION_OK FALSE) - else () - set(VERSION_MSG "(found suitable exact version \"${VERSION}\")") - endif () - unset(_VERSION_HEAD) - else () - if (NOT ${_NAME}_FIND_VERSION VERSION_EQUAL VERSION) - set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"") - set(VERSION_OK FALSE) - else () - set(VERSION_MSG "(found suitable exact version \"${VERSION}\")") - endif () - endif () - unset(_VERSION_DOTS) - - else() # minimum version specified: - if (${_NAME}_FIND_VERSION VERSION_GREATER VERSION) - set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is at least \"${${_NAME}_FIND_VERSION}\"") - set(VERSION_OK FALSE) - else () - set(VERSION_MSG "(found suitable version \"${VERSION}\", minimum required is \"${${_NAME}_FIND_VERSION}\")") - endif () - endif() - - else() + SET(VERSION_MSG "") + SET(VERSION_OK TRUE) + SET(VERSION ${${FPHSA_VERSION_VAR}} ) + IF (${_NAME}_FIND_VERSION) + + IF(VERSION) + + IF(${_NAME}_FIND_VERSION_EXACT) # exact version required + IF (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}") + SET(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"") + SET(VERSION_OK FALSE) + ELSE (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}") + SET(VERSION_MSG "(found suitable exact version \"${VERSION}\")") + ENDIF (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}") + + ELSE(${_NAME}_FIND_VERSION_EXACT) # minimum version specified: + IF ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}") + SET(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is at least \"${${_NAME}_FIND_VERSION}\"") + SET(VERSION_OK FALSE) + ELSE ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}") + SET(VERSION_MSG "(found suitable version \"${VERSION}\", required is \"${${_NAME}_FIND_VERSION}\")") + ENDIF ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}") + ENDIF(${_NAME}_FIND_VERSION_EXACT) + + ELSE(VERSION) # if the package was not found, but a version was given, add that to the output: - if(${_NAME}_FIND_VERSION_EXACT) - set(VERSION_MSG "(Required is exact version \"${${_NAME}_FIND_VERSION}\")") - else() - set(VERSION_MSG "(Required is at least version \"${${_NAME}_FIND_VERSION}\")") - endif() - - endif() - else () - if(VERSION) - set(VERSION_MSG "(found version \"${VERSION}\")") - endif() - endif () - - if(VERSION_OK) - set(DETAILS "${DETAILS}[v${VERSION}(${${_NAME}_FIND_VERSION})]") - else() - set(${_NAME}_FOUND FALSE) - endif() + IF(${_NAME}_FIND_VERSION_EXACT) + SET(VERSION_MSG "(Required is exact version \"${${_NAME}_FIND_VERSION}\")") + ELSE(${_NAME}_FIND_VERSION_EXACT) + SET(VERSION_MSG "(Required is at least version \"${${_NAME}_FIND_VERSION}\")") + ENDIF(${_NAME}_FIND_VERSION_EXACT) + + ENDIF(VERSION) + ELSE (${_NAME}_FIND_VERSION) + IF(VERSION) + SET(VERSION_MSG "(found version \"${VERSION}\")") + ENDIF(VERSION) + ENDIF (${_NAME}_FIND_VERSION) + + IF(VERSION_OK) + SET(DETAILS "${DETAILS}[v${VERSION}(${${_NAME}_FIND_VERSION})]") + ELSE(VERSION_OK) + SET(${_NAME_UPPER}_FOUND FALSE) + ENDIF(VERSION_OK) # print the result: - if (${_NAME}_FOUND) - FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG} ${COMPONENT_MSG}" "${DETAILS}") - else () + IF (${_NAME_UPPER}_FOUND) + FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG}" "${DETAILS}") + ELSE (${_NAME_UPPER}_FOUND) - if(FPHSA_CONFIG_MODE) + IF(FPHSA_CONFIG_MODE) _FPHSA_HANDLE_FAILURE_CONFIG_MODE() - else() - if(NOT VERSION_OK) + ELSE(FPHSA_CONFIG_MODE) + IF(NOT VERSION_OK) _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_FIRST_REQUIRED_VAR}})") - else() + ELSE(NOT VERSION_OK) _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} (missing: ${MISSING_VARS}) ${VERSION_MSG}") - endif() - endif() + ENDIF(NOT VERSION_OK) + ENDIF(FPHSA_CONFIG_MODE) + + ENDIF (${_NAME_UPPER}_FOUND) - endif () + SET(${_NAME_UPPER}_FOUND ${${_NAME_UPPER}_FOUND} PARENT_SCOPE) - set(${_NAME}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE) - set(${_NAME_UPPER}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE) -endfunction() +ENDFUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _FIRST_ARG) diff --git a/CMakeModules/FindPackageMessage.cmake b/CMakeModules/FindPackageMessage.cmake deleted file mode 100644 index a0349d3d..00000000 --- a/CMakeModules/FindPackageMessage.cmake +++ /dev/null @@ -1,57 +0,0 @@ -#.rst: -# FindPackageMessage -# ------------------ -# -# -# -# FIND_PACKAGE_MESSAGE( "message for user" "find result details") -# -# This macro is intended to be used in FindXXX.cmake modules files. It -# will print a message once for each unique find result. This is useful -# for telling the user where a package was found. The first argument -# specifies the name (XXX) of the package. The second argument -# specifies the message to display. The third argument lists details -# about the find result so that if they change the message will be -# displayed again. The macro also obeys the QUIET argument to the -# find_package command. -# -# Example: -# -# :: -# -# if(X11_FOUND) -# FIND_PACKAGE_MESSAGE(X11 "Found X11: ${X11_X11_LIB}" -# "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]") -# else() -# ... -# endif() - -#============================================================================= -# Copyright 2008-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -function(FIND_PACKAGE_MESSAGE pkg msg details) - # Avoid printing a message repeatedly for the same find result. - if(NOT ${pkg}_FIND_QUIETLY) - string(REPLACE "\n" "" details "${details}") - set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg}) - if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}") - # The message has not yet been printed. - message(STATUS "${msg}") - - # Save the find details in the cache to avoid printing the same - # message again. - set("${DETAILS_VAR}" "${details}" - CACHE INTERNAL "Details about finding ${pkg}") - endif() - endif() -endfunction() From 57c5875fc601a076441334aaf7c3504ac92ae0bd Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 15:50:20 +0530 Subject: [PATCH 21/51] Adds Event2 CMake Module and uses it. Fixes #199 --- CMakeModules/FindLibEvent.cmake | 59 +++++++++++++++++++++++++++++++++ src/onion/CMakeLists.txt | 4 ++- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 CMakeModules/FindLibEvent.cmake diff --git a/CMakeModules/FindLibEvent.cmake b/CMakeModules/FindLibEvent.cmake new file mode 100644 index 00000000..dce50520 --- /dev/null +++ b/CMakeModules/FindLibEvent.cmake @@ -0,0 +1,59 @@ +# - Find libevent +# Find the native libevent includes and library. +# Once done this will define +# +# LIBEVENT_INCLUDE_DIRS - where to find event2/event.h, etc. +# LIBEVENT_LIBRARIES - List of libraries when using libevent. +# LIBEVENT_FOUND - True if libevent found. +# +# LIBEVENT_VERSION_STRING - The version of libevent found (x.y.z) +# LIBEVENT_VERSION_MAJOR - The major version +# LIBEVENT_VERSION_MINOR - The minor version +# LIBEVENT_VERSION_PATCH - The patch version +# +# Avaliable components: +# core +# pthreads +# extra +# openssl +# + +SET(LIBEVENT_core_LIBRARY "NOTREQ") +SET(LIBEVENT_pthreads_LIBRARY "NOTREQ") +SET(LIBEVENT_extra_LIBRARY "NOTREQ") +SET(LIBEVENT_openssl_LIBRARY "NOTREQ") + +FIND_PATH(LIBEVENT_INCLUDE_DIR NAMES event2/event.h) + +IF(LIBEVENT_INCLUDE_DIR AND EXISTS "${LIBEVENT_INCLUDE_DIR}/event2/event-config.h") + # Read and parse libevent version header file for version number + file(READ "${LIBEVENT_INCLUDE_DIR}/event2/event-config.h" _libevent_HEADER_CONTENTS) + + string(REGEX REPLACE ".*#define _EVENT_VERSION +\"([0-9]+).*" "\\1" LIBEVENT_VERSION_MAJOR "${_libevent_HEADER_CONTENTS}") + string(REGEX REPLACE ".*#define _EVENT_VERSION +\"[0-9]+\\.([0-9]+).*" "\\1" LIBEVENT_VERSION_MINOR "${_libevent_HEADER_CONTENTS}") + string(REGEX REPLACE ".*#define _EVENT_VERSION +\"[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" LIBEVENT_VERSION_PATCH "${_libevent_HEADER_CONTENTS}") + + SET(LIBEVENT_VERSION_STRING "${LIBEVENT_VERSION_MAJOR}.${LIBEVENT_VERSION_MINOR}.${LIBEVENT_VERSION_PATCH}") +ENDIF() + +FOREACH(component ${Libevent_FIND_COMPONENTS}) + UNSET(LIBEVENT_${component}_LIBRARY) + FIND_LIBRARY(LIBEVENT_${component}_LIBRARY NAMES event_${component} PATH_SUFFIXES event2) +ENDFOREACH() + +# handle the QUIETLY and REQUIRED arguments and set LIBEVENT_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Libevent + REQUIRED_VARS LIBEVENT_core_LIBRARY LIBEVENT_pthreads_LIBRARY LIBEVENT_extra_LIBRARY LIBEVENT_openssl_LIBRARY LIBEVENT_INCLUDE_DIR + VERSION_VAR LIBEVENT_VERSION_STRING + ) + +IF(LIBEVENT_FOUND) + SET(LIBEVENT_INCLUDE_DIRS ${LIBEVENT_INCLUDE_DIR}) + FOREACH(component ${Libevent_FIND_COMPONENTS}) + LIST(APPEND LIBEVENT_LIBRARIES ${LIBEVENT_${component}_LIBRARY}) + ENDFOREACH() +ENDIF() + +MARK_AS_ADVANCED(LIBEVENT_core_LIBRARY LIBEVENT_pthreads_LIBRARY LIBEVENT_extra_LIBRARY LIBEVENT_openssl_LIBRARY LIBEVENT_INCLUDE_DIR) diff --git a/src/onion/CMakeLists.txt b/src/onion/CMakeLists.txt index 87e03d3f..af1d8b9b 100644 --- a/src/onion/CMakeLists.txt +++ b/src/onion/CMakeLists.txt @@ -19,7 +19,9 @@ LIST(APPEND LIBRARIES rt) # Poller can be a bit more complex, but basically the same. if (${ONION_POLLER} STREQUAL libevent) + find_package(Libevent COMPONENTS core pthreads REQUIRED) LIST(APPEND SOURCES poller_libevent.c) + include_directories(${LIBEVENT_INCLUDE_DIRS}) endif (${ONION_POLLER} STREQUAL libevent) if (${ONION_POLLER} STREQUAL libev) find_package(LibEv REQUIRED) @@ -68,7 +70,7 @@ if (REDIS_ENABLED) LIST(APPEND LIBRARIES ${HIREDIS_LIBRARIES}) endif(REDIS_ENABLED) if (${ONION_POLLER} STREQUAL libevent) - LIST(APPEND LIBRARIES event_core event_pthreads) + LIST(APPEND LIBRARIES ${LIBEVENT_LIBRARIES}) endif (${ONION_POLLER} STREQUAL libevent) if (${ONION_POLLER} STREQUAL libev) LIST(APPEND LIBRARIES ${LIBEV_LIBRARIES}) From 662a4e235d8bdb0b89578b7f43c4ecd73114ad79 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 19:00:18 +0530 Subject: [PATCH 22/51] Uses cross compatible S_ISDIR instead of DT_DIR to detect if a name referes to a directory. --- tools/opack/opack.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/opack/opack.c b/tools/opack/opack.c index 2b4a7af3..b5c92bed 100644 --- a/tools/opack/opack.c +++ b/tools/opack/opack.c @@ -187,7 +187,9 @@ void parse_directory(const char *prefix, const char *dirname, FILE *outfd, onion if (de->d_name[0]=='.' || de->d_name[strlen(de->d_name)-1]=='~') continue; snprintf(fullname, sizeof(fullname), "%s/%s", dirname, de->d_name); - if (de->d_type==DT_DIR){ + struct stat s; + stat(de->d_name, &s); + if (S_ISDIR(s.st_mode)){ char prefix2[256]; snprintf(prefix2, sizeof(prefix2), "%s/%s", prefix, de->d_name); parse_directory(prefix2, fullname, outfd, assets); @@ -209,7 +211,9 @@ void parse_directory(const char *prefix, const char *dirname, FILE *outfd, onion if (de->d_name[0]=='.' || de->d_name[strlen(de->d_name)-1]=='~') continue; char *fname=funcname(prefix, de->d_name); - if (de->d_type==DT_DIR){ + struct stat s; + stat(de->d_name, &s); + if (S_ISDIR(s.st_mode)){ int l=strlen(de->d_name); fprintf(outfd, " if (strncmp(\"%s/\", path, %d)==0){\n", de->d_name, l+1); fprintf(outfd, " onion_request_advance_path(req, %d);\n", l+1); From 8a6962afd45dea3e5629d6f7179b91c1de8c4264 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 19:03:48 +0530 Subject: [PATCH 23/51] Adds a missing header file to resolve ssize_t problem during compilation --- tools/common/updateassets.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/common/updateassets.c b/tools/common/updateassets.c index f6425fb4..8d9c104e 100644 --- a/tools/common/updateassets.c +++ b/tools/common/updateassets.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "updateassets.h" From e319868b9096d99d4951b44ccded372a9a06af14 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Wed, 17 Aug 2016 19:13:31 +0530 Subject: [PATCH 24/51] Adds _DARWIN_C_SOURCE to make RTLD_NODELETE available --- tools/otemplate/load.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/otemplate/load.c b/tools/otemplate/load.c index 9acebb72..333b23bf 100644 --- a/tools/otemplate/load.c +++ b/tools/otemplate/load.c @@ -16,6 +16,8 @@ along with this program. If not, see . */ +#define _DARWIN_C_SOURCE + #include #include #include From 16f0717bce4ef15ed11eb5ab23e8c162d227ecc0 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Thu, 18 Aug 2016 00:19:34 +0530 Subject: [PATCH 25/51] Fixes #202 --- examples/ofileserver/fileserver.c | 4 ++-- tools/otemplate/otemplate.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/ofileserver/fileserver.c b/examples/ofileserver/fileserver.c index 735b769e..140b7cef 100644 --- a/examples/ofileserver/fileserver.c +++ b/examples/ofileserver/fileserver.c @@ -27,7 +27,7 @@ #include #include #include -#ifdef GETTEXT_ENABLED +#ifdef HAVE_GETTEXT # include #endif #include @@ -102,7 +102,7 @@ int main(int argc, char **argv){ onion_handler_add(root, onion_handler_export_local_new(dirname)); // This is the root directory where the translations are. -#ifdef GETTEXT_ENABLED +#ifdef HAVE_GETTEXT #define W "." setenv("LANGUAGE","locale",1); // Remove LANGUAGE env var, set it to the locale name, setlocale(LC_ALL,""); diff --git a/tools/otemplate/otemplate.c b/tools/otemplate/otemplate.c index 9e51ac0c..9fe7cbca 100644 --- a/tools/otemplate/otemplate.c +++ b/tools/otemplate/otemplate.c @@ -237,7 +237,7 @@ int work(const char *infilename, const char *outfilename, onion_assets_file *ass fprintf(status.out, "/** Autogenerated by otemplate v. 0.2.0 */\n" "\n" -#ifdef GETTEXT_ENABLED +#ifdef HAVE_GETTEXT "#include \n" #endif "#include \n\n" From 2b7c4fda12ef176abc22b3fc2fbac6ffd476cc62 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Thu, 18 Aug 2016 00:20:06 +0530 Subject: [PATCH 26/51] Adds the include directory and library of GetText or Intl --- CMakeLists.txt | 1 + examples/ofileserver/CMakeLists.txt | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index adfe48b5..b41d867d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -206,6 +206,7 @@ endif(${ONION_USE_SYSTEMD}) find_package(Intl) if (Intl_FOUND) set(GETTEXT_ENABLED true) + include_directories(${Intl_INCLUDE_DIRS}) message(STATUS "gettext support is compiled in otemplate.") else (Intl_FOUND) message(STATUS "No gettext support.") diff --git a/examples/ofileserver/CMakeLists.txt b/examples/ofileserver/CMakeLists.txt index 5bf364f2..083ba5ed 100644 --- a/examples/ofileserver/CMakeLists.txt +++ b/examples/ofileserver/CMakeLists.txt @@ -1,5 +1,5 @@ -include_directories (${PROJECT_SOURCE_DIR}/src/) -include_directories (${CMAKE_CURRENT_BINARY_DIR}) +include_directories (${PROJECT_SOURCE_DIR}/src/) +include_directories (${CMAKE_CURRENT_BINARY_DIR}) find_program(HAVE_MSGFMT msgfmt) add_custom_command( @@ -13,28 +13,28 @@ if(HAVE_MSGFMT) add_custom_target( fo_zh ALL COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/locale/LC_MESSAGES/ - COMMAND msgfmt ${CMAKE_CURRENT_SOURCE_DIR}/zh.po + COMMAND msgfmt ${CMAKE_CURRENT_SOURCE_DIR}/zh.po -o ${CMAKE_CURRENT_BINARY_DIR}/locale/LC_MESSAGES/zh.mo DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/zh.po ) add_custom_target( fo_es ALL COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/locale/LC_MESSAGES/ - COMMAND msgfmt ${CMAKE_CURRENT_SOURCE_DIR}/es.po + COMMAND msgfmt ${CMAKE_CURRENT_SOURCE_DIR}/es.po -o ${CMAKE_CURRENT_BINARY_DIR}/locale/LC_MESSAGES/es.mo DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/es.po ) add_custom_target( fo_fr ALL COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/locale/LC_MESSAGES/ - COMMAND msgfmt ${CMAKE_CURRENT_SOURCE_DIR}/fr.po + COMMAND msgfmt ${CMAKE_CURRENT_SOURCE_DIR}/fr.po -o ${CMAKE_CURRENT_BINARY_DIR}/locale/LC_MESSAGES/fr.mo DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/fr.po ) add_custom_target( fo_pl ALL COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/locale/LC_MESSAGES/ - COMMAND msgfmt ${CMAKE_CURRENT_SOURCE_DIR}/pl.po + COMMAND msgfmt ${CMAKE_CURRENT_SOURCE_DIR}/pl.po -o ${CMAKE_CURRENT_BINARY_DIR}/locale/LC_MESSAGES/pl.mo DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/pl.po ) @@ -42,11 +42,13 @@ endif(HAVE_MSGFMT) add_executable(ofileserver fileserver.c fileserver_html.c) -target_link_libraries(ofileserver onion_static m ) +target_link_libraries(ofileserver onion_static m) +if (GETTEXT_ENABLED) + target_link_libraries(ofileserver ${Intl_LIBRARIES}) +endif (GETTEXT_ENABLED) if (${Z_LIB}) target_link_libraries(ofileserver ${Z_LIB}) endif(${Z_LIB}) set_target_properties(ofileserver PROPERTIES OUTPUT_NAME "onion-ofileserver") install(TARGETS ofileserver DESTINATION ${CMAKE_INSTALL_BINDIR}) - From bfd3976328e8a09a1d515f4d1c5339e645e5ffc5 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Thu, 18 Aug 2016 00:54:21 +0530 Subject: [PATCH 27/51] Uses Cairo CMake Module --- CMakeLists.txt | 12 ++++-------- examples/cairo/CMakeLists.txt | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f71167c..e604356f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,15 +144,11 @@ if (${ONION_USE_PNG}) endif (PNG_FOUND) endif (${ONION_USE_PNG}) -find_library(CAIRO_LIB NAMES cairo PATH ${LIBPATH}) -find_file(CAIRO_HEADER cairo/cairo.h ${INCLUDE_PATH}) -if (CAIRO_HEADER) +find_package(CAIRO) +if (CAIRO_FOUND) set(CAIRO_ENABLED true) - set(CAIRO_LIB ${CAIRO_LIB}) - message(STATUS "libcairo found. Adding cairo examples. ${CAIRO_LIB}") -else (CAIRO_HEADER) - message(STATUS "libcairo NOT found.") -endif (CAIRO_HEADER) + message(STATUS "Adding cairo examples.") +endif (CAIRO_FOUND) if (${ONION_USE_JPEG}) find_package(JPEG) diff --git a/examples/cairo/CMakeLists.txt b/examples/cairo/CMakeLists.txt index e34ae8ac..cfe1e1c9 100644 --- a/examples/cairo/CMakeLists.txt +++ b/examples/cairo/CMakeLists.txt @@ -1,7 +1,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/) add_executable(cairo_example cairo.c) -target_link_libraries(cairo_example onion onion_extras cairo m) +target_link_libraries(cairo_example onion onion_extras ${CAIRO_LIBRARIES} m) set_target_properties(cairo_example PROPERTIES OUTPUT_NAME "onion-cairo_example") install(TARGETS cairo_example DESTINATION ${CMAKE_INSTALL_BINDIR}) From 18f672e8752b9dd4ffc8f7a940396b9d5f0a6ae2 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Thu, 18 Aug 2016 00:58:41 +0530 Subject: [PATCH 28/51] Fixes #200, uses ZLIB CMake Module --- examples/ofileserver/CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/ofileserver/CMakeLists.txt b/examples/ofileserver/CMakeLists.txt index b20d7e9d..a1e870c9 100644 --- a/examples/ofileserver/CMakeLists.txt +++ b/examples/ofileserver/CMakeLists.txt @@ -42,9 +42,11 @@ endif(HAVE_MSGFMT) add_executable(ofileserver fileserver.c fileserver_html.c) target_link_libraries(ofileserver onion_static m ) -if (${Z_LIB}) - target_link_libraries(ofileserver ${Z_LIB}) -endif(${Z_LIB}) + +find_package(ZLIB) +if (${ZLIB_FOUND}) + target_link_libraries(ofileserver ${ZLIB_LIBRARIES}) +endif(${ZLIB_FOUND}) set_target_properties(ofileserver PROPERTIES OUTPUT_NAME "onion-ofileserver") install(TARGETS ofileserver DESTINATION ${CMAKE_INSTALL_BINDIR}) From 06ee7ac75541a1e2f65a42156503d0d509653619 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Thu, 18 Aug 2016 01:01:30 +0530 Subject: [PATCH 29/51] Fixes #201, corrects otemplate help menu --- tools/otemplate/otemplate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/otemplate/otemplate.c b/tools/otemplate/otemplate.c index fc0b44dc..5bfb080b 100644 --- a/tools/otemplate/otemplate.c +++ b/tools/otemplate/otemplate.c @@ -144,7 +144,7 @@ void help(const char *msg){ " error reporting refers to the C file, not the template.\n" " --asset-file|-a Write function definitions to an asset file. Defaults to assets.h\n" " Input filename or '-' to use stdin.\n" -" Output filename or '-' to use stdin.\n" +" Output filename or '-' to use stdout.\n" "\n" "Templatetags plugins are search in this order, always libPLUGIN.so, where PLUGIN is the plugin name:\n" " 1. Set by command line with --templatetagsdir or -t\n" From 9d54bce088c30a4f8f3f6eb17ff53f58bad724d3 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Thu, 18 Aug 2016 01:19:09 +0530 Subject: [PATCH 30/51] Properly handles the Cairo example problem, Fixes #195 --- CMakeLists.txt | 14 +++++++------- examples/CMakeLists.txt | 2 -- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e604356f..9b0d6fb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,19 +137,19 @@ if (${ONION_USE_PNG}) find_package(PNG) if (PNG_FOUND) set(PNG_ENABLED true) - set(PNG_LIB ${PNG_LIB}) message(STATUS "libpng found. png support is compiled in at extras.") + find_package(CAIRO) + if (CAIRO_FOUND) + set(CAIRO_ENABLED true) + message(STATUS "Adding cairo examples.") + else (CAIRO_FOUND) + message(WARNING "Some examples are disabled as you dont have cairo: cairo") + endif (CAIRO_FOUND) else (PNG_LIB) message("libpng not found. No png support.") endif (PNG_FOUND) endif (${ONION_USE_PNG}) -find_package(CAIRO) -if (CAIRO_FOUND) - set(CAIRO_ENABLED true) - message(STATUS "Adding cairo examples.") -endif (CAIRO_FOUND) - if (${ONION_USE_JPEG}) find_package(JPEG) if (JPEG_FOUND) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index da6a2854..f80f80ae 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -42,8 +42,6 @@ endif(OTEMPLATE) if (${CAIRO_ENABLED}) add_subdirectory(cairo) -else (${CAIRO_ENABLED}) - message(WARNING "Some examples are disabled as you dont have cairo: cairo") endif (${CAIRO_ENABLED}) From ad07e9ae8cc144f7a81b6a45dd4f88cf9fda1aee Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Thu, 18 Aug 2016 01:23:40 +0530 Subject: [PATCH 31/51] Fixes typo in FindBoehmGC.cmake --- CMakeLists.txt | 2 +- CMakeModules/{FindBohemGC.cmake => FindBoehmGC.cmake} | 8 ++++---- debian/changelog | 2 +- src/onion/low.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) rename CMakeModules/{FindBohemGC.cmake => FindBoehmGC.cmake} (95%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b0d6fb2..0d9bce50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,7 +161,7 @@ if (${ONION_USE_JPEG}) endif (${ONION_USE_JPEG}) if (${ONION_USE_GC}) - find_package(BohemGC) + find_package(BoehmGC) if (BOEHM_GC_FOUND) message(STATUS "compiling Boehm GC examples") set(GC_ENABLED true) diff --git a/CMakeModules/FindBohemGC.cmake b/CMakeModules/FindBoehmGC.cmake similarity index 95% rename from CMakeModules/FindBohemGC.cmake rename to CMakeModules/FindBoehmGC.cmake index a5082b0c..bdb7240e 100644 --- a/CMakeModules/FindBohemGC.cmake +++ b/CMakeModules/FindBoehmGC.cmake @@ -1,9 +1,9 @@ -# - Try to find Cairo +# - Try to find Boehm GC # Once done, this will define # -# BOEHM_GC_FOUND - system has Cairo -# BOEHM_GC_INCLUDE_DIR - the Bohem GC include directories -# BOEHM_GC_LIBRARIES - link these to use Bohem GC +# BOEHM_GC_FOUND - system has Boehm GC +# BOEHM_GC_INCLUDE_DIR - the Boehm GC include directories +# BOEHM_GC_LIBRARIES - link these to use Boehm GC # # Copyright (c) 2010-2015 Takashi Kato # diff --git a/debian/changelog b/debian/changelog index 223dd68e..3f7e0c14 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,7 +10,7 @@ libonion (0.8.0) stable; urgency=low * Rework on request parser to allow OCS_YIELD (David Moreno). * Overall API improvements (David Moreno) * Use of custom low level functions: onion_malloc, onion_free... (Basile Starynkevitch) - * Bohem GC support (Basile Starynkevitch) + * Boehm GC support (Basile Starynkevitch) * Man pages for the tools. (David Moreno) * Semantic Versioning. * Many small fixes and improvements. diff --git a/src/onion/low.c b/src/onion/low.c index 88696e8d..84ba1720 100644 --- a/src/onion/low.c +++ b/src/onion/low.c @@ -41,7 +41,7 @@ #include "low.h" #include "log.h" -/// @defgroup low Low level OS functions. Encapsulates some low level functions to allow other OS implementations (Bohem GC) +/// @defgroup low Low level OS functions. Encapsulates some low level functions to allow other OS implementations (Boehm GC) /* the pointers to user provided routines for memory management & memory failure */ From ac2fb3687db5c280b77efcf6fb8fa261a1267086 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Thu, 18 Aug 2016 02:55:04 +0530 Subject: [PATCH 32/51] Adds alternatives to SOCK_CLOEXEC in tests/01-internal/util.c --- tests/01-internal/utils.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/01-internal/utils.c b/tests/01-internal/utils.c index a0fbe136..7df639d8 100644 --- a/tests/01-internal/utils.c +++ b/tests/01-internal/utils.c @@ -15,17 +15,22 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ +#define _DARWIN_C_SOURCE #include "utils.h" #include #include #include #include +#include #include #include #include +#ifndef SOCK_CLOEXEC +#define SOCK_CLOEXEC O_CLOEXEC +#endif int connect_to(const char *addr, const char *port){ struct addrinfo hints; From 3d41df2e248187734dbbaecb3f32ce7e3e6d453c Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Thu, 18 Aug 2016 03:07:54 +0530 Subject: [PATCH 33/51] Specifies for gnutls-certtool as osx itself has its own certtool and thus the conflicts breaks the compilation --- tests/01-internal/CMakeLists.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/01-internal/CMakeLists.txt b/tests/01-internal/CMakeLists.txt index 4c1c210f..9bb80b26 100644 --- a/tests/01-internal/CMakeLists.txt +++ b/tests/01-internal/CMakeLists.txt @@ -20,15 +20,15 @@ add_test(internal-server 05-server) if (GNUTLS_ENABLED) IF (CURL) -message(STATUS "Looking for certool") -FIND_PROGRAM(CERTTOOL certtool) -IF (CERTTOOL) -message(STATUS "Found certool compiling all tests") +message(STATUS "Looking for gnutls-certtool") +find_program(GNUTLS_CERTTOOL gnutls-certtool) +IF (GNUTLS_CERTTOOL) +message(STATUS "Found gnutls-certtool compiling all tests") add_custom_command( OUTPUT mycert.pem COMMAND - ${CERTTOOL} --generate-privkey --outfile mycert.key && - ${CERTTOOL} --generate-self-signed --load-privkey mycert.key --outfile mycert.crt --template ${CMAKE_CURRENT_SOURCE_DIR}/mycert.cfg && + ${GNUTLS_CERTTOOL} --generate-privkey --outfile mycert.key && + ${GNUTLS_CERTTOOL} --generate-self-signed --load-privkey mycert.key --outfile mycert.crt --template ${CMAKE_CURRENT_SOURCE_DIR}/mycert.cfg && cat mycert.crt mycert.key > mycert.pem DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/mycert.cfg ) @@ -40,9 +40,9 @@ if(PTHREADS) add_test(internal-onion 06-onion) endif(PTHREADS) -ELSE(CERTTOOL) -message(STATUS "Not found certool not compiling 06-server") -ENDIF (CERTTOOL) +ELSE(GNUTLS_CERTTOOL) +message(STATUS "Not found gnutls-certool not compiling 06-server") +ENDIF (GNUTLS_CERTTOOL) ENDIF (CURL) endif(GNUTLS_ENABLED) From 49ce3a6e9981a1018e03a860b3b09ec35b502a45 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Thu, 18 Aug 2016 03:09:41 +0530 Subject: [PATCH 34/51] Replaces deprecated malloc.h with stdlib.h in tests/01-internal/06-onion.c --- tests/01-internal/06-onion.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/01-internal/06-onion.c b/tests/01-internal/06-onion.c index 5acdbaf3..e4682e50 100755 --- a/tests/01-internal/06-onion.c +++ b/tests/01-internal/06-onion.c @@ -17,7 +17,7 @@ */ #include -#include +#include #include #include #include From 05a07cf61e276fd9efac98464431d53de664162a Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Thu, 18 Aug 2016 03:12:59 +0530 Subject: [PATCH 35/51] Links test 01-internal no. 13 with external library --- tests/01-internal/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/01-internal/CMakeLists.txt b/tests/01-internal/CMakeLists.txt index 9bb80b26..a274138d 100644 --- a/tests/01-internal/CMakeLists.txt +++ b/tests/01-internal/CMakeLists.txt @@ -87,6 +87,9 @@ add_custom_command( DEPENDS ${OTEMPLATE} ${CMAKE_CURRENT_SOURCE_DIR}/../../AGPL.txt ) target_link_libraries(13-otemplates onion) +if (GETTEXT_ENABLED) + target_link_libraries(13-otemplates ${Intl_LIBRARIES}) +endif (GETTEXT_ENABLED) add_test(internal-otemplates 13-otemplates) endif (OTEMPLATE) From 1259e72c6b44fa0e8e50baec08a2b4d8b61ec93c Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Thu, 18 Aug 2016 03:19:33 +0530 Subject: [PATCH 36/51] Links external library gettext with 07-tools --- tests/07-tools/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/07-tools/CMakeLists.txt b/tests/07-tools/CMakeLists.txt index b874869e..fb23e3d3 100644 --- a/tests/07-tools/CMakeLists.txt +++ b/tests/07-tools/CMakeLists.txt @@ -1,5 +1,5 @@ -include_directories (${PROJECT_SOURCE_DIR}/src/) +include_directories (${PROJECT_SOURCE_DIR}/src/) add_custom_command( OUTPUT test_html.c @@ -32,6 +32,9 @@ add_custom_command( add_executable(01-otemplate 01-otemplate.c test_html.c external_html.c extended_html.c base_html.c) target_link_libraries(01-otemplate onion_static) +if (GETTEXT_ENABLED) + target_link_libraries(01-otemplate ${Intl_LIBRARIES}) +endif (GETTEXT_ENABLED) # add_executable(02-test 02-test.cpp test_html.c external_html.c extended_html.c base_html.c) # target_link_libraries(02-test onion_static onion_handlers onioncpp) From 798d76bc8e7f0877b965c7adf603c5d18082cdd5 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Thu, 18 Aug 2016 03:28:09 +0530 Subject: [PATCH 37/51] Includes CTest to compile target make test --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index cf874b55..413a0f82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -276,6 +276,7 @@ project (onion) INCLUDE(CPackConfig.cmake) INCLUDE(CPack) +INCLUDE(CTest) add_subdirectory(src) add_subdirectory(tools) From a88a1a14bd16fdb9c3b78c1a3389bb1927673886 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Thu, 18 Aug 2016 16:08:50 +0530 Subject: [PATCH 38/51] Corrects Boehm-GC example by removing GC prefix from some functions and using pthread function declarations directly. From gc_config_macros.h and gc_pthread_redirects.h, the pthread function declarations are going to be automatically defined if not defined using macros making it cross compatible --- examples/boehm-gc/boehm-gc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/boehm-gc/boehm-gc.c b/examples/boehm-gc/boehm-gc.c index 81495e84..9c168ef7 100644 --- a/examples/boehm-gc/boehm-gc.c +++ b/examples/boehm-gc/boehm-gc.c @@ -1,5 +1,5 @@ /** Licensed under AGPL 3.0. (C) 2010 David Moreno Montero. http://coralbits.com */ -#define GC_THREADS 1 +#define GC_THREADS #include @@ -48,8 +48,8 @@ int main(int argc, char **argv){ memory_allocation_error); onion_low_initialize_threads( GC_pthread_create, GC_pthread_join, - GC_pthread_cancel, GC_pthread_detach, - GC_pthread_exit, GC_pthread_sigmask); + pthread_cancel, GC_pthread_detach, + pthread_exit, pthread_sigmask); signal(SIGINT,shutdown_server); signal(SIGTERM,shutdown_server); From 2aa3e76ee495ec9b0a27792b6a66aabe1346cf6a Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Thu, 18 Aug 2016 23:00:09 +0530 Subject: [PATCH 39/51] Makes SOCK_CLOEXEC 0 when SOCK_CLOEXEC is not defined to pass test case 01-internal/18-listen_stop on darwin. --- tests/01-internal/utils.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/01-internal/utils.c b/tests/01-internal/utils.c index 7df639d8..34524a1a 100644 --- a/tests/01-internal/utils.c +++ b/tests/01-internal/utils.c @@ -15,8 +15,6 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -#define _DARWIN_C_SOURCE - #include "utils.h" #include #include @@ -29,7 +27,7 @@ #include #ifndef SOCK_CLOEXEC -#define SOCK_CLOEXEC O_CLOEXEC +#define SOCK_CLOEXEC 0 #endif int connect_to(const char *addr, const char *port){ From 3390bd7e4598b16d9e369217248d25db70693f15 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Fri, 19 Aug 2016 01:15:02 +0530 Subject: [PATCH 40/51] Uses PAM CMake Module --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d9bce50..cea56f54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,13 +124,13 @@ if (${ONION_USE_XML2}) endif(${ONION_USE_XML2}) if (${ONION_USE_PAM}) - find_library(PAM_LIB NAMES pam PATH ${LIBPATH}) - if (PAM_LIB) + find_package(PAM) + if (PAM_FOUND) set(PAM_ENABLED true) - message(STATUS "pam found. PAM support is compiled in in handlers.") - else (PAM_LIB) - message("pam not found. No PAM support.") - endif (PAM_LIB) + message(STATUS "PAM support is compiled in in handlers.") + else (PAM_FOUND) + message("No PAM support.") + endif (PAM_FOUND) endif (${ONION_USE_PAM}) if (${ONION_USE_PNG}) From dcbdce5f60ea1c0169e77ee0da2ae9f895a7238f Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Fri, 19 Aug 2016 01:16:42 +0530 Subject: [PATCH 41/51] Fixes a typo in PAM found status message --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cea56f54..b8dd8bff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,7 +127,7 @@ if (${ONION_USE_PAM}) find_package(PAM) if (PAM_FOUND) set(PAM_ENABLED true) - message(STATUS "PAM support is compiled in in handlers.") + message(STATUS "PAM support is compiled in handlers.") else (PAM_FOUND) message("No PAM support.") endif (PAM_FOUND) From 2693ba2ab745f0d31c4abf9f362f930d2b9aa3fd Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Fri, 19 Aug 2016 01:34:02 +0530 Subject: [PATCH 42/51] Fixes #204 Fix: Takes another variable expected_result and sprintf the same format and the variable in it and check it with the onion_response_printf. Since both will follow the same implementation will give the same result if the test case works. --- tests/01-internal/03-response.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/01-internal/03-response.c b/tests/01-internal/03-response.c index def24b1f..7d6cba3b 100644 --- a/tests/01-internal/03-response.c +++ b/tests/01-internal/03-response.c @@ -182,6 +182,7 @@ void t05_printf(){ onion_add_listen_point(server,NULL,NULL,onion_buffer_listen_point_new()); onion_request *request; char buffer[4096]; + char expected_result[4096]; memset(buffer,0,sizeof(buffer)); request=onion_request_new(server->listen_points[0]); @@ -196,7 +197,8 @@ void t05_printf(){ onion_request_free(request); onion_free(server); - FAIL_IF_NOT_STRSTR(buffer, "Hello world 123 (nil)"); + sprintf(expected_result, "%s %d %p", "Hello world", 123, NULL); + FAIL_IF_NOT_STRSTR(buffer, expected_result); END_LOCAL(); } From ec1c9ea2030029337101423578d82af205dfb4f0 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Fri, 19 Aug 2016 01:39:40 +0530 Subject: [PATCH 43/51] Fixes #206 --- tests/01-internal/14-websockets.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/01-internal/14-websockets.c b/tests/01-internal/14-websockets.c index 25645c8c..c5b8b606 100644 --- a/tests/01-internal/14-websockets.c +++ b/tests/01-internal/14-websockets.c @@ -187,7 +187,7 @@ void t02_websocket_server_w_ws(){ void t03_websocket_server_receive_small_packet(){ INIT_LOCAL(); int length = 0; - char *buffer = NULL, buffer2[114]; + char *buffer = NULL, buffer2[115]; memset(&ws_status,0,sizeof(ws_status)); onion *o=websocket_server_new(); onion_request *req=websocket_start_handshake(o); @@ -201,7 +201,7 @@ void t03_websocket_server_receive_small_packet(){ onion_websocket_read(ws, (char *)&buffer2, 120); - buffer2[113] = '\0'; + buffer2[114] = '\0'; FAIL_IF_NOT_EQUAL_STR(buffer2, "Some UTF-8-encoded chars which will be cut at the 117th char so I write some gap-filling text with no meaning unti"); onion_websocket_free(ws); From 192de8509ab24a72f9f9424c687c42388ec2964b Mon Sep 17 00:00:00 2001 From: Anurag Agarwal Date: Thu, 18 Aug 2016 20:36:01 +0000 Subject: [PATCH 44/51] Fixes typo in looking out for Cairo --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8dd8bff..9156a90a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,7 +138,7 @@ if (${ONION_USE_PNG}) if (PNG_FOUND) set(PNG_ENABLED true) message(STATUS "libpng found. png support is compiled in at extras.") - find_package(CAIRO) + find_package(Cairo) if (CAIRO_FOUND) set(CAIRO_ENABLED true) message(STATUS "Adding cairo examples.") From c61454f44aae663f297311dd84bbc63aefd18786 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Fri, 19 Aug 2016 02:22:34 +0530 Subject: [PATCH 45/51] Adds FindIntl.cmake for supporting earlier versions of CMake --- CMakeLists.txt | 8 ++-- CMakeModules/FindIntl.cmake | 64 +++++++++++++++++++++++++++++ examples/ofileserver/CMakeLists.txt | 2 +- tests/01-internal/CMakeLists.txt | 2 +- tests/07-tools/CMakeLists.txt | 2 +- 5 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 CMakeModules/FindIntl.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f9cc7100..efcc9dd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,13 +200,13 @@ if (${ONION_USE_SYSTEMD}) endif(${ONION_USE_SYSTEMD}) find_package(Intl) -if (Intl_FOUND) +if (INTL_FOUND) set(GETTEXT_ENABLED true) - include_directories(${Intl_INCLUDE_DIRS}) + include_directories(${INTL_INCLUDE_DIRS}) message(STATUS "gettext support is compiled in otemplate.") -else (Intl_FOUND) +else (INTL_FOUND) message(STATUS "No gettext support.") -endif (Intl_FOUND) +endif (INTL_FOUND) FIND_PROGRAM(MD2MAN md2man-roff) if(MD2MAN) diff --git a/CMakeModules/FindIntl.cmake b/CMakeModules/FindIntl.cmake new file mode 100644 index 00000000..80f872ad --- /dev/null +++ b/CMakeModules/FindIntl.cmake @@ -0,0 +1,64 @@ +#.rst: +# FindIntl +# -------- +# +# Find the Gettext libintl headers and libraries. +# +# This module reports information about the Gettext libintl +# installation in several variables. General variables:: +# +# INTL_FOUND - true if the libintl headers and libraries were found +# INTL_INCLUDE_DIRS - the directory containing the libintl headers +# INTL_LIBRARIES - libintl libraries to be linked +# +# The following cache variables may also be set:: +# +# INTL_INCLUDE_DIR - the directory containing the libintl headers +# INTL_LIBRARY - the libintl library (if any) +# +# .. note:: +# On some platforms, such as Linux with GNU libc, the gettext +# functions are present in the C standard library and libintl +# is not required. ``INTL_LIBRARIES`` will be empty in this +# case. +# +# .. note:: +# If you wish to use the Gettext tools (``msgmerge``, +# ``msgfmt``, etc.), use :module:`FindGettext`. + + +# Written by Roger Leigh + +#============================================================================= +# Copyright 2014 Roger Leigh +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# Find include directory +find_path(INTL_INCLUDE_DIR + NAMES "libintl.h" + DOC "libintl include directory") +mark_as_advanced(INTL_INCLUDE_DIR) + +# Find all INTL libraries +find_library(INTL_LIBRARY "intl" + DOC "libintl libraries (if not in the C library)") +mark_as_advanced(INTL_LIBRARY) + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Intl + REQUIRED_VARS INTL_INCLUDE_DIR INTL_LIBRARY + FAIL_MESSAGE "Failed to find Gettext libintl") + +if (INTL_FOUND) + set(INTL_INCLUDE_DIRS "${INTL_INCLUDE_DIR}") + set(INTL_LIBRARIES "${INTL_LIBRARY}") +endif () diff --git a/examples/ofileserver/CMakeLists.txt b/examples/ofileserver/CMakeLists.txt index 70bd5af3..151100a9 100644 --- a/examples/ofileserver/CMakeLists.txt +++ b/examples/ofileserver/CMakeLists.txt @@ -45,7 +45,7 @@ add_executable(ofileserver fileserver.c fileserver_html.c) target_link_libraries(ofileserver onion_static m) if (GETTEXT_ENABLED) - target_link_libraries(ofileserver ${Intl_LIBRARIES}) + target_link_libraries(ofileserver ${INTL_LIBRARIES}) endif (GETTEXT_ENABLED) find_package(ZLIB) diff --git a/tests/01-internal/CMakeLists.txt b/tests/01-internal/CMakeLists.txt index a274138d..9367d6ed 100644 --- a/tests/01-internal/CMakeLists.txt +++ b/tests/01-internal/CMakeLists.txt @@ -88,7 +88,7 @@ add_custom_command( ) target_link_libraries(13-otemplates onion) if (GETTEXT_ENABLED) - target_link_libraries(13-otemplates ${Intl_LIBRARIES}) + target_link_libraries(13-otemplates ${INTL_LIBRARIES}) endif (GETTEXT_ENABLED) add_test(internal-otemplates 13-otemplates) endif (OTEMPLATE) diff --git a/tests/07-tools/CMakeLists.txt b/tests/07-tools/CMakeLists.txt index fb23e3d3..e4b2f8b2 100644 --- a/tests/07-tools/CMakeLists.txt +++ b/tests/07-tools/CMakeLists.txt @@ -33,7 +33,7 @@ add_custom_command( add_executable(01-otemplate 01-otemplate.c test_html.c external_html.c extended_html.c base_html.c) target_link_libraries(01-otemplate onion_static) if (GETTEXT_ENABLED) - target_link_libraries(01-otemplate ${Intl_LIBRARIES}) + target_link_libraries(01-otemplate ${INTL_LIBRARIES}) endif (GETTEXT_ENABLED) # add_executable(02-test 02-test.cpp test_html.c external_html.c extended_html.c base_html.c) From 49aeb70a69911b6ebdc7dc7857aab6c6cc0cfce2 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Fri, 19 Aug 2016 07:51:56 +0530 Subject: [PATCH 46/51] Adds a condition for certtool, in linux gnutls certtool is saved with name certtool while in Mac OSX it saves with name gnutls-certtool --- tests/01-internal/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/01-internal/CMakeLists.txt b/tests/01-internal/CMakeLists.txt index 9367d6ed..60c9761c 100644 --- a/tests/01-internal/CMakeLists.txt +++ b/tests/01-internal/CMakeLists.txt @@ -21,7 +21,11 @@ add_test(internal-server 05-server) if (GNUTLS_ENABLED) IF (CURL) message(STATUS "Looking for gnutls-certtool") -find_program(GNUTLS_CERTTOOL gnutls-certtool) +if (APPLE) + find_program(GNUTLS_CERTTOOL gnutls-certtool) +else (APPLE) + find_program(GNUTLS_CERTTOOL certtool) +endif (APPLE) IF (GNUTLS_CERTTOOL) message(STATUS "Found gnutls-certtool compiling all tests") add_custom_command( From 381c76ff26255e7781a35f3f524471f94113fd91 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Fri, 19 Aug 2016 07:59:53 +0530 Subject: [PATCH 47/51] Changes condition of LibIntl as is not needed in linux --- CMakeModules/FindIntl.cmake | 10 +++++++--- examples/ofileserver/CMakeLists.txt | 4 +++- tests/01-internal/CMakeLists.txt | 4 +++- tests/07-tools/CMakeLists.txt | 5 ++++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CMakeModules/FindIntl.cmake b/CMakeModules/FindIntl.cmake index 80f872ad..c89bc570 100644 --- a/CMakeModules/FindIntl.cmake +++ b/CMakeModules/FindIntl.cmake @@ -48,17 +48,21 @@ find_path(INTL_INCLUDE_DIR DOC "libintl include directory") mark_as_advanced(INTL_INCLUDE_DIR) -# Find all INTL libraries +# Find all Intl libraries find_library(INTL_LIBRARY "intl" DOC "libintl libraries (if not in the C library)") mark_as_advanced(INTL_LIBRARY) include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(Intl - REQUIRED_VARS INTL_INCLUDE_DIR INTL_LIBRARY + REQUIRED_VARS INTL_INCLUDE_DIR FAIL_MESSAGE "Failed to find Gettext libintl") if (INTL_FOUND) set(INTL_INCLUDE_DIRS "${INTL_INCLUDE_DIR}") - set(INTL_LIBRARIES "${INTL_LIBRARY}") + if (INTL_LIBRARY) + set(INTL_LIBRARIES "${INTL_LIBRARY}") + else () + unset(INTL_LIBRARIES) + endif () endif () diff --git a/examples/ofileserver/CMakeLists.txt b/examples/ofileserver/CMakeLists.txt index 151100a9..509593df 100644 --- a/examples/ofileserver/CMakeLists.txt +++ b/examples/ofileserver/CMakeLists.txt @@ -45,7 +45,9 @@ add_executable(ofileserver fileserver.c fileserver_html.c) target_link_libraries(ofileserver onion_static m) if (GETTEXT_ENABLED) - target_link_libraries(ofileserver ${INTL_LIBRARIES}) + if (INTL_LIBRARIES) + target_link_libraries(ofileserver ${INTL_LIBRARIES}) + endif (INTL_LIBRARIES) endif (GETTEXT_ENABLED) find_package(ZLIB) diff --git a/tests/01-internal/CMakeLists.txt b/tests/01-internal/CMakeLists.txt index 60c9761c..4f0c22bc 100644 --- a/tests/01-internal/CMakeLists.txt +++ b/tests/01-internal/CMakeLists.txt @@ -92,7 +92,9 @@ add_custom_command( ) target_link_libraries(13-otemplates onion) if (GETTEXT_ENABLED) - target_link_libraries(13-otemplates ${INTL_LIBRARIES}) + if (INTL_LIBRARIES) + target_link_libraries(13-otemplates ${INTL_LIBRARIES}) + endif (INTL_LIBRARIES) endif (GETTEXT_ENABLED) add_test(internal-otemplates 13-otemplates) endif (OTEMPLATE) diff --git a/tests/07-tools/CMakeLists.txt b/tests/07-tools/CMakeLists.txt index e4b2f8b2..e4c95d59 100644 --- a/tests/07-tools/CMakeLists.txt +++ b/tests/07-tools/CMakeLists.txt @@ -33,9 +33,12 @@ add_custom_command( add_executable(01-otemplate 01-otemplate.c test_html.c external_html.c extended_html.c base_html.c) target_link_libraries(01-otemplate onion_static) if (GETTEXT_ENABLED) - target_link_libraries(01-otemplate ${INTL_LIBRARIES}) + if (INTL_LIBRARIES) + target_link_libraries(01-otemplate ${INTL_LIBRARIES}) + endif (INTL_LIBRARIES) endif (GETTEXT_ENABLED) + # add_executable(02-test 02-test.cpp test_html.c external_html.c extended_html.c base_html.c) # target_link_libraries(02-test onion_static onion_handlers onioncpp) From 80f65771f1c301107c6a89787f3c73d020836afa Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Fri, 19 Aug 2016 09:56:15 +0530 Subject: [PATCH 48/51] Adds osx in .travis.yml Adds ./install-dependencies.sh to install dependencies needed for osx Make some other changes in .travis.yml --- .travis.yml | 31 +++++++++++++++---------------- install-dependencies.sh | 23 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 install-dependencies.sh diff --git a/.travis.yml b/.travis.yml index 773513fd..e6895f74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,9 @@ language: cpp +os: + - linux + - osx + compiler: - gcc - clang @@ -9,39 +13,34 @@ sudo: false git: depth: 1 -env: - global: - - LLVM_VERSION=3.7.0 - - LLVM_ARCHIVE_PATH=$HOME/clang+llvm.tar.xz - before_install: - - wget http://llvm.org/releases/$LLVM_VERSION/clang+llvm-$LLVM_VERSION-x86_64-linux-gnu-ubuntu-14.04.tar.xz -O $LLVM_ARCHIVE_PATH - - mkdir $HOME/clang+llvm - - tar xf $LLVM_ARCHIVE_PATH -C $HOME/clang+llvm --strip-components 1 - - export PATH=$HOME/clang+llvm/bin:$PATH - - ln -s $HOME/clang+llvm/bin/clang++ $HOME/clang+llvm/bin/clang++-3.7 + - gem install md2man --no-rdoc --no-ri + - chmod +x ./install-dependencies.sh + - ./install-dependencies.sh addons: apt: sources: - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.7 packages: - - g++-5 - gcc-5 + - g++-5 + - clang-3.7 + - gettext - libhiredis-dev install: # install some packages from Ubuntu's default sources - - if [ "$CXX" = "g++" ]; then export CXX="g++-5" CC="gcc-5"; fi - - if [ "$CXX" = "clang++" ]; then export CXX="clang++-3.7" CC="clang-3.7"; fi + - if [[ $CXX == 'g++' ]]; then export CXX="g++-5" CC="gcc-5"; fi + - if [[ $CXX == 'clang++' ]]; then export CXX="clang++-3.7"; fi +#FIXME: removes -Werror flag for osx check script: # make distcheck still does not work on travis - mkdir build && cd build && cmake .. - -DCMAKE_C_FLAGS="-Werror" - -DCMAKE_CXX_FLAGS="-Werror" && make VERBOSE=1 && (make test || true) @@ -49,4 +48,4 @@ after_script: - if test -f ./Testing/Temporary/LastTest.log; then echo "cat test logs:"; cat ./Testing/Temporary/LastTest.log; - fi + fi \ No newline at end of file diff --git a/install-dependencies.sh b/install-dependencies.sh new file mode 100644 index 00000000..107556c5 --- /dev/null +++ b/install-dependencies.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +if [[ $TRAVIS_OS_NAME == 'osx' ]]; then + + # Install some custom requirements on OS X + # e.g. brew install pyenv-virtualenv + + brew update; + brew tap homebrew/versions; + brew install gnutls; + brew install libgcrypt; + brew install hiredis; + brew install bdw-gc; + brew install libev; + brew install gettext; + + #FIXME: temporary hack for mac as gettext is not detected otherwise + ln -s /usr/local/Cellar/gettext/*/lib/libintl.dylib /usr/local/lib/; + ln -s /usr/local/Cellar/gettext/*/include/libintl.h /usr/local/include; + + if [[ $CXX == 'g++' ]]; then brew install gcc5 --enable-cxx; fi + if [[ $CXX == 'clang++' ]]; then brew install llvm37 --enable-cxx; fi +fi \ No newline at end of file From af87d334e3eddf3c6bee9976642089f1d71b579c Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Sat, 20 Aug 2016 20:18:03 +0530 Subject: [PATCH 49/51] onioncpp_static links to correct library --- src/bindings/cpp/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/cpp/CMakeLists.txt b/src/bindings/cpp/CMakeLists.txt index 2b379a3a..df927824 100644 --- a/src/bindings/cpp/CMakeLists.txt +++ b/src/bindings/cpp/CMakeLists.txt @@ -6,7 +6,7 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++0x") SET(INCLUDES_ONIONCPP onion.hpp dict.hpp request.hpp response.hpp url.hpp handler.hpp extrahandlers.hpp shortcuts.hpp exceptions.hpp listen_point.hpp http.hpp https.hpp mime.hpp) target_link_libraries(onioncpp onion) -target_link_libraries(onioncpp_static onioncpp_static) +target_link_libraries(onioncpp_static onion) MESSAGE(STATUS "Found include files ${INCLUDES_ONIONCPP}") From fce7f0f30ff6b2cfa6247ffe6a98d77efb63cd39 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Sat, 20 Aug 2016 20:51:24 +0530 Subject: [PATCH 50/51] Adds an extra if to check if the user has enabled PAM to avoid unnecessary warnings in examples --- examples/CMakeLists.txt | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index f80f80ae..5a8949e5 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,24 +1,26 @@ -if (PAM_ENABLED) - if (OPACK) - add_subdirectory(otop) - endif(OPACK) - add_subdirectory(basic) - add_subdirectory(fileserver) -else (PAM_ENABLED) - if (OPACK) - message(WARNING "Oterm without authentication support! May be very unsecure.") - else(OPACK) - message(WARNING "Oterm not compiled as there is no opack.") - endif (OPACK) +if (ONION_USE_PAM) + if (PAM_ENABLED) + if (OPACK) + add_subdirectory(otop) + endif(OPACK) + add_subdirectory(basic) + add_subdirectory(fileserver) + else (PAM_ENABLED) + if (OPACK) + message(WARNING "Oterm without authentication support! May be very unsecure.") + else(OPACK) + message(WARNING "Oterm not compiled as there is no opack.") + endif (OPACK) - message(WARNING "Some examples are disabled as you dont have PAM: otop, basic, fileserver.") -endif (PAM_ENABLED) + message(WARNING "Some examples are disabled as you dont have PAM: otop, basic, fileserver.") + endif (PAM_ENABLED) -if (OPACK) - if (CMAKE_SYSTEM_NAME STREQUAL "Linux") - add_subdirectory(oterm) - endif (CMAKE_SYSTEM_NAME STREQUAL "Linux") -endif (OPACK) + if (OPACK) + if (CMAKE_SYSTEM_NAME STREQUAL "Linux") + add_subdirectory(oterm) + endif (CMAKE_SYSTEM_NAME STREQUAL "Linux") + endif (OPACK) +endif (ONION_USE_PAM) add_subdirectory(post) From e84c52ec7caa8ca0c2f6ea6118ef960422808043 Mon Sep 17 00:00:00 2001 From: anuragagarwal561994 Date: Sat, 20 Aug 2016 21:00:19 +0530 Subject: [PATCH 51/51] Sets the value of CMAKE_MACOSX_RPATH to True --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index efcc9dd5..eb7cec71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required (VERSION 2.8) cmake_policy(VERSION 2.8) project(libonion) +set(CMAKE_MACOSX_RPATH 1) + # Some tweak parameters SET(ONION_USE_SSL true CACHE BOOL "Use SSL, requires GnuTLS") SET(ONION_USE_PAM true CACHE BOOL "Compile PAM handler. Needs libpam")