Skip to content

Commit f53f7ff

Browse files
authored
Merge pull request #586 from Juff-Ma/main
Update CMake build system and introduce Conan and VCPKG
2 parents 3d7b3e0 + 87064ed commit f53f7ff

File tree

4 files changed

+113
-14
lines changed

4 files changed

+113
-14
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,15 @@ Thumbs.db
125125
**/cmake_install.cmake
126126
**/CMakeCache.txt
127127
**/CMakeFiles/
128+
CMakeUserPresets.json
128129
.zig-cache
130+
131+
# Conan
132+
**/compressor
133+
**/conan-*
134+
**/cmake-build-*
135+
**/deactivate_conanbuildenv*
136+
137+
# vcpkg
138+
vcpkg-manifest-install.log
139+
vcpkg_installed/

CMakeLists.txt

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,57 @@
1-
cmake_minimum_required(VERSION 3.10)
1+
cmake_minimum_required(VERSION 3.18)
22

33
# Project name
4-
project(WebUILibrary)
4+
project(WebUILibrary
5+
VERSION 2.5.0
6+
DESCRIPTION "Use any web browser or WebView as GUI, with your preferred language in the backend and modern web technologies in the frontend, all in a lightweight portable library."
7+
HOMEPAGE_URL "https://webui.me/")
58

6-
# Set C++ standard
9+
# Set C & C++ standard
710
set(CMAKE_CXX_STANDARD 17)
811
set(CMAKE_CXX_STANDARD_REQUIRED ON)
12+
set(CMAKE_C_STANDARD 99)
13+
set(CMAKE_C_STANDARD_REQUIRED ON)
914

1015
# Variables for library names, source files, etc.
11-
set(WEBUI_OUT_LIB_NAME "webui-2")
16+
set(WEBUI_DEFAULT_OUT_LIB_NAME "webui-2")
1217

1318
# Conditional compilation for TLS
1419
option(WEBUI_USE_TLS "Enable TLS support" OFF)
15-
if(WEBUI_USE_TLS)
16-
find_package(OpenSSL REQUIRED)
17-
set(WEBUI_OUT_LIB_NAME "webui-2-secure")
20+
if (WEBUI_USE_TLS)
21+
find_package(OpenSSL REQUIRED)
22+
set(WEBUI_DEFAULT_OUT_LIB_NAME "webui-2-secure")
1823
endif()
1924

25+
if (NOT BUILD_SHARED_LIBS)
26+
set(WEBUI_DEFAULT_OUT_LIB_NAME "${WEBUI_DEFAULT_OUT_LIB_NAME}-static")
27+
endif()
28+
29+
# Output library name
30+
set(WEBUI_OUT_LIB_NAME "${WEBUI_DEFAULT_OUT_LIB_NAME}" CACHE STRING "Name of the output library")
31+
2032
# Source files (already filled)
2133
set(SOURCE_FILES
2234
src/civetweb/civetweb.c
2335
src/webui.c
2436
)
37+
if (APPLE)
38+
# enable macos webview
39+
enable_language(OBJC)
40+
set(CMAKE_OBJC_STANDARD 11)
41+
list(APPEND SOURCE_FILES src/webview/wkwebview.m)
42+
endif()
2543

2644
# Library targets
2745
add_library(webui ${SOURCE_FILES})
2846
target_include_directories(webui PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
29-
target_compile_definitions(webui PUBLIC NDEBUG NO_CACHING NO_CGI USE_WEBSOCKET)
47+
target_compile_definitions(webui PUBLIC NO_CACHING NO_CGI USE_WEBSOCKET
48+
"$<$<CONFIG:Debug>:WEBUI_LOG>" "$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")
3049

31-
if(BUILD_SHARED_LIBS AND WIN32)
50+
if (BUILD_SHARED_LIBS AND WIN32)
3251
target_compile_definitions(webui PRIVATE CIVETWEB_DLL_EXPORTS PUBLIC CIVETWEB_DLL_IMPORTS)
3352
endif()
3453

35-
if(WEBUI_USE_TLS)
54+
if (WEBUI_USE_TLS)
3655
target_compile_definitions(webui PUBLIC WEBUI_TLS NO_SSL_DL OPENSSL_API_1_1)
3756
target_link_libraries(webui PRIVATE OpenSSL::SSL OpenSSL::Crypto)
3857
else()
@@ -41,11 +60,16 @@ endif()
4160

4261
if (WIN32)
4362
target_link_libraries(webui PRIVATE ws2_32 user32 shell32 ole32)
44-
endif ()
63+
elseif (APPLE)
64+
# link required frameworks
65+
find_library(COCOA_FRAMEWORK Cocoa REQUIRED)
66+
find_library(WEBKIT_FRAMEWORK WebKit REQUIRED)
67+
68+
target_link_libraries(webui PRIVATE ${COCOA_FRAMEWORK} ${WEBKIT_FRAMEWORK})
69+
endif()
4570

4671
set_target_properties(webui PROPERTIES
47-
OUTPUT_NAME ${WEBUI_OUT_LIB_NAME}
48-
PREFIX "")
72+
OUTPUT_NAME ${WEBUI_OUT_LIB_NAME})
4973

5074
# Install headers
5175
install(FILES include/webui.h include/webui.hpp DESTINATION include)
@@ -54,7 +78,8 @@ install(FILES include/webui.h include/webui.hpp DESTINATION include)
5478
install(TARGETS webui
5579
EXPORT webui
5680
ARCHIVE DESTINATION lib
57-
LIBRARY DESTINATION lib)
81+
LIBRARY DESTINATION lib
82+
RUNTIME DESTINATION bin)
5883

5984
install(EXPORT webui
6085
FILE webui-config.cmake

conanfile.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from conan import ConanFile
2+
from conan.tools.cmake import CMake, CMakeToolchain
3+
4+
class WebuiConan(ConanFile):
5+
name = "webui"
6+
version = "2.5.0-beta.4"
7+
license = "MIT"
8+
url = "https://github.com/webui-dev/webui"
9+
homepage = "https://webui.me"
10+
description = "Use any web browser or WebView as GUI, with your preferred language in the backend and modern web technologies in the frontend, all in a lightweight portable library."
11+
12+
settings = "os", "compiler", "build_type", "arch"
13+
options = {"tls": [True, False], "shared": [True, False]}
14+
default_options = {"tls": False, "shared": False}
15+
16+
generators = "CMakeDeps"
17+
18+
def generate(self):
19+
tc = CMakeToolchain(self)
20+
tc.variables["WEBUI_USE_TLS"] = self.options.tls
21+
tc.variables["BUILD_SHARED_LIBS"] = self.options.shared
22+
tc.generate()
23+
24+
def build(self):
25+
cmake = CMake(self)
26+
cmake.configure()
27+
cmake.build()
28+
29+
def requirements(self):
30+
self.tool_requires("cmake/[>=3.18.0]")
31+
32+
if self.options.tls:
33+
self.requires("openssl/[>3.0.0]")

vcpkg.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "webui",
3+
"version": "2.5.0-beta.4",
4+
"description": "Use any web browser or WebView as GUI, with your preferred language in the backend and modern web technologies in the frontend, all in a lightweight portable library.",
5+
"license": "MIT",
6+
"homepage": "https://webui.me",
7+
"dependencies": [
8+
{
9+
"name": "webview2",
10+
"platform": "windows"
11+
},
12+
{
13+
"name": "vcpkg-cmake",
14+
"host": true
15+
},
16+
{
17+
"name": "vcpkg-cmake-config",
18+
"host": true
19+
}
20+
],
21+
"features": {
22+
"tls": {
23+
"description": "Enable TLS support",
24+
"dependencies": [{
25+
"name": "openssl",
26+
"version>=": "3.0.0"
27+
}]
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)