Skip to content

Commit

Permalink
Merge pull request #538 from JackBoosY/jack/update-cmake
Browse files Browse the repository at this point in the history
Update CMakeLists
  • Loading branch information
AlbertShown authored Jan 7, 2025
2 parents 0ff3b13 + d695c5b commit c9abbc9
Showing 1 changed file with 31 additions and 50 deletions.
81 changes: 31 additions & 50 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,69 +9,50 @@ set(CMAKE_CXX_STANDARD 11)
# Variables for library names, source files, etc.
set(WEBUI_OUT_LIB_NAME "webui-2")

# Platform and compiler specific settings
if(WIN32)

# Windows specific compiler flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DNO_SSL")

# Add Windows specific source files or flags here
# Example: set(SOURCE_FILES ${SOURCE_FILES} additional_windows_sources.c)

elseif(UNIX)
# Linux specific settings

# Linux specific compiler flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_SSL -w")

# Add Linux specific source files or flags here
# Example: set(SOURCE_FILES ${SOURCE_FILES} additional_linux_sources.c)
endif()

# Conditional compilation for TLS
option(WEBUI_USE_TLS "Enable TLS support" OFF)
if(WEBUI_USE_TLS)
# Add definitions and libraries for TLS
add_definitions(-DWEBUI_TLS)

if(WIN32)
# Windows TLS settings
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DWEBUI_TLS /DNO_SSL_DL /DOPENSSL_API_1_1")
# Specify the TLS library for Windows, if needed
# Example: target_link_libraries(webui_static PRIVATE ssl crypto)
else()
# Linux TLS settings
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWEBUI_TLS -DNO_SSL_DL -DOPENSSL_API_1_1")
# Specify the TLS library for Linux, if needed
# Example: target_link_libraries(webui_static PRIVATE ssl crypto)
endif()
find_package(OpenSSL REQUIRED)
set(WEBUI_OUT_LIB_NAME "webui-2-secure")
endif()

# Include directories
include_directories(include bridge)
add_subdirectory(src/civetweb)

# Source files (already filled)
set(SOURCE_FILES
src/civetweb/civetweb.c
src/webui.c
bridge/webui_bridge.h
)

# Library targets (static and dynamic)
add_library(webui_static STATIC ${SOURCE_FILES})
set_target_properties(webui_static PROPERTIES
OUTPUT_NAME ${WEBUI_OUT_LIB_NAME}-static
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/dist")
target_link_libraries(webui_static PRIVATE civetweb)
# Library targets
add_library(webui ${SOURCE_FILES})
target_include_directories(webui PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
target_compile_definitions(webui PUBLIC NDEBUG NO_CACHING NO_CGI USE_WEBSOCKET)

add_library(webui_dynamic SHARED ${SOURCE_FILES})
set_target_properties(webui_dynamic PROPERTIES
if(BUILD_SHARED_LIBS AND WIN32)
target_compile_definitions(webui PRIVATE CIVETWEB_DLL_EXPORTS PUBLIC CIVETWEB_DLL_IMPORTS)
endif()

if(WEBUI_USE_TLS)
target_compile_definitions(webui PUBLIC WEBUI_TLS NO_SSL_DL OPENSSL_API_1_1)
target_link_libraries(webui PRIVATE OpenSSL::SSL OpenSSL::Crypto)
else()
target_compile_definitions(webui PUBLIC NO_SSL)
endif()

set_target_properties(webui PROPERTIES
OUTPUT_NAME ${WEBUI_OUT_LIB_NAME}
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/dist")
target_link_libraries(webui_dynamic PRIVATE civetweb)
PREFIX "")

# Install headers
install(FILES include/webui.h include/webui.hpp DESTINATION include)

# Install targets
install(TARGETS webui_static webui_dynamic
install(TARGETS webui
EXPORT webui
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)

install(EXPORT webui
FILE webui-config.cmake
NAMESPACE webui::
DESTINATION share/webui
)

0 comments on commit c9abbc9

Please sign in to comment.