rbeeli / websocketclient-cpp

A transport-agnostic, high-performance, header-only C++23 WebSocket client library with minimal dependencies.
MIT License
1 stars 1 forks source link

Building and installing the library #6

Closed MeanSquaredError closed 1 month ago

MeanSquaredError commented 1 month ago

Hi,

I tried building and installing the library, but it seems that there are a bunch of dependencies that are required in order to build the library. On Fedora 40 I had to install these:

google-benchmark-devel 
gtest-devel 
asio-devel

And even after installing asio-devel, there was some find_package() call in CMakeLists.cmake which failed because it couldn't find asio-config.cmake or asioConfig.cmake. I couldn't find a Fedora package that provides either of these files, so I just gave up on trying to build the test/benchmark stuff and just commented out the following lines in CMakeLists.cmake

# add_subdirectory(bench)
# add_subdirectory(tests)
# add_subdirectory(tests/autobahn)
# add_subdirectory(examples)

After that the project built successfully (which is not surprising given that it seems to be a header-only library).

It probably makes sense to add CMake options that would allow excluding these four directories by default and only building them if the user explicitly requests that.

Also another issue arises from the following defines

WS_CLIENT_USE_SIMD_UTF8
WS_CLIENT_USE_ZLIB_NG

Initially I thought that they are CMake options and should be specified as

cmake ... -DWS_CLIENT_USE_SIMD_UTF8 -DWS_CLIENT_USE_ZLIB_NG

But obviously that is not the case. So obviously they are C++ defines and the next question is whether they should be defined during the building of the library or during the building of the user's application that uses the library. Given that it seems to be a header-only library, the defines probably should be added to the client applications's CMakeLists.txt

So all these things should probably be added to the readme file.

rbeeli commented 1 month ago

Hi,

It probably makes sense to add CMake options that would allow excluding these four directories by default and only building them if the user explicitly requests that.

Yes, the bench/tests/examples should be optional, I'll introduce CMake options for them.


WS_CLIENT_USE_SIMD_UTF8
WS_CLIENT_USE_ZLIB_NG

Indeed, those are compile time definitions, see examples:

target_compile_definitions(ex_echo_sync PRIVATE
    WS_CLIENT_USE_ZLIB_NG=1 # Use zlib-ng instead of zlib
    WS_CLIENT_USE_SIMD_UTF8=1 # Use simdutf for utf-8 validation
)

I agree that it's not obvious from the README and should be clarified.

Will look into it next week when I have more time at hand.

MeanSquaredError commented 1 month ago

OK, thank you for the clarification. Also I installed the library via

cmake -B build
cmake --build build
cmake --install build

After that it these two directories to /usr/local/include/, more specifically

/usr/local/include/coroio/
/usr/local/include/ws_client/

The second one, ws_client, contains .hpp files, but the first one, coroio, contains both .hpp files and .cpp files.

root@fedora:~# ls -la /usr/local/include/coroio/
total 116
drwxr-xr-x   2 root root  4096 Jul 23 04:58 .
drwxr-xr-x. 11 root root  4096 Jul 23 04:58 ..
-rw-r--r--   1 root root   745 Jul 23 01:35 all.hpp
-rw-r--r--   1 root root  1658 Jul 23 01:35 base.hpp
-rw-r--r--   1 root root  2771 Jul 23 01:35 corochain.hpp
-rw-r--r--   1 root root  4009 Jul 23 01:35 epoll.cpp
-rw-r--r--   1 root root   497 Jul 23 01:35 epoll.hpp
-rw-r--r--   1 root root  3046 Jul 23 01:35 kqueue.cpp
-rw-r--r--   1 root root   516 Jul 23 01:35 kqueue.hpp
-rw-r--r--   1 root root   422 Jul 23 01:35 loop.hpp
-rw-r--r--   1 root root  2662 Jul 23 01:35 poll.cpp
-rw-r--r--   1 root root  3889 Jul 23 01:35 poller.hpp
-rw-r--r--   1 root root   439 Jul 23 01:35 poll.hpp
-rw-r--r--   1 root root  1319 Jul 23 01:35 promises.hpp
-rw-r--r--   1 root root 10952 Jul 23 01:35 resolver.cpp
-rw-r--r--   1 root root  2814 Jul 23 01:35 resolver.hpp
-rw-r--r--   1 root root  1885 Jul 23 01:35 select.cpp
-rw-r--r--   1 root root   606 Jul 23 01:35 select.hpp
-rw-r--r--   1 root root  5664 Jul 23 01:35 socket.cpp
-rw-r--r--   1 root root  7975 Jul 23 01:35 socket.hpp
-rw-r--r--   1 root root  2544 Jul 23 01:35 sockutils.cpp
-rw-r--r--   1 root root  3815 Jul 23 01:35 sockutils.hpp
-rw-r--r--   1 root root  2389 Jul 23 01:35 ssl.cpp
-rw-r--r--   1 root root  7537 Jul 23 01:35 ssl.hpp
root@fedora:~# 

What is the purpose of the .cpp files in that directory? Are they to be compiled in some way by the client application? It seems to me that they should actually be compiled during the library build and then installed as libcoroio.a or libcoroio.so. Or am I missing something about this installation?

rbeeli commented 1 month ago

You can ignore coroio / remove it. That's an alternative to ASIO, which is also optional. Maybe I should remove it or make a CMake option.

rbeeli commented 1 month ago

If something else is worth clarifying or documenting, please let me know or submit a pull request. Thanks.