CMake 3.9 now creates “autogen” projects in Visual

2020-07-02 06:28发布

问题:

We're using CMake, Qt, and Visual Studio. Many of our projects are configured to run automoc, via passing AUTOMOC ON to add_library.

We recently updated to CMake 3.9.1, and Visual Studio now shows an additional project for every automoc'd library. For example, we now have a "Core" project and a "Core_autogen" project in our solution.

(this occurs in both VS2015 and VS2017, and both Qt 5.8 and 5.9.1)

This has a few annoying consequences:

  • Nearly double the number of projects, adding a lot of visual clutter.
  • Automoc no longer runs when building an individual project through the UI, which can lead to subtle bugs when debugging build issues for a specific project.

Does anyone know if there's a way to restore the previous CMake behavior for autogen?

Or barring that, some way to at least reduce the visual clutter of the autogen projects?

回答1:

This is a regression and supposed to be fixed in CMake 3.10. The CMake bug report is here: https://gitlab.kitware.com/cmake/cmake/issues/17205



回答2:

According to the CMake v3.9 Documentation, you could use AUTOGEN_BUILD_DIR to move the generated files to a different folder.

By default CMake uses <dir>/<target-name>_autogen where:

<dir> is CMAKE_CURRENT_BINARY_DIR and <target-name> is NAME

Or from the AUTOMOC property you could use:

The global property AUTOGEN_TARGETS_FOLDER can be used to group the automoc targets together in an IDE, e.g. in MSVS.

The global property AUTOGEN_SOURCE_GROUP can be used to group files generated by AUTOMOC together in an IDE, e.g. in MSVS.

Hope this helps.



回答3:

This collects all autogen projects in one folder:

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY AUTOGEN_TARGETS_FOLDER AutoMoc)