0

I was trying to include an external library in my project using the following:

ExternalProject_Add(
    http_server_dl
    GIT_REPOSITORY "https://github.com/av4625/http_server.git"
    GIT_TAG "beast"
    GIT_SHALLOW TRUE
    BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target http_server
    TEST_COMMAND ""
    INSTALL_COMMAND ""
    BUILD_BYPRODUCTS "<BINARY_DIR>/src/libhttp_server.a"
)

ExternalProject_Get_Property(http_server_dl SOURCE_DIR BINARY_DIR)

add_library(http_server IMPORTED STATIC GLOBAL)
add_dependencies(http_server http_server_dl)

file(MAKE_DIRECTORY ${SOURCE_DIR}/src)

set_target_properties(http_server PROPERTIES
    IMPORTED_LOCATION ${BINARY_DIR}/src/libhttp_server.a
    INTERFACE_INCLUDE_DIRECTORIES ${SOURCE_DIR}/src)

This seems to work ok but the external library depends on boost. It uses conan to build boost and I can see this happening when the external project build step is happening.

When I try to do:

#include <server.hpp>

in one of my files I get this warning:

fatal error: 'boost/noncopyable.hpp' file not found
#include <boost/noncopyable.hpp>

server.hpp does use that boost file.

In the library that I include server.hpp I have done:

add_library(<my_lib> library_file.cpp)
target_link_libraries(<my_lib> PRIVATE http_server)

How do I fix this so everything is bundled into the http_server library?

av4625
  • 303
  • 1
  • 11
  • 1
    "How do I fix this so everything is bundled into the `http_server` library? - Do you want to copy Boost headers into `http_server` project and link `http_server` library statically with Boost? Well, you may do that, but this is not what is normally done. – Tsyvarev Feb 28 '23 at 18:57
  • 1
    If all you want is using `target_link_libraries( PRIVATE http_server)` to propagate all needed things (include directories, linked libraries) to your library, then consider to use FetchContent instead of ExternalProject. That way the **target** `http_server` will be created by `http_server` project, so the project will be able to adjust all properties of that target for external usage. – Tsyvarev Feb 28 '23 at 18:58
  • @Tsyvarev I will look into that, thanks, I wasn't sure the best way to get an external library in cmake – av4625 Feb 28 '23 at 19:20

0 Answers0