Skip to content

Commit

Permalink
build: Check if libdl exists in the system
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
  • Loading branch information
zhaojh329 committed Apr 4, 2020
1 parent df0610c commit ac25a30
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/CMakeLists.txt
Expand Up @@ -8,10 +8,18 @@ set(UHTTPD_VERSION_PATCH 1)

# Check the third party Libraries
find_package(Libev REQUIRED)
find_library(LIBDL dl)

include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/buffer ${CMAKE_CURRENT_BINARY_DIR} ${LIBEV_INCLUDE_DIR})

set(EXTRA_LIBS ${LIBEV_LIBRARY} dl m)
set(EXTRA_LIBS ${LIBEV_LIBRARY} m)

if(NOT ${LIBDL} STREQUAL "LIBDL-NOTFOUND")
message(STATUS "Found Libdl: ${LIBDL}")
list(APPEND EXTRA_LIBS ${LIBDL})
add_definitions(-DHAVE_DLOPEN)
endif()

set(SOURCE_FILES uhttpd.c log.c connection.c buffer/buffer.c http-parser/http_parser.c ssl.c)

set(UHTTPD_SSL_SUPPORT_CONFIG 1)
Expand Down Expand Up @@ -100,7 +108,9 @@ target_link_libraries(uhttpd_s ${EXTRA_LIBS})
# configure a header file to pass some of the CMake settings to the source code
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)

add_subdirectory(plugins)
if(NOT ${LIBDL} STREQUAL "LIBDL-NOTFOUND")
add_subdirectory(plugins)
endif()

install(
FILES
Expand Down
9 changes: 8 additions & 1 deletion src/uhttpd.c
Expand Up @@ -26,9 +26,11 @@
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <dlfcn.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#ifdef HAVE_DLOPEN
#include <dlfcn.h>
#endif

#include "uhttpd.h"
#include "utils.h"
Expand Down Expand Up @@ -113,6 +115,7 @@ static int uh_server_ssl_init(struct uh_server *srv, const char *cert, const cha

static int uh_load_plugin(struct uh_server *srv, const char *path)
{
#ifdef HAVE_DLOPEN
struct uh_plugin *p;
void *dlh;

Expand Down Expand Up @@ -143,6 +146,10 @@ static int uh_load_plugin(struct uh_server *srv, const char *path)
srv->plugins = p;

return 0;
#else
uh_log_err("Not support plugin\n");
return -1;
#endif
}

int uh_server_init(struct uh_server *srv, struct ev_loop *loop, const char *host, int port)
Expand Down

0 comments on commit ac25a30

Please sign in to comment.