在我们的工作流程中,我们可以有一个由多个头文件组成的 module A,module A 不会产生任何二进制文件(旁注:它显然会被使用由其他模块,包括来自 module A 的一些 header 以生成二进制文件)。
一个很好的例子是一个只有头文件的库,由于 INTERFACE
库的概念,CMake 3 引入了很好的支持(参见 this SO answer 和 CMake 的 documentation of the feature )。
我们可以用模块A制作一个接口(interface)库目标:
add_library(module_A INTERFACE)
这为我们提供了 CMakes 目标的所有优秀特性(可以将其用作另一个目标的依赖项、导出它、传递转发需求等)
但在这种情况下,module A 中的 header 不会显示在我们的 IDE 中(Xcode,但我们希望它与大多数/所有其他 IDE 相同)。
这被证明是工作流程中的一个主要缺点,因为我们需要在 IDE 中显示组成 module A 的文件以进行编辑。有可能实现吗?
最佳答案
几个月后,我没有找到直接列出 INTERFACE
库的头文件的方法。
由于问题仍然有一些观点,这就是我最终做的事情(即看起来像当前可用的较小黑客)。
想象一下 module A 是一个只有头文件的库。在 CMakeLists.txt 中声明其目标:
# Define 'modA_headers' variable to list all the header files
set(modA_headers
utility.h
moreUtilities.h
...)
add_library(moduleA INTERFACE) # 'moduleA' is an INTERFACE pseudo target
#
# From here, the target 'moduleA' can be customised
#
target_include_directories(moduleA ...) # Transitively forwarded
install(TARGETS moduleA ...)
#
# HACK: have the files showing in the IDE, under the name 'moduleA_ide'
#
add_custom_target(moduleA_ide SOURCES ${modA_headers})
我不接受这个答案,因为我希望 CMake 的进一步版本能够提供更语义正确的方法,然后会被接受:)
关于c++ - 如何在 IDE 中让 CMake 显示不属于任何二进制目标的 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27039019/