CMAKE-如何正确地将静态库的头文件复制到/ usr / include? [英] CMAKE - How to properly copy static library's header file into /usr/include?
本文介绍了CMAKE-如何正确地将静态库的头文件复制到/ usr / include?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用C进行CMAKE使用,实际上我正在创建两个非常小的静态库。
I'm getting into CMAKE usage with C and actually I'm creating two very small static libraries.
我的目标是:
- 库被编译并链接到* .a文件中。 [此
工作] - 然后我希望将* .a文件复制到/ usr / local / lib [这也应工作]
- 据我所知,关于库(很少),它们是使用
-lnameoflib
链接的,这是一个编译器标志。好。我已经准备好了CMakeLists.txt,它实际上将* .a文件复制到/ usr / local / lib
中。但是,为了能够在程序中使用它们,我还需要将其头文件复制到/ usr / local / include
中,然后可以通过简单的方法将它们包括在#include< mylibheader.h>
。这就是我现在的理解。
- The libraries are compiled and linked into *.a files. [THIS WORKS]
- Then I wish to copy that *.a files into /usr/local/lib [THIS ALSO WORKS]
- As far as I know about libraries (very little), they are linked using
-lnameoflib
, which is a compiler flag. OK. I have prepared my CMakeLists.txt and it actually copies *.a files into/usr/local/lib
. However, to be able to use them in a program, I also need to copy their header files into/usr/local/include
, then I can include them the easy way#include <mylibheader.h>
. That's how I understand it now.
我的问题是-将头文件复制到/ usr / include文件夹的正确方法是什么? CMAKE?我希望在执行 make install
时自动复制它们,例如* .a文件。
And my question is - how is the proper way of copying header files into /usr/include folder with CMAKE? I would like it to copy them automatically when make install
is executed, like *.a files are.
这两个库我都有一个比较简单的CMakeLists.txt:
For both of the libraries I have a smiliar CMakeLists.txt:
project(programming-network)
add_library(programming-network STATIC
send_string.c
recv_line.c
)
INSTALL(TARGETS programming-network
DESTINATION "lib"
)
推荐答案
最新的cmake版本的更好方法是:使用目标的 PUBLIC_HEADER
属性。
A better way for newest cmake version is to use target's PUBLIC_HEADER
properties.
project(myproject)
add_library(mylib some.c another.c)
set_target_properties(mylib PROPERTIES PUBLIC_HEADER "some.h;another.h")
INSTALL(TARGETS mylib
LIBRARY DESTINATION some/libpath
PUBLIC_HEADER DESTINATION some/includepath
)
部分参考文献:
这篇关于CMAKE-如何正确地将静态库的头文件复制到/ usr / include?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文