如何使用Cmake将通用头文件文件夹下的头子文件夹中的头文件分组

发布于 2024-09-27 21:31:11 字数 183 浏览 0 评论 0原文

您好,我正在构建基于 Cmake 的构建系统。 我想将头文件分组到通用文件夹 Header Files 下的文件夹中(VC++ 可以做到)。 类似地,我想将相应的 .cpp 文件分组到 Source Files 目录下的文件夹中。 不幸的是我找不到任何关于如何操作的说明。

请帮忙。

迪米特雷

Hi I am building Cmake based build system.
I would like to group header files in folders (VC++ can do it) under the general folder Header Files.
Similar, I would like to group the corresponding .cpp files in folders under the Source Files directory.
Unfortunately I could not find any instructions of how to do it.

Please help.

Dimitre

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赢得她心 2024-10-04 21:31:11

您应该看看 CMake source_group 命令。

You should give a look at CMake source_group command.

蓝礼 2024-10-04 21:31:11

您可以使用 source_group。这是一个具体的例子。

假设你有一个像这样的目录结构:

|-include
    | some.h
    |-sub
       | someother.h 
|-src
   | some.cpp
   |-sub
      |-someother.cpp

收集文件(有些人 - 包括文档 - 不鼓励使用 GLOB,但我把它留给你,如果你愿意,你可以列出它们之一,尽管我发现 GLOB 就可以了很多次):

file(GLOB HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
file(GLOB HEADER_FILES_SUB "${CMAKE_CURRENT_SOURCE_DIR}/include/sub/*.h")
file(GLOB SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h")
file(GLOB SOURCE_FILES_SUB "${CMAKE_CURRENT_SOURCE_DIR}/src/sub/*.h")

# Setup your library or executable:
add_library(MY_LIB ${HEADER_FILES} ${HEADER_FILES_SUB}
                   ${SOURCE_FILES} ${SOURCE_FILES_SUB})

# Here's the important part ("Header Files" and "Source Files" are literals.)
source_group("Header Files\\sub" ${HEADER_FILES_SUB})
source_group("Source Files\\sub" ${SOURCE_FILES_SUB})

You can use source_group. Here's a concrete example.

Suppose you have a directory structure like:

|-include
    | some.h
    |-sub
       | someother.h 
|-src
   | some.cpp
   |-sub
      |-someother.cpp

Collect the files (some people - including the documentation - discourages use of GLOB, but I leave that to you, you can list of them one by if you want to, though I find GLOB is just fine many times):

file(GLOB HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
file(GLOB HEADER_FILES_SUB "${CMAKE_CURRENT_SOURCE_DIR}/include/sub/*.h")
file(GLOB SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h")
file(GLOB SOURCE_FILES_SUB "${CMAKE_CURRENT_SOURCE_DIR}/src/sub/*.h")

# Setup your library or executable:
add_library(MY_LIB ${HEADER_FILES} ${HEADER_FILES_SUB}
                   ${SOURCE_FILES} ${SOURCE_FILES_SUB})

# Here's the important part ("Header Files" and "Source Files" are literals.)
source_group("Header Files\\sub" ${HEADER_FILES_SUB})
source_group("Source Files\\sub" ${SOURCE_FILES_SUB})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文