Stiffstream / restinio

Cross-platform, efficient, customizable, and robust asynchronous HTTP(S)/WebSocket server C++ library with the right balance between performance and ease of use
Other
1.13k stars 93 forks source link

CMake configure fails when using boost asio via find #201

Closed rcane closed 6 months ago

rcane commented 7 months ago

There are two bugs in the cmake scripts when using boost asio (RESTINIO_ASIO_SOURCE=boost and RESTINIO_DEP_BOOST_ASIO=find).

The first one is this line in the CMakeLists.txt file. The COMPONENTS part of find_package is only supposed to refer to libraries that are being linked. Since 'headers' is a header-only library it cannot be linked. Having it in the COMPONENTS list will make the cmake configuration fail since there is no target for the 'headers' library. To fix this just remove the 'headers' reference. The include directory for those header files will already be configured with the find_package(Boost REQUIRED) line.

The second bug is in dev/restinio/cmake/restinio-config.cmake.in where "boost" is misspelled. It should say "Boost" instead.

eao197 commented 7 months ago

Hi, @rcane !

Thanks for reporting! We'll take a look at them a bit later.

eao197 commented 7 months ago

I've added a new Dockerfile to check the presence of the first problem on Linux. Unfornunately, this file doesn't show an error with CMake configure.

I'll try to find another way to show that such a problem exists and that it will be fixed properly.

rcane commented 7 months ago

Her is some more information that maybe helps:

I encountered the problems when I tried to install restinio via vcpkg. Since the official vcpkg port uses standalone asio, I created an overlay port where I changed the dependency from "asio" to "boost-asio" and modified the cmake configure parameters in the portfile.cmake to use boost asio. I am doing this under Windows with VS2022.

This SO article got me to the fix of the first bug.

This is the modified configure call I use in the portfile:

vcpkg_cmake_configure(
    SOURCE_PATH "${SOURCE_PATH}/dev"
    OPTIONS
        -DRESTINIO_INSTALL=ON
        -DRESTINIO_TEST=OFF
        -DRESTINIO_SAMPLE=OFF
        -DRESTINIO_BENCHMARK=OFF
        -DRESTINIO_WITH_SOBJECTIZER=OFF
        -DRESTINIO_ASIO_SOURCE=boost
        -DRESTINIO_DEP_BOOST_ASIO=find
        -DRESTINIO_DEP_LLHTTP=find
        -DRESTINIO_DEP_FMT=find
        -DRESTINIO_DEP_EXPECTED_LITE=find
)

So it is basically what your are doing in the dockerfile. I have no idea why it does not show the error. Maybe vcpkg does something that makes this different.

eao197 commented 7 months ago

I'm trying to check that behaviour on Windows with Boost. Maybe it will show the problem.

ngrodzitski commented 7 months ago

@eao197
Since v0.7.0 we have boost-asio ci (both system and prebuild=kindly build from sources by @MarkusJx). So I don't think dockerfile is necessary: Ubuntu-22.04 (gcc-9, Debug, C++17, boost-system-package asio) Ubuntu-22.04 (gcc-12, Release, C++20, boost asio)

Regarding windows and vcpkg I can take a look tomorrow, and since github runners by default have vcpkg in it we can think of adding a CI (win+vcpk) to avoid such issues future.

eao197 commented 7 months ago

@ngrodzitski

I had used Dockerfiles before you've configured GitHub CI for v0.7, but the Dockerfile used RESTINIO_DEP_BOOST_ASIO=system. The new file uses RESTINIO_DEP_BOOST_ASIO=find.

I hope I can check Boost on Window today (without vcpkg).

eao197 commented 7 months ago

It seems that this issue is related to vcpkg. I've tried Boost (1.83.0) on Windows and there are no problems.

I'll try to make a project that uses vcpkg's overlay for RESTinio.

eao197 commented 7 months ago

I've repeated this problem with help of https://github.com/Stiffstream/restinio-crud-example/tree/restinio-0.7.0-vcpkg-overlay-boost-asio

There is a fix for the problem in the 0.7-dev-issue-201 branch (at the commit 1f0234d06563a5b060e2435dbf8fdb1e50dc6e2e).

I think this fix will be a part of upcoming 0.7.1 release, but I'm afraid this may not happen on this week.

rcane commented 7 months ago

Great. But no rush. Since I already need a port overlay anyway, it was quite easy to patch restinio there and get it working for me. I am waiting for 0.7.1 to land in vcpkg so I can remove my local patch.