0

I'm testing vcpkg (on macOS) with a CMake project.

Since not all vcpkg packages have CMake find modules, I'm trying with a package that doesn't have one: libuuid

This is the directory tree relative to libuuid I can see from the vcpkg root:

$ find packages/libuuid_x64-osx
packages/libuuid_x64-osx
packages/libuuid_x64-osx/include
packages/libuuid_x64-osx/include/uuid
packages/libuuid_x64-osx/include/uuid/uuid.h
packages/libuuid_x64-osx/BUILD_INFO
packages/libuuid_x64-osx/lib
packages/libuuid_x64-osx/lib/libuuid.a
packages/libuuid_x64-osx/CONTROL
packages/libuuid_x64-osx/debug
packages/libuuid_x64-osx/debug/lib
packages/libuuid_x64-osx/debug/lib/libuuid.a
packages/libuuid_x64-osx/share
packages/libuuid_x64-osx/share/libuuid
packages/libuuid_x64-osx/share/libuuid/copyright

Example program:

#include <iostream>
#include <uuid/uuid.h>

int main(int argc, char **argv)
{
    std::cout << "Hello, world!" << std::endl;

    return 0;
}

Example CMakeLists.txt

cmake_minimum_required(VERSION 3.13)

project(vcpkg_example_project)

add_executable(app app.cpp)
target_link_libraries(app uuid)

If I understand correctly, vcpkg's philosophy is not to provide missing CMake find-modules, but to simply have #include <libfoo/foo.h> work out of the box. And in fact the example above compiles fine. But fails to find -luuid:

$ cmake -DCMAKE_TOOCHAIN_FILE=/Users/me/Dev/vcpkg/scripts/buildsystems/vcpkg.cmake ..
...
$ cmake --build .
Scanning dependencies of target app
[ 50%] Building CXX object CMakeFiles/app.dir/app.cpp.o
[100%] Linking CXX executable app
ld: library not found for -luuid
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [app] Error 1
make[1]: *** [CMakeFiles/app.dir/all] Error 2
make: *** [all] Error 2

What am I missing?

Also, I see there is a installed/x64-osx/lib/libuuid.a. Shouldn't installed/x64-osx/lib automatically added as lib path by the toolchain cmake script?

fferri
  • 18,285
  • 5
  • 46
  • 95

1 Answers1

0

I'd make a target out of uuid. From what you describe, most probably an Interface Library called uuid. You can add_target_include_directories and target_link_libraries for the headers and any libraries, and then add it to the rest of your project.

So something like this:

add_library(uuid INTERFACE)

if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
    find_library(LIBUUID uuid "${CMAKE_CURRENT_SOURCE_DIR}/packages/libuuid_x64-osx/lib/")
else()
    find_library(LIBUUID uuid "${CMAKE_CURRENT_SOURCE_DIR}/packages/libuuid_x64-osx/debug/lib/")
endif()

target_link_libraries(uuid INTERFACE "${LIBUUID}")

target_include_directories(uuid SYSTEM INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/packages/libuuid_x64-osx/include")

I'd then do an add_subdirectory to the library's folder and link to uuid

Bernard
  • 45,296
  • 18
  • 54
  • 69
Cascades
  • 627
  • 7
  • 18