Skip to content

Commit

Permalink
fix static build
Browse files Browse the repository at this point in the history
Add BUILD_SHARED_LIBS and BUILD_STATIC_LIBS to allow the user to build a
static only version

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  • Loading branch information
ffontaine committed Apr 6, 2020
1 parent b2501c3 commit 4d0f435
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
7 changes: 6 additions & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
include_directories(${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/buffer ${CMAKE_BINARY_DIR}/src ${LIBEV_INCLUDE_DIR})

add_executable(example example.c)
target_link_libraries(example uhttpd ${LIBEV_LIBRARY})

if(BUILD_SHARED_LIBS)
target_link_libraries(example uhttpd ${LIBEV_LIBRARY})
else()
target_link_libraries(example uhttpd_s ${LIBEV_LIBRARY})
endif()
37 changes: 25 additions & 12 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ endif()

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

option(BUILD_SHARED_LIBS "Build shared library" ON)
option(BUILD_STATIC_LIBS "Build static library" ON)

if(NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
message(FATAL_ERROR "BUILD_SHARED_LIBS and BUILD_STATIC_LIBS can't be OFF at the same time, please select at least one of them")
endif()

set(UHTTPD_SSL_SUPPORT_CONFIG 1)
option(UHTTPD_SSL_SUPPORT "SSL support" ON)

Expand Down Expand Up @@ -96,13 +103,25 @@ else()
endif()
endif()

add_library(uhttpd SHARED ${SOURCE_FILES})
set_target_properties(uhttpd PROPERTIES VERSION ${UHTTPD_VERSION_MAJOR}.${UHTTPD_VERSION_MINOR}.${UHTTPD_VERSION_PATCH})
target_link_libraries(uhttpd ${EXTRA_LIBS})
if(BUILD_SHARED_LIBS)
add_library(uhttpd SHARED ${SOURCE_FILES})
set_target_properties(uhttpd PROPERTIES VERSION ${UHTTPD_VERSION_MAJOR}.${UHTTPD_VERSION_MINOR}.${UHTTPD_VERSION_PATCH})
target_link_libraries(uhttpd ${EXTRA_LIBS})
install(
TARGETS uhttpd
LIBRARY DESTINATION lib
)
endif()

add_library(uhttpd_s STATIC ${SOURCE_FILES})
set_target_properties(uhttpd_s PROPERTIES OUTPUT_NAME uhttpd)
target_link_libraries(uhttpd_s ${EXTRA_LIBS})
if(BUILD_STATIC_LIBS)
add_library(uhttpd_s STATIC ${SOURCE_FILES})
set_target_properties(uhttpd_s PROPERTIES OUTPUT_NAME uhttpd)
target_link_libraries(uhttpd_s ${EXTRA_LIBS})
install(
TARGETS uhttpd_s
ARCHIVE DESTINATION lib
)
endif()

# 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)
Expand All @@ -123,12 +142,6 @@ install(
include/uhttpd
)

install(
TARGETS uhttpd uhttpd_s
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

message(STATUS "UHTTPD_VERSION: ${UHTTPD_VERSION_MAJOR}.${UHTTPD_VERSION_MINOR}.${UHTTPD_VERSION_PATCH}")
message(STATUS "UHTTPD_SSL_SUPPORT: ${SSL_NAME}")

0 comments on commit 4d0f435

Please sign in to comment.