5

I am trying to write a web service in C++ (I am very new to the language) using restbed for HTTP handling. Both projects seem to be using cmake to do build configuration and dependency management, so I figured I would do so as well. But I am confused about how to go about it.

Here is my minimal CMakeLists.txt

cmake_minimum_required(VERSION 3.7)
project(WebService)

set (WebService_VERSION_MAJOR 1)
set (WebService_VERSION_MAJOR 0)

set(CMAKE_CXX_STANDARD 11)

add_executable(${PROJECT_NAME} main.cpp)

I understand that there are a few ways to add dependencies in cmake. I have tried doing things like find_package(restbed), but obviously it doesn't know where to find the package I want and keeps asking for extra cmake files to help it. I am not sure where I am supposed to find these. Am I supposed to write one myself?

I have tried using the ExternalProject_Add directive. I added the following.

ExternalProject_Add(
    restbed
    GIT_REPOSITORY "git@github.com:Corvusoft/restbed.git"
    SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/restbed"
    CMAKE_ARGS -DBUILD_SSL=OFF
    )
set (restbed_INCLUDE ${CMAKE_SOURCE_DIR}/deps/restbed/distribution/include/)
set (restbed_LIB ${CMAKE_SOURCE_DIR}/deps/restbed/distribution/library/librestbed.a)

add_dependencies(${PROJECT_NAME} restbed)
include_directories(${restbed_INCLUDE})
target_link_libraries(${PROJECT_NAME} ${restbed_LIB})

The problem I am having is that apparently all the steps for setting up an external project are performed during the build and not during cmake configuration. This means that every external project rebuilds and reinstalls everything every time I run make. My service is small and this seems very wasteful.

Is there a better way to deal with dependencies? Is there an easier tool than cmake? Is there something for C++ that is similar to Rust's cargo or Haskell's stack maybe?

Mad Wombat
  • 14,490
  • 14
  • 73
  • 109

0 Answers0