getdnsapi / getdns

A modern asynchronous DNS API https://getdnsapi.net/
Other
468 stars 126 forks source link

Clearer instructions for windows on how to include this in another cmake project using vcpkg #533

Open Andersama opened 2 years ago

Andersama commented 2 years ago

I installed this from vcpkg. Had no luck trying to find an example CMakeLists.txt file. I went and looked at stubby's source code to find a find_package directive which does not appear to work. Looking at the readme:

Once these are installed, set CMake variables CMAKE_INCLUDE_PATH and CMAKE_LIBRARY_PATH to the vcpkg include and library directories e.g. ../vcpkg/installed/x64-windows/include and ../vcpkg/installed/x64-windows/lib.

This at best in my case included the header file, but did not include the library into the project. Currently it seems that the vcpkg install builds the project as a library (static or dynamic depending on the triplet). It's relatively straightforward to include the header with cmake.

target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_INCLUDE_PATH}" "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include")

But what to do with the .lib file I'm not too sure, for one the file appears to be named differently between the static and dynamic versions so that's a bit confusing. It appears to be either getdns.lib or getdns_static.lib.

target_link_libraries(${PROJECT_NAME} PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/getdns.lib")
#target_link_libraries(${PROJECT_NAME} PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/getdns_static.lib")

These two steps appear to be all that's necessary to get cmake to function*. Granted, the .dll file may need to be copied over depending on which triplet is used.

garthgoodson commented 3 months ago

In the vcpkg ports dir there should really be a getdns-config.in.cmake file that defines how to use find_package() and link_libraries, like other ports have.