Skip to content

Commit 55caecb

Browse files
Use the guarded/direct export of header approach
1 parent 2e595ca commit 55caecb

File tree

7 files changed

+72
-556
lines changed

7 files changed

+72
-556
lines changed

.github/workflows/update-module-exports.yml

Lines changed: 0 additions & 81 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,16 @@ if(HTTPLIB_COMPILE)
248248
$<BUILD_INTERFACE:${_httplib_build_includedir}/httplib.h>
249249
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/httplib.h>
250250
)
251+
252+
# Add C++20 module support if requested
253+
if(HTTPLIB_BUILD_MODULES)
254+
target_sources(${PROJECT_NAME}
255+
PUBLIC
256+
FILE_SET CXX_MODULES FILES
257+
"${_httplib_build_includedir}/httplib.cppm"
258+
)
259+
endif()
260+
251261
set_target_properties(${PROJECT_NAME}
252262
PROPERTIES
253263
VERSION ${${PROJECT_NAME}_VERSION}
@@ -264,8 +274,12 @@ endif()
264274
# Only useful if building in-tree, versus using it from an installation.
265275
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
266276

267-
# Require C++11
268-
target_compile_features(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC} cxx_std_11)
277+
# Require C++11, or C++20 if modules are enabled
278+
if(HTTPLIB_BUILD_MODULES)
279+
target_compile_features(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC} cxx_std_20)
280+
else()
281+
target_compile_features(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC} cxx_std_11)
282+
endif()
269283

270284
target_include_directories(${PROJECT_NAME} SYSTEM ${_INTERFACE_OR_PUBLIC}
271285
$<BUILD_INTERFACE:${_httplib_build_includedir}>
@@ -337,7 +351,11 @@ if(HTTPLIB_INSTALL)
337351
# Creates the export httplibTargets.cmake
338352
# This is strictly what holds compilation requirements
339353
# and linkage information (doesn't find deps though).
340-
install(TARGETS ${PROJECT_NAME} EXPORT httplibTargets)
354+
if(HTTPLIB_BUILD_MODULES)
355+
install(TARGETS ${PROJECT_NAME} EXPORT httplibTargets FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/httplib/modules CXX_MODULES_BMI DESTINATION ${CMAKE_INSTALL_LIBDIR}/httplib/modules)
356+
else()
357+
install(TARGETS ${PROJECT_NAME} EXPORT httplibTargets)
358+
endif()
341359

342360
install(FILES "${_httplib_build_includedir}/httplib.h" TYPE INCLUDE)
343361

@@ -366,14 +384,13 @@ if(HTTPLIB_INSTALL)
366384
include(CPack)
367385
endif()
368386

369-
if(HTTPLIB_TEST)
370-
include(CTest)
371-
add_subdirectory(test)
372-
endif()
373-
374387
if(HTTPLIB_BUILD_MODULES)
375388
if(NOT HTTPLIB_COMPILE)
376389
message(FATAL_ERROR "HTTPLIB_BUILD_MODULES requires HTTPLIB_COMPILE to be ON.")
377390
endif()
378-
add_subdirectory(modules)
391+
endif()
392+
393+
if(HTTPLIB_TEST)
394+
include(CTest)
395+
add_subdirectory(test)
379396
endif()

README.md

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,43 +1275,6 @@ $ ./split.py
12751275
Wrote out/httplib.h and out/httplib.cc
12761276
```
12771277

1278-
Build C++ Modules
1279-
-----------------
1280-
1281-
If using CMake, it is possible to build this as a C++20 module using the `HTTPLIB_BUILD_MODULES` option (which requires `HTTPLIB_COMPILE` to be enabled).
1282-
1283-
#### Server (Multi-threaded)
1284-
```cpp
1285-
import httplib;
1286-
1287-
using httplib::Request;
1288-
using httplib::Response;
1289-
using httplib::SSLServer;
1290-
1291-
SSLServer svr;
1292-
1293-
svr.Get("/hi", []([[maybe_unused]] const Request& req, Response& res) -> void {
1294-
res.set_content("Hello World!", "text/plain");
1295-
});
1296-
1297-
svr.listen("0.0.0.0", 8080);
1298-
```
1299-
1300-
#### Client
1301-
```cpp
1302-
import httplib;
1303-
1304-
using httplib::Client;
1305-
using httplib::Result;
1306-
1307-
Client cli("https://yhirose.github.io");
1308-
1309-
if (Result res = cli.Get("/hi")) {
1310-
res->status;
1311-
res->body;
1312-
}
1313-
```
1314-
13151278
Dockerfile for Static HTTP Server
13161279
---------------------------------
13171280

modules/CMakeLists.txt

Lines changed: 0 additions & 25 deletions
This file was deleted.

modules/httplib.cppm

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)