Repository navigation
Conversation
cmake --install now installs the headers, the shared and the static library and a package (ClarabelConfig.cmake and its version file) that defines the imported targets Clarabel::clarabel_c and Clarabel::clarabel_c_static, so that another project can use an installed Clarabel.cpp with find_package(Clarabel). The same names are aliases of the two interface targets when Clarabel.cpp is added with add_subdirectory. The cargo target is built by default, since the examples, which were the only targets depending on it, can now be left out with CLARABEL_BUILD_EXAMPLES=OFF. The compile definitions of the enabled features are passed on to the installed targets. The static library also needs the system libraries of the Rust standard library: on Linux both libclarabel_c_static and the installed static target now link them, while before any executable linked to libclarabel_c_static failed with undefined references to log, exp and the like. The shared library has no SONAME, so the installed target is marked IMPORTED_NO_SONAME, and executables record libclarabel_c.so rather than the absolute path of the library.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
At the moment
cmake --installdoes nothing, so a project that wants to link Clarabel.cpp without adding it as a subdirectory has to copy the headers andrust_wrapper/target/release/libclarabel_c.*by hand and write its own find module. I use Clarabel.cpp as a QP backend of a C++ library (SMS++) and of its packages, where this is what I ended up doing.This PR adds:
install()rules for the headers (include/as it is), the shared and the static library, withGNUInstallDirs, and on Windows the DLL inbin;lib/cmake/Clarabel/ClarabelConfig.cmake(plus the version file) that defines the imported targetsClarabel::clarabel_candClarabel::clarabel_c_static, with the include directory, theFEATURE_*definitions of the enabled cargo features, andEigen3::Eigenif Eigen is found (the C++ headers need it, the C ones do not);libclarabel_c_sharedandlibclarabel_c_static, so that a consumer is written the same way withfind_packageand withadd_subdirectory;CLARABEL_BUILD_EXAMPLES(default ON, as now); since the examples were the only targets depending on the cargo target,libclarabel_cis now built byALL, otherwise with the examples off nothing would trigger cargo;Two details I ran into while testing:
cargo rustc -- --print native-static-libsgives-lgcc_s -lutil -lrt -lpthread -lm -ldl -lchere). Without them, linking an executable to the currentlibclarabel_c_staticfails with undefined references tolog,expand so on, so on Linux bothlibclarabel_c_staticand the installed static target now linkThreads::Threads ${CMAKE_DL_LIBS} m rt util. I did not add a list for macOS and Windows, which I cannot test;libclarabel_c.sohas no SONAME, so linking it by full path records that absolute path in the executable; the installed target is markedIMPORTED_NO_SONAME, and the executable recordslibclarabel_c.so, found through its RUNPATH.I tested it on Linux (Ubuntu 24.04, GCC 13.3, CMake 3.28, Rust stable) with a separate project built against the installed tree, which compiles
examples/c/example_qp.cagainst both targets andexamples/cpp/example_qp.cppagainst the shared one (all three solve), and with the same C example linked toClarabel::clarabel_c_staticthroughadd_subdirectory. The default build with the examples is unchanged, and-DCLARABEL_CARGO_FEATURES=serde,faer-sparsegivesFEATURE_FAER_SPARSE;FEATURE_SERDEin the installed package.#72 also adds install rules, for the use in acados; this PR installs the headers and a package with targets as well, and keeps the build directory logic as it is.