c++ - 有没有办法将库更改添加为 cmake 中的依赖项?
问题描述
我有一个使用 CMake 构建的应用程序和一个库,如果可能的话,我想简化构建过程。就目前而言,如果库发生更改并且我重建应用程序,CMake 不会重建修改后的库文件。同样,如果我重建库然后make
在应用程序上运行,它会说无事可做。我目前的解决方法是使用 bash 脚本来重建所有内容,但这会不必要地重新编译大量文件,如果可能的话,我想在应用程序的构建目录中处理它们。
用简单的例子更新:
有 3 个文件夹:app
、lib
和include
。 include
包含test_program.h
、lib
包含test_program.cpp
和app
包含test.cpp
其中包含test_program.h
。
这是CMakeLists.txt
for lib
:
include_directories(.)
add_library (test_lib STATIC
test_program.cpp
)
这是CMakeLists.txt
for app
:
include_directories(
.
../include
)
link_directories(
../../lib/build
)
add_executable(test_exe
test.cpp
)
target_link_libraries(
test_exe
test_lib
)
我想这样做,test_program.cpp
如果我对.cmake ../
make
app/build
test_program.cpp
更新:我在项目的顶层添加了一个顶层CMakeLists.txt
和一个build
。该文件非常简单,似乎从一开始就是我想要的:
add_subdirectory(app)
add_subdirectory(lib)
如果这里有任何改进,我很乐意接受建议。
解决方案
推荐阅读
- javascript - 取消选中复选框后如何从数组中删除元素
- xamarin.ios - Xcode 11 更新后 Xamarin iOS 模拟器黑屏
- sql - 如何在 Asp.net Mvc 中显示没有模型的数据?
- rest - rest - 将用户限制在自己的数据中的方法
- java - 如何在 Spring MVC Web 应用程序中创建会话范围的调度程序?
- python - 如何像在 ggplot 中一样在 matplotlib 中创建堆积条形直方图
- node.js - 提交表单时无法发布/注册错误 - NodeJs
- amazon-web-services - API网关将某些IP列入白名单
- linux - 如何将文件从 linux 实例正确复制到 aws ec2 实例?
- javascript - 我的包含 javascript 变量的回声不起作用