I want to integrate CasADi into a CMake-based C++ codebase as an ExternalProject
. For this purpose, I would like to use pre-compiled libraries because building from source is not recommended. So far, I have only managed to write the following:
ExternalProject_Add(
casadi-3.5.5
URL https://github.com/casadi/casadi/releases/download/3.5.5/casadi-linux-py39-v3.5.5-64bit.tar.gz
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
PREFIX ${CMAKE_BINARY_DIR}/external/casadi)
and I noticed that all the binaries are correctly downloaded in the specified folder. However, I do not know how to link my targets to CasADi, nor how to find the package.
There is a natural problem with ExternalProject_Add:
Hence, download will not happen at the configure stage of your project which makes it difficult to use
find_package
, because the files cannot be found during your first configure run.Take this CMakeLists.txt:
In order to use it you have to do the following:
find_package
will find the needed filesIf you want a one step build, there are ways to get around this problem
ExternalProject_Add
commands and execute the approriate build (download) steps manually in your own CMakeLists.txt viaexecute_process
calls: https://stackoverflow.com/a/37554269/8088550Here is an example for the second option, which might be better since FetchContent doesn't have the full functionality of ExternalProject.
main.cpp
CMakeLists.txt
external/CMakeLists.txt
The point is to have another cmake project under
external/CMakeLists.txt
, which gets configured and build viaexecute_process
calls from the main cmake project. Do note, that you can now havefind_package(casadi REQUIRED ...)
at configure stage, because the download will happen just before.