Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMakeLists.txt example #3

Closed
jm130794 opened this issue Jun 5, 2018 · 5 comments
Closed

CMakeLists.txt example #3

jm130794 opened this issue Jun 5, 2018 · 5 comments

Comments

@jm130794
Copy link

jm130794 commented Jun 5, 2018

Hello,

We want to test restinio under Windows 10. Apparently, we can use the vcpkg tool. We have installed all the necessary libraries but we can't build our example. Do you have an example CMakeLists.txt file that works?
Here is the error message :

CMake Error at C:/Users/jm/vcpkg/scripts/buildsystems/vcpkg.cmake:141 (_add_executable):
  Target "helloworld" links to target "unofficial::http_parser::http_parser"
  but the target was not found.  Perhaps a find_package() call is missing for
  an IMPORTED target, or an ALIAS target is missing?
Call Stack (most recent call first):
  CMakeLists.txt:5 (add_executable)

And the contents of the CMakeLists.txt file :

cmake_minimum_required(VERSION 3.8.0)
project (helloworld)
add_executable(helloworld helloworld.cpp)
find_package(restinio REQUIRED)
find_package(fmt REQUIRED)
find_path(RESTINIO_INCLUDE_DIR restinio/all.hpp)
include_directories(${RESTINIO_INCLUDE_DIR})
target_link_libraries(helloworld PRIVATE restinio::restinio)
#include <restinio/all.hpp>

int main()
{
    restinio::run(
        restinio::on_this_thread()
        .port(8080)
        .address("localhost")
        .request_handler([](auto req) {
            return req->create_response().set_body("Hello, World!").done();
        }));
    return 0;
}
@ngrodzitski
Copy link
Member

Hi!

For vcpkg, try also to include find_package(unofficial-http-parser REQUIRED) to a list of packages you search.
I guess this would work (if no, let me know, I'll make a sample from scratch).

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

# RESTinio dependencies:
# 1. ASIO or Boost::ASIO (goes as headers, vcpkg knows where)
# 2. HTTP parser
find_package(unofficial-http-parser REQUIRED)
# 3. fmtlib
find_package(fmt REQUIRED)
# RESTinio itself
find_package(restinio REQUIRED)

# Make your project dependent on restinio, 
# and let cmake deal with all the headers paths and linked libs.
target_link_libraries(helloworld PRIVATE restinio::restinio)

@jm130794
Copy link
Author

jm130794 commented Jun 5, 2018

Hi,

Your example works... and thanks for the quick response.
We learn CMake at the same time. Sorry if the question seem silly.

You should add this example in the documentation in the CMake section.

Jean-Marc

@ngrodzitski
Copy link
Member

It a usual question. I periodically go through the similar issues with 3rd party libs myself. It's clear for the authors how to put all dependencies together but for a fresher, it might be tricky. So feel free to ask for any help with RESTinio.

You should add this example in the documentation in the CMake section.

Yeah, sounds reasonable. Will keep the issue opened until adding notes to docs.

@ngrodzitski
Copy link
Member

@ras0219-msft
Copy link

@ngrodzitski You might look at adding a find_dependency() call to your -config.cmake file: https://cmake.org/cmake/help/latest/module/CMakeFindDependencyMacro.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants