19

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?

Alex Goldberg
  • 975
  • 11
  • 14
  • Maybe `set_property( GLOBAL PROPERTY USE_FOLDERS ON )` will help? – Dmitry Sazonov Aug 28 '17 at 09:31
  • Check out [issue 17205](https://gitlab.kitware.com/cmake/cmake/issues/17205) in the CMake gitlab. It reports the `_autogen` part of this problem and links to a merge request which is expected to address it (currently targeted at the 3.10.0 release). – Craig Scott Aug 29 '17 at 22:39

3 Answers3

7

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.

Community
  • 1
  • 1
Isaac Gómez
  • 156
  • 1
  • 4
  • 1
    Thanks for the suggestions, but that doesn't quite help. AUTOGEN_TARGETS_FOLDER sets the location where the generated files (eg. mocs_compilation.cpp) are stored. CMake still creates the "_autogen" projects regardless. Before 3.9, CMake ran moc as part of a project's prebuild step. Now it seems to create an extra project for every automoc'd project. – Alex Goldberg Aug 24 '17 at 04:59
6

This collects all autogen projects in one folder:

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

enter image description here

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
4

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