ami-iit / meshcat-cpp

Self-contained C++ interface for the MeshCat visualizer
BSD 3-Clause "New" or "Revised" License
25 stars 4 forks source link

Use the library from the build directory (i.e. with add_subdirectory) #11

Closed wpumacay closed 1 year ago

wpumacay commented 1 year ago

First of all, thanks for making this package :smiley: . I'm trying to integrate Meshcat as visualizer for an application I'm developing. I got the example file working when using the library after installation; everything so far works right. However, I'm running into some issues when trying to use the library without installing it, and instead using FetchContent to grab the source of the library and using add_subdirectory to include the project into my CMake workflow.

This also happens if I try to build the example file along the library, and try to run the example, getting the following error:

terminate called after throwing an instance of 'std::runtime_error'
  what():  Unable to load index.html
Aborted (core dumped)

I noticed that the index.html file in the misc folder at the root of the project should be served, but the location used actually comes from the file FindResource.cpp.in, which when installing points to the installation location (e.g. /usr/local/share/MeshcatCpp/misc). This works when using the library after installing it. However, if we'd like to use the example that is being compiled along the library without installing it, I'd keep running into the error mentioned before.

Is it possible to update the FindResource.cpp.in or a similar file(s) to handle the case when we don't want to install the library into our system?.

traversaro commented 1 year ago

Hello @wpumacay ! See https://github.com/ami-iit/meshcat-cpp/pull/1#issuecomment-1412037838 for two possible ways of solving this problem.

wpumacay commented 1 year ago

Thanks!, I'll try it out :+1: .

traversaro commented 1 year ago

@wpumacay if it is ok I would keep the issue open so it is clear that this is an open problem, and we can close the issue once one solution is merged.

GiulioRomualdi commented 1 year ago

@wpumacay and @traversaro https://github.com/ami-iit/meshcat-cpp/pull/14 should fix this issue