将预编译库集成到 C++使用 CMakeExternalProject 的代码库
我想将CasADi集成到CMake 的 C++ 代码库作为 ExternalProject
。 为此,我想使用预编译库,因为从源代码构建是 不推荐。到目前为止,我只编写了以下内容:
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)
并且我注意到所有二进制文件都已正确下载到指定的文件夹中。但是,我不知道如何将我的目标链接到CasADi,也不知道如何找到该包。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ExternalProject_Add 有一个天然的问题:
因此,在项目的配置阶段不会进行下载,这使得使用
find_package
变得困难,因为在项目配置阶段无法找到文件。首先配置运行。获取此 CMakeLists.txt:
为了使用它,您必须执行以下操作:
find_package
将找到所需的文件如果你想要一步构建,有一些方法可以解决这个问题
ExternalProject_Add
命令在子文件夹中创建子 cmake 项目,并通过在您自己的 CMakeLists.txt 中手动执行适当的构建(下载)步骤execute_process
调用:https://stackoverflow.com/a/37554269/8088550这是第二个选项的示例,由于 FetchContent 可能会更好不具备ExternalProject的全部功能。
main.cpp
CMakeLists.txt
external/CMakeLists.txt
重点是在
external/CMakeLists.txt<下有另一个cmake项目/code>,它通过主 cmake 项目的
execute_process
调用进行配置和构建。请注意,您现在可以在配置阶段使用find_package(casadi REQUIRED ...)
,因为下载将在之前进行。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.