本文介绍了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 :
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项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!