0

Context:

I have a cpp program built on MacOS 12.6 with the following CMakeLists.txt file.

cmake_minimum_required(VERSION 3.19.0)
project(cpp-test VERSION 0.1.0)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

add_executable(cpp-test main.cpp)
add_library(test-helpers main.cpp ${PROJECT_SOURCE_DIR}/helpers.hpp)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

# this is super important in order for cmake to include the vcpkg search/lib paths!
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")

# find library and its headers
find_path(IXWEBSOCKET_INCLUDE_DIR ixwebsocket/IXWebSocket.h)
find_library(IXWEBSOCKET_LIBRARY ixwebsocket)
find_package(OpenSSL REQUIRED)
find_package(CURL REQUIRED)

# include headers
include_directories(${IXWEBSOCKET_INCLUDE_DIR} ${CURL_INCLUDE_DIR})

# Cmake will automatically fail the generation if the lib was not found, i.e is set to NOTFOUND
target_link_libraries(
  ${PROJECT_NAME} PRIVATE
  ${IXWEBSOCKET_LIBRARY}
  OpenSSL::SSL
  OpenSSL::Crypto
  ${CURL_LIBRARIES}
  "-framework Foundation"
  "-framework Security"
  "-lz"
)

This compiles just fine. However, when I try to pull it into my Ubuntu VM and try to build it /build> cmake .., I get the following errors

CMake Error in CMakeLists.txt:
  Found relative path while evaluating include directories of "cpp-test":

    "IXWEBSOCKET_INCLUDE_DIR-NOTFOUND"



CMake Error in CMakeLists.txt:
  Found relative path while evaluating include directories of
  "test-helpers":

    "IXWEBSOCKET_INCLUDE_DIR-NOTFOUND"



-- Generating done

What I have tried...

  • I have installed vcpkg and created my symlink ln -s /path/to/vcpkg /usr/local/bin/vcpkg.
  • I have installed ixwebsocket via vcpkg install ixwebsocket, but it seems that the CMAKE_TOOLCHAIN_FILE is not being parsed correctly.

I'm a bit lost, any help would be appreciated

  • "I have installed ixwebsocket via `vcpkg install ixwebsocket`" - So why don't use `find_package(ixwebsocket)` in your code? vcpkg helps only in finding **packages** (via `find_package`), it doesn't help to find things via direct `find_library` or `find_path`. – Tsyvarev Oct 12 '22 at 10:09
  • 1
    I wasn't aware of that. If that's the case, the documentation here is wrong https://machinezone.github.io/IXWebSocket/build/, which is what I was following – Jose Arrillaga Oct 12 '22 at 10:21
  • Yes, the documentation looks weird. According to [CMakeLists.txt](https://github.com/machinezone/IXWebSocket/blob/master/CMakeLists.txt#L290) the project definitely supports `find_package`, but the documentation suggests to use `find_library` and `find_path`... – Tsyvarev Oct 12 '22 at 10:47

1 Answers1

0

This is not a great answer to the issue, but I ended up resolving it by building ixwebsocket via CMake instead.

It seems that vcpkg was not compatible with the linux distro in my VM.