mattgodbolt / seasocks

Simple, small, C++ embeddable webserver with WebSockets support
BSD 2-Clause "Simplified" License
724 stars 120 forks source link

Documentation for client code usage #120

Open offa opened 5 years ago

offa commented 5 years ago

There's no good documentation around, how this library is integrated in client projects (#119).

iwanders commented 4 years ago

Was about to file a PR and I saw this issue and related #119. Just quickly chiming in, since this is really simple since my contributions in PR's #116, #108 and #110 .

In the most minimal form, a direct copy paste from the description of #116. This should work after an install (make install) of seasocks has been performed:

cmake_minimum_required(VERSION 3.3)
find_package(Seasocks 1.4.0) # Requires at least version 1.4.0.
add_executable(my_server serve.cpp)
target_link_libraries(my_server Seasocks::seasocks)

Seasocks can also be used as a submodule inside the directory structure of the host cmake project. In that case let's assume seasocks is located in the thirdparty folder.

Doing something like:

if(USE_EXTERNAL_SEASOCKS)
  find_package(Seasocks REQUIRED)
else()
  set(UNITTESTS OFF CACHE INTERNAL "")
  set(SEASOCKS_EXAMPLE_APP OFF CACHE INTERNAL "")
  add_subdirectory(thirdparty/seasocks)
endif()

After those lines you can just link your binary / library against the now exported Seasocks::seasocks target with the target_link_libraries(my_server Seasocks::seasocks) instruction.