[CMake] Multiple source directory scenario and cdt generator

Dan Kegel dank at kegel.com
Fri Nov 11 18:27:34 EST 2011


On Fri, Nov 11, 2011 at 11:01 PM, Dan Kegel <dank at kegel.com> wrote:
> 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.

OK, the following shell script is a kludgy prototype of what I think I need,
it seems to work for me.  Set top to the parent directory of all the peers,
src to the directory containing the master CMakeLists.txt, and
run this after running cmake.   (Presumably inside cdt there's some
more artful way of detecting CMakeLists.txt instances that are outside
the normal tree, and which need this special treatment.)

# Generate null projects for each source directory by hand
# rather than asking the cdt generator to do it, since
# it can't handle more than one
projnames=`grep '^[^#]*add_subdirectory(\.\.' $SRC/CMakeLists.txt |
sed 's,.*/,,;s, .*,,' | sort -u`
for dir in $projnames
do
    sed "s/PROJNAME/_$dir/" < $SRC/skeleton.project > ../$dir/.project
done

# And now link those directories to the binary project
# so changes in them cause Eclipse to know the binary project
# needs rebuilding.
# FIXME: this needs to be inside the cdt generator, else
# the links will be lost when cmake regenerates itself on
# CMakeLists.txt changes
sed '/<\/linkedResources>/,$d' < .project > .newproject
for dir in $projnames
do
    cat >> .newproject <<_EOF_
                <link>
                        <name>[_$dir]</name>
                        <type>2</type>
                        <location>$top/$dir</location>
                </link>
_EOF_
done
sed '1,/<\/link>/d' < .project >> .newproject
mv .project .oldproject
mv .newproject .project


More information about the CMake mailing list