[Libwebsockets] howto build minimal example

Andy Green andy at warmcat.com
Sat Nov 14 22:04:28 CET 2020



On 11/14/20 7:23 PM, Michael Johanssen wrote:
> Hi - let me start with stating that I am a real beginner. So I am 
> working under Windows, of course.
> 
> I managed cloning the git repository, configure, generate, build and 
> install the basic installation w/o any cmake adaptations.
> libwebsockets-test-server.exe and libwebsockets-test-client.exe seem to 
> work as intended.
> However, now when trying to build the minimal-ws-server-timer example, 
> cmake fails:
> 
> CMake Error at C:/Projects/install/cmake/LwsCheckRequirements.cmake:52 
> (message):
>    This project requires lws must have been configured with LWS_ROLE_WS
> 
> I think the error is caused because I do not know how to tell cmake 
> where the libwebsockets install resides.

Right... on unix, there are well defined places to put things where they 
can be discovered easily by default.  So cmake .. && make && sudo make 
install will put things in sane places down /usr/local/...

The default equivalent on windows is like "C:\Program Files 
(x86)/libwebsockets", this is where lws will go if you build and then, 
as admin

cmake --install . --config DEBUG

But for windows' loader to actually find your .lib / .dll, there is no 
linkage to that dir convention, it seems they must either be copied into 
the same dir as the app that wants it, or the dir the library was 
installed to be included in PATH.

> In the libwebsockets/minimal-examples/ws-server/minimal-ws-server-timer 
> directory, I call:
> 
> cmake -B build -S . -DCMAKE_PREFIX_PATH="c:/Projects/install"
> 
> So my question is: What would be a correct invocation (presumably, which 
> variable setting(s)) that causes CMake to set respective include 
> directories ?

For the examples, you can add them to the library build at cmake with 
-DLWS_WITH_MINIMAL_EXAMPLES=1, after the lib build it will proceed to 
build all of the minimal examples that can be built with your current 
cmake options, against the just-built-and-not-installed library and 
headers.  This works on windows and unix.

On Unix the supplied example makefiles build standalone just fine after 
make install.  But on windows (only) it looks like something broken atm 
in the generated libwebsockets-config.cmake file, 
LIBWEBSOCKETS_INCLUDE_DIRS seems empty.

You can try and modify the examples building at the same time as the lib 
to get started, but when splitting off your own app based on it for 
standalone build, you're going to have to add in some extra 
include_directories etc by hand atm.

-Andy


More information about the Libwebsockets mailing list