Home › Forum › SOFA › Programming with SOFA › Link SOFA as an external dependency in a c++ project
- This topic has 3 replies, 3 voices, and was last updated 5 years, 10 months ago by Hugo.
-
AuthorPosts
-
19 October 2016 at 13:46 #7581Bruno MarquesBlocked
Hi there,
I would like to use SOFA packages as external dependencies of a c++ program, but can’t figure out how to specify it in my CMake file.
When using a library like OpenCV for instance, it is possible to do a ‘find_package’ after only providing an OpenCV_DIR entry in CMake. I would like to do the same with Sofa, by doing the following:
set(SofaFramework_DIR path_to_sofa_install/lib/cmake/SofaFramework CACHE PATH “sofa”)
find_package(SofaFramework REQUIRED)but when I try to configure my project, I get cmake errors as it can’t find its dependencies (TinyXML / ZLib etc.):
CMake Error at C:/Users/bruno/dev/sofa/build/install/lib/cmake/SofaFramework/SofaFrameworkConfig.cmake:36 (find_package): By not providing "FindTinyXML.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "TinyXML", but CMake did not find one. Could not find a package configuration file provided by "TinyXML" with any of the following names: TinyXMLConfig.cmake tinyxml-config.cmake Add the installation prefix of "TinyXML" to CMAKE_PREFIX_PATH or set "TinyXML_DIR" to a directory containing one of the above files. If "TinyXML" provides a separate development package or SDK, be sure it has been installed. Call Stack (most recent call first): CMakeLists.txt:77 (find_package)
The CMakeLists Cheatsheet tells me to specify CMAKE_MODULE_PATH to link sofa as an other program’s dependency:
CMAKE_MODULE_PATH=/path/to/sofa/lib/cmake cmake /path/to/myProject/src
which I unsuccessfully did.
Is there a way, preferably in one single CMake entry (like SOFA_DIR) to simply specify where to find Sofa packages?
19 October 2016 at 14:03 #7582jnbrunetModeratorHey Bruno,
In my case, I usually set the CMAKE_PREFIX_PATH variable to the sofa’s install cmake directory.
ex:
cmake -DCMAKE_PREFIX_PATH=/home/user/sources/sofa/build/install/lib/cmake
Note that if I use the source’s cmake directory or the build’s cmake directory (without the /install in the previous path), this may not work, you really need to do a “make install” inside your build directory.
After that, I generally use, for example,
find_package(SofaGeneral REQUIRED)
find_package(SofaBase REQUIRED)
(…)
target_link_libraries(${PROJECT_NAME} SofaComponentGeneral SofaBaseTopology)Hope that helps,
Jean-Nicolas19 October 2016 at 14:55 #7583Bruno MarquesBlockedHi Jean-Nicolas
Thanks for your quick answer.
I tried what you said, but I got the same issue on windows. Though, I used CMAKE_PREFIX_PATH successfully on Linux, so it must be a CMake issue specific to Windows.Does anyone have any idea why it wouldn’t work on Windows?
Cheers,
Bruno25 February 2019 at 19:18 #13118 -
AuthorPosts
- You must be logged in to reply to this topic.