[CMake] Multiple source directory scenario and cdt generator
Dan Kegel
dank at kegel.com
Fri Nov 11 18:01:30 EST 2011
In http://www.cmake.org/pipermail/cmake/2011-November/047250.html
I wrote
"I can't reorganize the source tree on the developers,
so I'm making do by putting the enclosing CMakeLists.txt next to all
the projects:
toplevel/trunk/CMakeLists.txt
which is checked out to
toplevel/CMakeLists.txt
It does
add_subdirectory(../libfoo libfoo)
add_subdirectory(../libbar libbar)
add_subdirectory(../baz baz)
This has the possible advantage that one can have multiple
"top levels" (say, one for server code, and one for client).
I don't know how many shops suffer from this svn layout, but I'll probably
add an example covering it anyway for completeness once I'm sure
it doesn't explode in practice."
Right, well, I found out where it explodes in practice. Here's an example:
http://code.google.com/p/winezeug/source/browse/trunk/cmake_examples/ex7/
The problem comes when using the cdt generator. We can't use
-DECLIPSE_CDT4_GENERATE_SOURCE_PROJECT=TRUE
since there are more than one source project, but the
source project that generates is really trivial, so I generate
one for each source directory myself with a bit of shell:
for dir in demo libsrc
do
sed "s/PROJNAME/_$dir/" < ../skeleton.project > ../$dir/.project
done
before or after running cmake.
It all works great, the source projects all show up, the project builds...
BUT when you edit a source file and tell eclipse to rebuild, it just
sits there. It doesn't know that the source projects are related to
the build project.
It looks like adding a link does the trick:
--- .project.old 2011-11-11 22:51:56.797674441 +0000
+++ .project 2011-11-11 22:52:25.380913484 +0000
@@ -113,5 +113,11 @@
<type>2</type>
<location>/home/dank/winezeug/cmake_examples/ex7/demo</location>
</link>
+ <link>
+ <name>[Source directory 2]</name>
+ <type>2</type>
+ <location>/home/dank/winezeug/cmake_examples/ex7/libsrc</location>
+ </link>
+
</linkedResources>
</projectDescription>
After I add those lines to the .project, saved changes in libsrc do seem
to cause a rebuild the next time you click "build project".
So, I guess to support this style of project, the cdt generator
should call cmExtraEclipseCDT4Generator::AppendLinkedResource()
once for each call in my outer CMakeLists.txt like
add_subdirectory(../libsrc libsrc).
I have no idea how to make that happen inside the cdt generator. I could kludge
it in the shell script that runs cmake, but then it would break whenever
the project was updated and cmake rebuilt the project automatically.
Was http://public.kitware.com/Bug/view.php?id=9978 /
https://github.com/rpavlik/CMake/commit/10aece0d8199409fbb695478eab2c60545fcf310
related at all?
- Dan
More information about the CMake
mailing list