3

I would like to use vcpkg to manage my packages. I would also like to use CMake to manage my builds. Is it possible to include quantlib library without resorting to hard coded links? Something like find_package(quantlib)?

EDIT: Things I've tried to far (disclaimer - I'm new to this. It feels like I'm groping in the dark. This section makes my ignorance a little too transparent) First, this is a clean build and I do not have backward comparability constraints. My aim is to create something that I can use between my Linux and Windows environments. I am using VSCode to edit my code and CMake. My reference here was the Boost library. The way I used that, successfully (and header only at this point), was

find_package(Boost ${BOOST_VERSION} REQUIRED) 
if (Boost_FOUND)
  include_directories(${Boost_INCLUDE_DIRS})
else()
   MESSAGE("BOOST not found")
endif()

To date I am making progress with something along the following lines (I'm not 100% sure this works yet but I believe I will get it over the line):

set(QUANTLIB_DIR "E:/SD/Programming/C++/vcpkg/installed/x64-windows"
    CACHE PATH "The path to the quantlib directory")
include_directories(${QUANTLIB_DIR})
add_library(quantlib STATIC IMPORTED)
set_target_properties(quantlib PROPERTIES IMPORTED_LOCATION ${QUANTLIB_DIR}/lib/QuantLib-vc141-x64-mt.lib)
add_library(quantlibDebug STATIC IMPORTED)
set_target_properties(quantlibDebug PROPERTIES IMPORTED_LOCATION ${QUANTLIB_DIR}/debug/lib/QuantLib-vc141-x64-mt-gd.lib)

If this is the way I need to proceed (system dependent, build dependent) I will need to have sections like this for each different environments. I was hoping that using a package manager with CMake would allow me to use system agnostic variables in my build. Am I naive?

Steven
  • 253
  • 3
  • 11
  • What have you tried so far? Did it work? Was there any undesired behavior when you tried it? Please add such details to your question post. – Kevin Jul 11 '20 at 15:35
  • @squareskittles, I updated the post. I had was trying to avoid too many details because I think I am heading down a dead end. I'm hoping there is some high level guidance here like: "Look, Luigi has documented this countless time, please read this doc ...." – Steven Jul 12 '20 at 08:26

1 Answers1

2

I am using AutoVcpkg to integrate vcpkg into CMake, which safes you from managing dependency directories manually. Basically you start off by defining the vcpkg installation directory. I am using the VCPKG_ROOT environment variable as a default value (however, you could provide something else using a build variable, in case you have multiple vcpkg installations):

INCLUDE (AutoVcpkg)
SET (AUTO_VCPKG_ROOT $ENV{VCPKG_ROOT})

Next, you can use the VCPKG_INSTALL macro to install the library you want:

VCPKG_INSTALL(quantlib)
FIND_PACKAGE(quantlib REQUIRED)
TARGET_LINK_LIBRARIES(MyProject PUBLIC quantlib)
Carsten
  • 11,287
  • 7
  • 39
  • 62