From 53823817cf556a079de0d5b6923735fd84b68ec1 Mon Sep 17 00:00:00 2001 From: kakwa Date: Fri, 27 Jan 2017 00:28:46 +0100 Subject: [PATCH] including module to include argp --- CMakeLists.txt | 5 +++- cmake/Findargp.cmake | 61 ++++++++++++++++++++++++++++++++++++++++++++ src/cmd/uts-server.c | 9 ++++++- 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 cmake/Findargp.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a1cec41..df2ff38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ endif() IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") set(SED_FREEBSD "*.c") + find_package(argp REQUIRED) ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") if(BUNDLE_CIVETWEB) @@ -60,7 +61,7 @@ if(BUNDLE_CIVETWEB) ) set(LIBCIVETWEB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/vendor/usr/include") set(LIBCIVETWEB_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/vendor/usr/lib/libcivetweb.a") - set (CMAKE_C_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -ldl -lpthread -lrt") + set (CMAKE_C_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -lpthread -lrt") else(BUNDLE_CIVETWEB) find_package(libcivetweb REQUIRED) endif(BUNDLE_CIVETWEB) @@ -71,6 +72,7 @@ include_directories( ./inc/ ${LIBCIVETWEB_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR} + ${ARGP_INCLUDE_DIR} ) add_executable(uts-server @@ -83,6 +85,7 @@ add_executable(uts-server target_link_libraries(uts-server ${OPENSSL_LIBRARIES} ${LIBCIVETWEB_LIBRARIES} + ${ARGP_LIBRARIES} ) INSTALL(TARGETS uts-server diff --git a/cmake/Findargp.cmake b/cmake/Findargp.cmake new file mode 100644 index 0000000..6ed4ad1 --- /dev/null +++ b/cmake/Findargp.cmake @@ -0,0 +1,61 @@ +# This file is part of CMake-argp. +# +# CMake-argp is free software: you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License along +# with this program. If not, see +# +# http://www.gnu.org/licenses/ +# +# +# Copyright (c) +# 2016 Alexander Haase +# + +include(FindPackageHandleStandardArgs) +include(CheckFunctionExists) + + +# Check if argp is included in libc: +set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET}) +set(CMAKE_REQUIRED_QUIET TRUE) + +check_function_exists("argp_parse" ARGP_IN_LIBC) +if (ARGP_IN_LIBC) + set(ARGP_LIBRARIES "c" CACHE STRING "ARGP libraries.") + +elseif (NOT ARGP_IN_LIBC) + unset(ARGP_IN_LIBC CACHE) + + find_library(ARGP_LIB "argp") + find_path(ARGP_INCLUDE_DIR argp.h PATH_SUFFIXES include) + mark_as_advanced(ARGP_LIB) + if (ARGP_LIB) + set(CMAKE_REQUIRED_LIBRARIES "${ARGP_LIB}") + check_function_exists("argp_parse" ARGP_EXTERNAL) + if (ARGP_EXTERNAL) + set(ARGP_LIBRARIES "${ARGP_LIB}" CACHE STRING "ARGP libraries.") + endif () + endif () +endif () + +set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE}) + + +find_package_handle_standard_args(argp + FOUND_VAR ARGP_FOUND + REQUIRED_VARS ARGP_LIBRARIES +) + + + +MESSAGE(STATUS "Find Header Directory for argp: " ${ARGP_INCLUDE_DIR}) +MESSAGE(STATUS "Find Dynamic Library for arpg: " ${ARGP_LIBRARIES}) + diff --git a/src/cmd/uts-server.c b/src/cmd/uts-server.c index 6f2e5db..44de33d 100644 --- a/src/cmd/uts-server.c +++ b/src/cmd/uts-server.c @@ -4,7 +4,11 @@ #include #include #include +#ifdef BSD +#include +#else #include +#endif /* BSD */ #include #include #include @@ -94,8 +98,11 @@ int main(int argc, char **argv) { // other uts-server files (ca, certs, etc) can be declared relatively to the // configuration file char *conf_wd = strdup(conf_fp); +#ifdef BSD + conf_wd = dirname(conf_wd); +#else dirname(conf_wd); - +#endif /* BSD */ if (args.daemonize) skeleton_daemon();