How to set Visual Studio Filters for nested sub directory using cmake

前端 未结 4 569
北海茫月
北海茫月 2020-11-30 04:57

I have following structure

Main (dir)
      +-- CMakeLists.txt
      +-- File.cpp
      +-- File.hpp
      +-- Dir (dir)
          +-- CMakeLists.txt
                


        
4条回答
  •  温柔的废话
    2020-11-30 05:30

    I know that using the CMAKE glob function is usually frowned upon: Why is CMAKE glob evil, but in my case I found it to better than explicitly naming each file. I figured I would include a modified version of Florian's answer using GLOB.

    # This code sorts the project files as they appear in the root directory
    
    # Generate a list of all .c & .h files in the current directory and sub directores.
    file(
         GLOB_RECURSE source_list RELATIVE
         "${CMAKE_CURRENT_SOURCE_DIR}"
         *.c *.h
        )
    foreach(source IN LISTS source_list)
        get_filename_component(source_path "${source}" PATH)
        string(REPLACE "/" "\\" source_path_msvc "${source_path}")
        source_group("${source_path_msvc}" FILES "${source}")
    endforeach()  
    message(STATUS "Tree reorganized")
    

提交回复
热议问题