gpt4 book ai didi

xcode - 为什么在 cmake 构建后不保留原始项目目录结构(在 Xcode Project File .xcodeproj 中可见)

转载 作者:行者123 更新时间:2023-12-03 21:25:57 24 4
gpt4 key购买 nike

以下是我的目录结构,我想使用 CMake 生成一个 cmake 文件(ubuntu 的 .xcodeproj/codeBlock 项目文件或只是一个简单的 make 文件)。

├── ExternalLibs
│   ├── license.txt
│   ├── rapidxml.hpp
│   ├── rapidxml_iterators.hpp
│   ├── rapidxml_print.hpp
│   └── rapidxml_utils.hpp
├── FeatureExtractors
│   ├── FeatureExtactors.cpp
│   ├── HarrisKeyPoint.cpp
│   └── hdr
│   ├── BlurVarietyEnums.h
│   ├── CompressionVarietyEnums.h
│   ├── DescriptorExtractorType.h
│   ├── DescriptorMatcherType.h
│   ├── FeatureDetectorType.h
│   ├── FeatureExtactors.hpp
│   ├── HarrisKeyPoint.hpp
│   ├── ILLuminationVarietyEnums.h
│   ├── NoiseVarietyEnums.h
│   ├── OutlierFilter.h
│   └── openCVFeatureDetectorsExtractors.h
├── ImageProcessing
│   ├── ImageDeformationOperations.cpp
│   ├── ImageEnhancement.cpp
│   ├── MannualAdjustments.cpp
│   └── hdr
│   ├── Deforming_of_Image.hpp
│   ├── ImageDeformationOperations.hpp
│   ├── ImageEnhancement.hpp
│   └── MannualAdjustments.hpp
├── KeyPointDetectionTechniques.cpp
├── KeyPointEvaluation.cpp
├── Products
├── hdr
│   └── KeyPointDetectionTechniques.hpp
└── util
├── BasicAlgo.cpp
├── BasicAlgosUsingTemplates.cpp
├── DirectoryHandler.cpp
├── TiffImageReader.cpp
└── hdr
├── BasicAlgo.h
├── BasicAlgosUsingTemplates.hpp
├── DirectoryHandler.hpp
└── TiffImageReader.hpp

这些是我的 CMakeLists.txt 中使用的以下命令
cmake_minimum_required(VERSION 2.8.9)
PROJECT(KeyPointEvaluation CXX)
SET( PROJ_NAME "KeyPointEvaluation" )
set(CMAKE_BUILD_TYPE Release)

对于 openCv 库
find_package( OpenCV REQUIRED )

这些是目录,我认为我应该一一包含以保持相同的目录结构。
#Bring the headers and other files needed for the project to complile
SET( PROJ_INCLUDES "ExternalLibs" "FeatureExtractors" "hdr" "ImageProcessing" "Products" "util")

再次为了具有与生成构建后最初存在的项目相同的漂亮目录结构,我执行了以下操作
#Can manually add the sources using the set command as follows:
FILE( GLOB_RECURSE PROJ_SOURCES "FeatureExtractors/*.cpp" "ImageProcessing/*.cpp" "util/*.cpp" )
FILE( GLOB_RECURSE PROJ_HEADERS "FeatureExtractors/hdr/*.h" "FeatureExtractors/hdr/*.hpp" "hdr/*.h" "ImageProcessing/hdr/*.hpp" "util/hdr/*.hpp" "util/hdr/*.h" "ExternalLibs/hdr/*.hpp")

添加 openCv、源代码和标题
INCLUDE_DIRECTORIES( ${PROJ_INCLUDES} )
ADD_EXECUTABLE( ${PROJ_NAME} ${PROJ_SOURCES} ${PROJ_HEADERS})
target_link_libraries( KeyPointEvaluation ${OpenCV_LIBS} )

现在的问题是,在CMake build之后,所有的源文件都放在一个文件夹中,所有的头文件都放在另一个文件夹中。但是,我想保持与最初相同的目录结构

enter image description here

请告诉我,我应该在 CMakeLists.txt 文件中修改任何内容以获得与最初存在的目录结构相同的目录结构。

最佳答案

而不是使用 FILE( GLOB_RECURSE ) 执行以下操作:

set ( PROJ_SOURCES
"path/to/source1.cpp"
"path/to/source2.cpp"
)
set ( PROJ_HEADERS
"path/to/source1.h"
"path/to/source2.h"
)

source_group(TREE "${CMAKE_CURRENT_LIST_DIR}" FILES ${PROJ_SOURCES})
source_group(TREE "${CMAKE_CURRENT_LIST_DIR}" FILES ${PROJ_HEADERS})
您可以通过添加前缀来添加额外的结构,例如:
source_group(TREE "${CMAKE_CURRENT_LIST_DIR}" PREFIX "ExtraFolderName" FILES ${PROJ_SOURCES})

关于xcode - 为什么在 cmake 构建后不保留原始项目目录结构(在 Xcode Project File .xcodeproj 中可见),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48345594/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com