Closed Zhumos closed 2 years ago
I have found that the cleanest (and possibly final?) workaround is to set SKIP_AUTOMOC on the GenericListModel.cpp file as recommended by the AutoMoc error. While it's also possible to omit the source files from add_library, some IDE/generator combos will then not list them as project source files (which may or may not be desirable).
Adding the code snippet below to the CMake file above causes the build to complete successfully.
set_property(
SOURCE ${ToolkitSrcPath}/Internal/GenericListModel.cpp
PROPERTY SKIP_AUTOMOC ON
)
I have also logged an issue against AutoMoc which can be found here
@Zhumos I appreciate all the work you've put into this investigation!
Hopefully the behaviour of CMake + moc
will be fixed in the future. Since we have no timescale for when this will happen, I'll look into the options we can do on our end for anyone else that hits this problem.
Options are:
#ifndef Q_MOC_RUN
in a block around the GenericListModel comment.Q_OBJECT
Q_OBJECT
in such a way that the moc
bug does not trigger.Overall, I favour the second option, removing Q_OBJECT
, which does not detract from the example code itself.
As you currently have a good workaround, I will put in a fix into our dev branch for 100.14.
@anmacdonald,
Thank you for both the other workaround options and the fix, didn't know about the Q_MOC_RUN macro!
The ball is definitely in CMake's court for properly fixing it but it would (I assume) require implementation of handling comments in their parser to fix an edge case so I doubt it will move too quickly...
Out of curiosity (and if you don't mind answering), is there a particular reason why the qdoc comments are in the implementation file rather than the header? I've only ever seen documentation comments like these in header files and I'm quite interested to know what benefits there are doing it the other way around.
@Zhumos It's a good question, but not one I have a good answer for on the design level. Most C++ projects will be written with Doxygen in mind, which favors documenting in the header. We use Qt's QDoc to build our API docs, which favors source-file documentation.
Next, QDoc uses the values of the headerdirs variable and/or the headers variable to find and parse all the header files for your project. QDoc does not scan header files for QDoc comments. It parses the header files to build a master tree of all the items that should be documented, in other words, the items that QDoc should find QDoc comments for.
After parsing all the header files and building the master tree of items to be documented, QDoc uses the value of the sourcedirs variable and/or the value of the sources variable to find and parse all the .cpp and .qdoc files for your project. These are the files QDoc scans for QDoc comments.
While this toolkit doesn't include CMake support yet, this might save someone a lot of frustration in the future.
The Problem
In the following code snippet, Q_OBJECT is embedded in the comment block (line 46). This unfortunately confuses AutoMoc into thinking it's a real class and a valid macro reference (I'm guessing the AutoMoc parser doesn't keep track of comment blocks).
Minor aside: typo on line 49, should be CONSTANT
https://github.com/Esri/arcgis-runtime-toolkit-qt/blob/5c6f5abc3ad2f95e32dc9239782a4c2f7e23eecd/uitools/cpp/Esri/ArcGISRuntime/Toolkit/Internal/GenericListModel.cpp#L26-L52
Output error from build:
Workaround
Removing Q_OBJECT, or otherwise invalidating the line inside the comment allows AutoMoc to complete successfully.
Environment
OS: Windows 11
Versions:
Below is the CMakeLists.txt file I'm using. I've added this repo as a submodule to my project and the CMake sits one directory up from it. My project uses add_subdirectory to pull it in. To find the runtime itself, I use the cmake file provided in the ideintegration directory.