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.15k stars 93 forks source link

Include Restinio in a cross-compiled existing project #119

Closed undici77 closed 4 years ago

undici77 commented 4 years ago

I'm trying to include Restinio in a cross-compiled existing project.

I did

git clone https://github.com/stiffstream/restinio
cd restinio
mxxruexternals
cd dev
mkdir cmake_build
cd cmake_build
cmake -DCMAKE_BUILD_TYPE=Debug ..

and I get in restinio/dev/cmake_build all sample cross compiled and working on my device.

But now, also in a very simple project, I try to include Restinio using CMake

cmake_minimum_required(VERSION 3.8)
project (helloworld)
add_executable(helloworld main.cpp)
set(CMAKE_PREFIX_PATH "~/restinio/dev/cmake_build/restinio/CMakeFiles/Export/lib/cmake/restinio")

find_package(restinio REQUIRED)

target_link_libraries(helloworld PRIVATE restinio::restinio)

I get errors...

Can someone help me?

eao197 commented 4 years ago

What errors do you get? Errors from CMake during the configuration phase? Or errors from the compiler/linker?

If you get errors from CMake then I think the more correct actions sequence could be:

git clone https://github.com/stiffstream/restinio
cd restinio
mxxruexternals
cd dev
mkdir cmake_build
cd cmake_build
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=target ..
cmake --build . --config=Debug
cmake --build . --target install

Then specify ~/restinio/dev/cmake_build/target as the value of CMAKE_PREFIX_PATH in your CMakeLists.txt.

undici77 commented 4 years ago

Thanks for the answer: I got this error (also with your solution)

CMake Error at CMakeLists.txt:5 (find_package):
  By not providing "Findrestinio.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "restinio",
  but CMake did not find one.

  Could not find a package configuration file provided by "restinio" with any
  of the following names:

    restinioConfig.cmake
    restinio-config.cmake

  Add the installation prefix of "restinio" to CMAKE_PREFIX_PATH or set
  "restinio_DIR" to a directory containing one of the above files.  If
  "restinio" provides a separate development package or SDK, be sure it has
  been installed.
eao197 commented 4 years ago

After doing those actions:

cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=target ..
cmake --build . --config=Debug
cmake --build . --target install

you should have the following directory structure in target subfolder:

target/
├── bin
├── include
│   └── restinio
│       ├── helpers
│       │   └── http_field_parsers
│       │       └── details
│       ├── impl
│       ├── path2regex
│       ├── router
│       │   └── impl
│       ├── so5
│       ├── third_party
│       │   ├── expected-lite
│       │   ├── optional-lite
│       │   ├── string-view-lite
│       │   └── variant-lite
│       ├── transforms
│       ├── utils
│       │   └── impl
│       └── websocket
│           └── impl
├── lib
│   └── cmake
│       └── restinio
└── share
    └── unofficial-http-parser

The file restinio-config.cmake is in target/lib/cmake/restinio.

So I think you didn't do cmake --build . --target install or you specified a wrong path in CMAKE_PREFIX_PATH option.

undici77 commented 4 years ago

That's the key: I don't have in my target folder target->lib , cmake->restinio subfolder! I have libhttp_parser.a in target->lib and nothing more!

[  2%] Built target http_parser
[  4%] Built target fmt
[ 49%] Built target so_s.5.5.24.3
[ 62%] Built target zlibstatic
[ 63%] Built target sample.hello_world_basic
[ 65%] Built target sample.hello_world
[ 66%] Built target sample.hello_world_minimal
[ 68%] Built target sample.hello_world_delayed
[ 70%] Built target sample.hello_world_sendfile
[ 71%] Built target sample.run_existing_server
[ 73%] Built target sample.run_for_minute
[ 75%] Built target sample.express_router
[ 76%] Built target sample.express_router_tutorial
[ 77%] Built target sample.easy_parser_router
[ 79%] Built target sample.sendfiles
[ 81%] Built target sample.query_string_params
[ 82%] Built target sample.try_parse_query_string
[ 83%] Built target sample.websocket
[ 85%] Built target sample.websocket_detailed
[ 87%] Built target sample.using_external_io_context
[ 88%] Built target sample.async_handling_with_sobjectizer
[ 90%] Built target sample.compression
[ 92%] Built target sample.decompression
[ 93%] Built target sample.notificators
[ 95%] Built target sample.custom_buffer
[ 96%] Built target sample.connection_state
[ 98%] Built target sample.ip_blocker
[100%] Built target sample.file_upload
Install the project...
-- Install configuration: "Debug"
-- Installing: /home/administrator/restinio/dev/cmake_build/target/lib/libhttp_parser.a
-- Installing: /home/administrator/restinio/dev/cmake_build/target/share/unofficial-http-parser/unofficial-http-parser-config.cmake
-- Installing: /home/administrator/restinio/dev/cmake_build/target/share/unofficial-http-parser/unofficial-http-parser-config-debug.cmake
-- Installing: /home/administrator/restinio/dev/cmake_build/target/include/http_parser.h

That's the log of cmake --build . --target install

eao197 commented 4 years ago

I can't reproduce that behavior on my Kubuntu 18.04 with GCC 7.5 and CMake 3.10.2. Everything is working as expected. There are my commands performed inside restinio/dev/cmake_build subfolder:

cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=target -DRESTINIO_ALLOW_SOBJECTIZER=ON -DRESTINIO_TEST=OFF -DRESTINIO_BENCH=OFF ..
cmake --build . --target install
undici77 commented 4 years ago

Ok I found the issue: Unfortunately compiling the entire library RAM of my VM were full... So.. Now

I have 
├── lib
│   └── cmake
│       └── restinio

And now restinio-config.cmake is working. SO MANY THANKS!!!

But now I'm Now I'm locked in resolving dependency... (not so far from before)

But now I have same issue with fmt-config.cmake

Starting my project example:

cmake_minimum_required(VERSION 3.8.0)
project (helloworld)
add_executable(helloworld main.cpp)

list(APPEND CMAKE_PREFIX_PATH "/home/administrator/restinio/dev/cmake_build/target")
list(APPEND CMAKE_INSTALL_PREFIX "/home/administrator/restinio/dev/cmake_build/target")

find_package(unofficial-http-parser REQUIRED)
find_package(fmt REQUIRED)
find_package(restinio REQUIRED)
find_package(Boost 1.73.0 COMPONENTS system asio thread)
find_package(Threads REQUIRED)

find_package(OpenSSL REQUIRED)

target_link_libraries(helloworld PRIVATE restinio::restinio OpenSSL::SSL OpenSSL::Crypto ${CMAKE_THREAD_LIBS_INIT})

I'm getting same problem...


CMake Error at CMakeLists.txt:14 (find_package):
  By not providing "Findfmt.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "fmt", but
  CMake did not find one.

  Could not find a package configuration file provided by "fmt" with any of
  the following names:

    fmtConfig.cmake
    fmt-config.cmake

  Add the installation prefix of "fmt" to CMAKE_PREFIX_PATH or set "fmt_DIR"
  to a directory containing one of the above files.  If "fmt" provides a
  separate development package or SDK, be sure it has been installed.
eao197 commented 4 years ago

Unfortunately, it is the expected result because RESTinio doesn't install externals such fmtlib.

There are several options you can use:

  1. Copy source code of RESTinio and required dependencies to your source tree and add RESTinio to your project via CMake's add_subdirectory. The source code of fmtlib can be added to your project the same way.

  2. Install fmtlib separately and then pass RESTINIO_FIND_DEPS=ON to CMake when configuring RESTinio.

  3. Use Conan or Vcpkg for resolving the dependencies. But note that Vcpkg can contain Asio 1.17 and RESTinio up to 0.6.8.1 doesn't compatible with Asio 1.17 (Boost 1.73 holds Asio 1.16 AFAIK).

All those options more or less described in the docs.

undici77 commented 4 years ago

Many Thanks, I resolved!