Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preserving directory structure

Tags:

c++

cmake

I've got a project with the following structure :

  • src

    • tools
    • modules
    • core
      • shader
      • buffer
  • inc

    • tools
    • modules
    • core
      • shader
      • buffer

CMake create my project with all .cpp files in a unique folder "Source files". I'm trying to preserve the original structure here is my CMakeLists.txt :

# Paths.
set( SRCROOT ${PROJECT_SOURCE_DIR}/src/Framework/Graphic )
set( INCROOT ${PROJECT_SOURCE_DIR}/inc/Framework/Graphic )

# Get .hpp and .cpp files.
file(
    GLOB_RECURSE
    GRAPHIC_FILES
    ${SRCROOT}
    ${INCROOT}
)

# Packages.
find_package(OpenGL REQUIRED)

# Create the library.
add_library(Graphic ${GRAPHIC_FILES} )

How can I handle that ? Thanks for your time!

like image 820
Dono Avatar asked Sep 06 '25 03:09

Dono


1 Answers

I'm assuming that you are creating a Visual Studio project with CMake and want to visualize the source files as they are organized in the file system.

You can do that by using the CMake source group command explicitely for files in each subfolder.

FILE(GLOB TOOLS_FILES
    ${SRCROOT}/src/tools/*
)
SOURCE_GROUP(tools FILES ${TOOLS_FILES})

... and so on. (Not tested code)

like image 85
ronkot Avatar answered Sep 09 '25 17:09

ronkot