以下是我的目录结构,我想使用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构建之后,所有源文件都放在一个文件夹中,所有头文件都放在另一个文件夹中。但是,我想保持与原来相同的目录结构
请告诉我,我应该在我的CMakeLists.txt文件中修改任何内容,以获得与最初存在的目录结构相同的目录结构。
答案 0 :(得分:0)
不要使用 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})