Skip to content

Missing files in Visual Studio solutiun/projects when generated from Cmake #98

@davidhunter22

Description

@davidhunter22

If you generate a Visual Studio project using a command like cmake --preset=test-msvc and then open the generated solution in Visual Studio a number of files are missing. This is mostly header files which is reasonable as most build systems like ninja or make don't need to "see" the header files and a #include will find them fine. However if you want to edit them in an IDE it's a pain no having them.

So the PR I will submit does the following

  1. Files like src/ifc-dom/common.hxx are added to the relevant project
  2. Adds the following custom target. This is a target that does nothing in the build. It does however show up in the IDE
add_custom_target(ifc-include SOURCES
    include/ifc/abstract-sgraph.hxx
    include/ifc/assertions.hxx
    include/ifc/basic-types.hxx
    include/ifc/file.hxx
    include/ifc/index-utils.hxx
    include/ifc/operators.hxx
    include/ifc/pathname.hxx
    include/ifc/pp-forms.hxx
    include/ifc/reader.hxx
    include/ifc/source-word.hxx
    include/ifc/tooling.hxx
    include/ifc/underlying.hxx
    include/ifc/util.hxx
    include/ifc/version.hxx
    include/ifc/dom/node.hxx
)
  1. Add the following VS_SOLUTION_ITEMS property. This makes the files show up as solution files in the VS IDE. VS_SOLUTION_ITEMS is a new cmake 4.0 feature. If you use an older cmake or generate for ninja or similar the VS_SOLUTION_ITEMS property is just ignored.
set( SolutionItems
    .clang-format
    .gitignore
    CMakePresets.json
    LICENSE.txt
    README.md
    vcpkg.json)
set_property(DIRECTORY APPEND PROPERTY VS_SOLUTION_ITEMS ${SolutionItems})
source_group("Solution Items" FILES ${SolutionItems})
  1. Stop the files in a project being put into sub folders with names like "Sources" and "Headers". This may be useful if you have a lot of file in a project but is extremely annoying if you don't. I don't think this would have an effect on other generators but there is a guard just in case
# By default we don't want the Visual Studio default "sources" and "headers" folders, the following put's everything directly in the project. 
if (${CMAKE_GENERATOR} MATCHES "^Visual Studio")
    source_group( " "  REGULAR_EXPRESSION .*)
endif()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions