CMake:如何在“标题文件"中显示标题在Visual Studio项目中? [英] CMake: How to show headers in "Header files" in Visual Studio project?

查看:50
本文介绍了CMake:如何在“标题文件"中显示标题在Visual Studio项目中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用C ++创建了一个简单的库项目,并添加了CMake文件以自动生成Visual Studio项目.我的小型项目仅包含2个文件:

I have created a simple library project in C++ and added CMake file to automatically generate a Visual Studio project. My small project contains only 2 files:

include/
     testproject/
         testproject.h
src/
    testproject.cpp

CMakeLists.txt

头文件现在位于外部依赖项中(截图).如何在标题"部分显示它?(或其他任何条件.只是不是外部依赖关系")

Header file now in External Dependencies (screenshot). How to display it in the section "Headers"? (or any other. Just not "External Dependencies")

CMakeLists.txt:

CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

SET(PROJECTNAME testproject)

PROJECT(${PROJECTNAME})

FILE(GLOB MY_HEADERS "include/*.h")
FILE(GLOB MY_SOURCES "src/*.cpp")

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
ADD_LIBRARY(
    ${PROJECTNAME} STATIC
    ${MY_HEADERS} ${MY_SOURCES}
)

注意:如果将目录结构更改为

Note: If change dirs struct to

include/
     testproject.h
src/
    testproject.cpp

CMakeLists.txt

结果类似于屏幕截图.头文件"中的头文件.但是我需要以前的项目结构

result will be like on a screenshot. Header file in "Header files". But I need in previous project structure

推荐答案

使用 GLOB_RECURSE :

GLOB_RECURSE将生成类似于常规GLOB的列表,除了它将遍历匹配目录的所有子目录并匹配文件.仅当给出FOLLOW_SYMLINKS或cmake策略CMP0009未设置为NEW时,才遍历作为符号链接的子目录.有关更多信息,请参见cmake –help-policy CMP0009.

GLOB_RECURSE will generate a list similar to the regular GLOB, except it will traverse all the subdirectories of the matched directory and match the files. Subdirectories that are symlinks are only traversed if FOLLOW_SYMLINKS is given or cmake policy CMP0009 is not set to NEW. See cmake –help-policy CMP0009 for more information.

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

SET(PROJECTNAME testproject)

PROJECT(${PROJECTNAME})

FILE(GLOB_RECURSE MY_HEADERS "include/*.h")
FILE(GLOB MY_SOURCES "src/*.cpp")

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
ADD_LIBRARY(
    ${PROJECTNAME} STATIC
    ${MY_HEADERS} ${MY_SOURCES}
)

这篇关于CMake:如何在“标题文件"中显示标题在Visual Studio项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆