Visual Studio 2010 Project File Filters

I have a complex C / C ++ application group that I am working on, and which should also be platform independent. It is still compatible with UNIX / Windows and works fine. However, supporting 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, since everyone is platform independent, I had to completely separate the builders from the sources. IMHO, this in itself is a very good practice, and this should be respected by everyone :)

Here's the problem now ... VS2010 is completely unusable when you have to organize include / sources files in filters. You must do this manually by re-doing โ€œAdd โ†’ New Filterโ€ and then โ€œAdd โ†’ Output Elementโ€. I have a VERY complex folder structure and files in each included folder. The task of creating filters becomes a full day job. On the other hand, I could just drag the entire folder from Explorer to the project inside VS2010, but all the header / source files will be placed there without any filters, which makes it useless: you cannot search in 100 files for the correct one without hierarchy .

Question: Is VS2010 any obscure way to import a folder AND save the folder structure as filters? It seems to me that the M $ FT people who created VS2010 believe that M $ FT is the only animal in the jungle, and you MUST contaminate the source folder with building projects so you can use "show hiden files" to turn them on into the project along with the folder structure. This is absurd IMHO ...

+4
source share
1 answer

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

In a CMake file, you can group files using the source_group command. Filters will be automatically generated for vs according to the source groups. I do not know other IDEs such as Code :: Blocks or NetBeans.

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

 # 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() 
+8
source

Source: https://habr.com/ru/post/958955/


All Articles