Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010 project file filters

I have a complex C/C++ bunch of applications that I'm working on which is supposed to also be platform independent. So far, is UNIX/Windows compatible and it runs fine. However, maintaing this monster on VS2010 is a nightmare. I have the following file structure:

/
  sources
    lib1
      include
        ...
      src
        ...
    lib2
      include
        ...
      src
        ...
    app3
      include
        ...
      src
        ...
  builders
    cmake
      ...
    make
      ...
    VS2010
      vs2010.sln
      lib1
        lib1.vcxproj
        lib1.vcxproj.filters
      lib2
        lib2.vcxproj
        lib2.vcxproj.filters
      app3
        app3.vcxproj
        app3.vcxproj.filters

As we can see, because everything is platform independent, I had to completely separate the builders from sources. IMHO, that itself is a very good practice and it should be enforced by everyone :)

Here is the problem now... VS2010 is completely unusable when it comes to organize the include/sources files in filters. You have to do that manually by repeatedly doing "Add -> New Filter" followed by "Add -> Exiting Item". I have a VERY complex folder structure and files in each and every include folder. The task for creating the filters becomes a full day job. On the other hand, I could just drag the whole folder from Explorer onto the project inside VS2010 but it will put all header/source files in there without any filters, rendering it worthless: you can't possible search within 100 files for the right one without having some sort of hierarchy..

Question is: Is VS2010 having some obscure way of importing a folder AND preserving the folder structure as filters? Looks to me that M$FT people who created VS2010 think that M$FT is the only animal in the jungle and you MUST pollute the sources folder with builders projects so you can leverage "show hiden files" to include them in the project along with the folder structure. That is absurd IMHO...

like image 405
shiretu Avatar asked Feb 17 '23 20:02

shiretu


1 Answers

You are using CMake, so I advise you stick with only this. You can generate makefiles and VS2010 project files with it (at least). For VS, the generated files are a sln and a bunch of vxproj (one for each project in the CMake script).

In CMake file you can group files, using the command source_group. The filters will be automatically generated for vs according to the source groups. I don't know for other IDE like Code::Blocks or NetBeans.

If you want automatic grouping based on file path [Comment request]:

# Glob all sources file inside directory ${DIRECTORY}
file(GLOB_RECURSE TMP_FILES
    ${DIRECTORY}/*.h
    ${DIRECTORY}/*.cpp
    ${DIRECTORY}/*.c
)

foreach(f ${TMP_FILES})
    # Get the path of the file relative to ${DIRECTORY},
    # then alter it (not compulsory)
    file(RELATIVE_PATH SRCGR ${DIRECTORY} ${f})
    set(SRCGR "Something/${SRCGR}")

    # Extract the folder, ie remove the filename part
    string(REGEX REPLACE "(.*)(/[^/]*)$" "\\1" SRCGR ${SRCGR})

    # Source_group expects \\ (double antislash), not / (slash)
    string(REPLACE / \\ SRCGR ${SRCGR})
    source_group("${SRCGR}" FILES ${f})
endforeach()
like image 192
Synxis Avatar answered Feb 19 '23 11:02

Synxis