Closed DmitryShipilov closed 2 years ago
Hi!
http_parser isn't header-only dependency, it has to be compiled to static library.
To use header-only version of fmtlib you have to specify FMT_HEADER_ONLY symbol (see this issue).
Could you show minimal correct CMakeLists.txt with RESTinio library usage? I really frustrated with my desperate attempts to make it work
I'm not a CMake user, but it seems that in your case the minimal CMakeLists.txt could be as that:
cmake_minimum_required(VERSION 3.19)
project(restinio_example)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(RESTINIO_USE_BOOST_ASIO "none")
add_subdirectory(restinio-0.6.14/dev/restinio)
add_subdirectory(restinio-0.6.14/dev/fmt)
add_subdirectory(restinio-0.6.14/dev/nodejs/http_parser)
add_executable(restinio_hello main.cpp)
target_include_directories(restinio_hello PRIVATE restinio-0.6.14/dev/asio/include)
target_link_libraries(restinio_hello PRIVATE
restinio::restinio
fmt::fmt-header-only)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
if(Threads_FOUND)
target_link_libraries(restinio_hello PRIVATE Threads::Threads)
endif()
if(WIN32)
target_link_libraries(restinio_hello PRIVATE wsock32 ws2_32)
endif()
The directory structure:
example/
` restinio-0.6.14/
`- dev/
`- ...
`- main.cpp
`- CMakeLists.txt
But it seems that CMake will build fmtlib anyway.
You are my hero!
Hi there! I want just use this header only library. I've created dir, cloned RESTinio repo and trying to complete my CMake. I can't resolve my link errors bounded with fmt and http-parser. Could you tell, what should I write in CMake?
Project tree: -- RESTinio-0.6.14 (downloaded as archive) -- main.cpp -- CMakeListsts.txt
CmakeListst.txt contains:
cmake_minimum_required(VERSION 3.21) project(MyTests)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_BUILD_TYPE debug) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
set (Sources main.cpp )
add_subdirectory(restinio-0.6.14/dev)
add_executable(MyTest ${Sources})
include_directories(MyTest restinio-0.6.14/dev) include_directories(MyTest restinio-0.6.14/dev/asio/include) include_directories(MyTest restinio-0.6.14/dev/fmt/include) include_directories(MyTest restinio-0.6.14/dev/nodejs/http_parser)
main.cpp contains:
include <restinio/all.hpp>
int main() { using namespace restinio; 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; }