简体   繁体   English

在没有 CMakeLists.txt 的情况下将目录添加到 CMake 项目

[英]Add directory to CMake project without CMakeLists.txt

I have the following project structure:我有以下项目结构:

  • CMakeLists.txt (top level) CMakeLists.txt(顶级)
  • include包括
    • source.h源码.h
  • examples例子
    • CMakeLists.txt CMakeLists.txt
    • example.cpp例子.cpp
  • src源代码
    • CMakeLists.txt CMakeLists.txt
    • source.cpp源码.cpp

Top level CMakeLists.txt includes both src and examples using add_subdirectory .顶级CMakeLists.txt包括src和使用add_subdirectoryexamples I want to do the same with include directory.我想对include目录做同样的事情。 I have no problem using the header files from include .我使用来自include的 header 文件没有问题。 What I want is to be able to see include directory in my IDE.我想要的是能够在我的 IDE 中看到include目录。 Currently, QtCreator doesn't show include directory if I open the top level CMake file with it.目前,如果我用它打开顶级 CMake 文件,QtCreator 不会显示include目录。

I know that I can add dummy CMakeLists.txt but that's a bit meh.我知道我可以添加虚拟CMakeLists.txt ,但这有点笨拙。 Don't want to do this for code readers sanity sake.为了代码阅读器的理智,不想这样做。

add include_directories(include/) in your toplevel CMakeLists.txt just before using add_subdirectory在使用add_subdirectory之前,在顶层CMakeLists.txt中添加include_directories(include/)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM