Problems linking to installed preCICE static library via CMake
I'm trying to link to static preCICE via target_link_libraries(myTarget PRIVATE precice::precice), but it does not work for me. Instead, I must manually import all the preCICE’s dependencies:
find_package(precice REQUIRED CONFIG)
set(Boost_USE_STATIC_LIBS ON)
find_package (Boost REQUIRED COMPONENTS system program_options filesystem log log_setup thread unit_test_framework)
find_package (Eigen3 REQUIRED NO_MODULE)
And then:
target_link_libraries (${PROJECT_NAME}
PRIVATE
precice::precice
Eigen3::Eigen
Boost::boost
Boost::filesystem
Boost::program_options
Boost::system
Boost::log
Boost::log_setup
Boost::thread
Boost::unit_test_framework
)
And then still it wont work, because JSON and prettyprint are not found…
/usr/bin/ld: cannot find -lJSON
/usr/bin/ld: cannot find -lprettyprint
If this is needed, not renaming nlohmann_json to JSON could help, so people can use their system wide lib. And/or copy externally used json/printing libraries when make install.
System: Arch OS using newest CMake, preCICE, Eigen3, Boost, etc.
We currently don't recommend nor support building precice as a static library due to some of the problems you experienced.
Building a library as a static library exposes its privately linked dependencies. We use the header-only libraries eigen, json, numpy and prettyprint as private dependencies. They will be required by every target linking to precice via the link interface despite them being pure inferface libraries.
The real problem is petsc though, as finding it requires the user to use the FindPETSc script as well as its dependencies, which we would have to install alongside preCICE.
We could try to remove the header only dependencies from the link interface, but this requires a lot of tedious work which is better invested in other areas.
That said, I am happy to help you incorporate a contributed solution to the aforementioned problem into the project.
I see, thanks for the info. I don't have a problem using preCICE as shared library, rather was curious.
I have to disagree with removing header-only dependencies from linking as tedious. Tedious is at the moment - creating CMake subdir for each header-only dependency. You could just include those folders in the main project.
@j8asic I would like to keep this issue open as this it still is a problem that we need to address at some point.