CMake基本用法
我正在尝试使用 CMake 构建我的库。我正在处理 CMakeLists.txt 。
我希望能够执行以下操作:
我有一个名为“然后”的目录
include
src
,其中有 阿吉文件夹。 该文件夹中是库的子文件夹。
到目前为止,我收集到的信息是:
我需要做:
set(AGUI_SOURCES
src/Agui/Rectangle.cpp
src/Agui/xxx.cpp (and so on)
)
然后我认为需要做:
include_directories(./include)
然后我不太确定。
我知道 add_library 会参与其中,但我不确定如何参与。
问题是,我想创建 2 个选项:DLL 或静态。
如果是DLL,则必须定义AGUI_BUILD_DLL。
因此,根据这些信息:
- 我走在正确的道路上吗?
- 如何创建选项
- add_library 中应放入什么
- 如果用户想要 DLL 版本,如何添加预处理器 AGUI_BUILD_DLL?
如果其中任何一个或所有这些问题都能得到解答,我将不胜感激。
谢谢
I'm trying to build my library with CMake. I'm working on CMakeLists.txt .
I want to be able to do the following:
I have a directories called
include
src
Then inside of these there is
Agui folder.
And in that folder are the sub folders of the library.
So far from what I've gathered:
I'll need to do:
set(AGUI_SOURCES
src/Agui/Rectangle.cpp
src/Agui/xxx.cpp (and so on)
)
Then I think need to do:
include_directories(./include)
And then I'm not quite sure.
I know that add_library will be involved but I'm not sure how.
The thing is, I want to create 2 options: DLL, or static.
If it is DLL, then AGUI_BUILD_DLL must be defined.
So based on this information:
- Am I on the right track?
- How do I create the options
- What do I put in add_library
- How do I add the preprocessor AGUI_BUILD_DLL if the user wants the DLL version?
If any or all of these could be answered I would greatly appreciate it.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您查看 CMake 教程,其中介绍了添加可执行文件、库、系统自省等。 cmake 命令也是自记录的,因此在命令行输入时,
将为您提供 add_library 命令的文档。您可以使用 --help-commands 获取所有 CMake 命令文档的完整列表。因此,您可以使用 option 命令添加用于构建共享或静态的选项,并使用 add_definitions 命令添加预处理器定义。
例如,
您应该注意 targetName_EXPORTS 将在构建库时定义,因此可以在 declspec 逻辑中使用。这是由 CMake 完成的,在 Unix 系统上的 GCC 中使用可见性支持时也很有用。
I would recommend taking a look at the CMake tutorial which covers adding executables, libraries, system introspection etc. The cmake command also self documents, so on the command line entering,
would give you the documentation for the add_library command. You could use the --help-commands to get a full listing of all CMake command documentation. So you can use the option command to add an option for building shared or static, and use the add_definitions command to add a preprocessor definition.
For example,
You should note targetName_EXPORTS will be defined when building the library, and so can be used in the declspec logic. This is done by CMake, and is also useful when using visibility support in GCC on Unix systems.
靠近 CMakeLists.txt 开头的某个位置。您可能想要使用 ON 而不是 OFF - 取决于您是否希望 DLL 构建为默认值。
3,4。
somewhere near the start of CMakeLists.txt. You may want to use ON instead of OFF - depends on whether you want DLL build to de default.
3,4.