4

The following is my directory structure and I want to generate a cmake file (.xcodeproj / codeBlock project file for ubuntu or just a simple make file) using CMake.

├── 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

These are the following commands used in my CMakeLists.txt

cmake_minimum_required(VERSION 2.8.9)
PROJECT(KeyPointEvaluation CXX)
SET( PROJ_NAME  "KeyPointEvaluation" )
set(CMAKE_BUILD_TYPE Release)

For openCv library

find_package( OpenCV REQUIRED )

These are the directories, I think that I should include one by one for maintaining the same directory structure.

#Bring the headers and other files needed for the project to complile
SET( PROJ_INCLUDES  "ExternalLibs" "FeatureExtractors" "hdr" "ImageProcessing" "Products" "util")

Again for having the same nice directory structure of project as it existed originally after generating build, I did the following

#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")

Adding openCv, source and headers

INCLUDE_DIRECTORIES( ${PROJ_INCLUDES} )
ADD_EXECUTABLE( ${PROJ_NAME} ${PROJ_SOURCES} ${PROJ_HEADERS})
target_link_libraries( KeyPointEvaluation ${OpenCV_LIBS} )

Now the problem is that after CMake build, all the source files are put into one folder and all the header files are into another folder. But, I wanted to maintain the same directory structure what I had originally

enter image description here

Please tell me there is anything I should modify in my CMakeLists.txt file to obtain same directory structure as existed originally.

Tanmoy Mondal
  • 449
  • 1
  • 6
  • 12

1 Answers1

0

instead of using FILE( GLOB_RECURSE ) do the following:

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})

You can add extra structure by adding a prefix, e.g.:

source_group(TREE "${CMAKE_CURRENT_LIST_DIR}" PREFIX "ExtraFolderName" FILES ${PROJ_SOURCES})