<br><font size=2 face="sans-serif">I have a small project with several
different parts that I would like to build with CMake, but I'm having some
trouble pulling it all together.</font>
<br>
<br><font size=2 face="sans-serif"> For example purposes, there's
an overall project with three executables that use two static libraries.
The executables and static libraries are produced as part of the build.
The directory structure looks like this:</font>
<br>
<br><font size=2 face="sans-serif"> /</font>
<br><font size=2 face="sans-serif"> projects/</font>
<br><font size=2 face="sans-serif"> 00-0000/</font>
<br><font size=2 face="sans-serif">
CMakeLists.txt</font>
<br><font size=2 face="sans-serif"> products/</font>
<br><font size=2 face="sans-serif"> executable_a/</font>
<br><font size=2 face="sans-serif">
src/</font>
<br><font size=2 face="sans-serif">
include/</font>
<br><font size=2 face="sans-serif"> CMakeLists.txt</font>
<br><font size=2 face="sans-serif"> executable_b/</font>
<br><font size=2 face="sans-serif">
src/</font>
<br><font size=2 face="sans-serif">
include/</font>
<br><font size=2 face="sans-serif"> CMakeLists.txt</font>
<br><font size=2 face="sans-serif"> executable_c/</font>
<br><font size=2 face="sans-serif">
src/</font>
<br><font size=2 face="sans-serif">
include/</font>
<br><font size=2 face="sans-serif"> CMakeLists.txt</font>
<br><font size=2 face="sans-serif"> components/</font>
<br><font size=2 face="sans-serif"> a/</font>
<br><font size=2 face="sans-serif">
src/</font>
<br><font size=2 face="sans-serif">
include/</font>
<br><font size=2 face="sans-serif">
CMakeLists.txt</font>
<br><font size=2 face="sans-serif"> b/</font>
<br><font size=2 face="sans-serif">
src/</font>
<br><font size=2 face="sans-serif">
include/</font>
<br><font size=2 face="sans-serif">
CMakeLists.txt</font>
<br>
<br><font size=2 face="sans-serif">I would like /projects/00-0000/CMakeLists.txt
to be the top level CMakeLists.txt file and to contain:</font>
<br>
<br><font size=2 face="sans-serif"> PROJECT(00-0000)</font>
<br>
<br><font size=2 face="sans-serif"> ADD_SUBDIRECTORY(../../products/executable_a
executable_a)</font>
<br><font size=2 face="sans-serif"> ADD_SUBDIRECTORY(../../products/executable_b
executable_b)</font>
<br><font size=2 face="sans-serif"> ADD_SUBDIRECTORY(../../products/executable_c
executable_c)</font>
<br>
<br><font size=2 face="sans-serif">And /products/executable_a/CMakeLists.txt
to contain:</font>
<br>
<br><font size=2 face="sans-serif"> PROJECT(executable_a)</font>
<br>
<br><font size=2 face="sans-serif"> ADD_SUBDIRECTORY(../../components/a
a)</font>
<br>
<br><font size=2 face="sans-serif">And /products/executable_b/CMakeLists.txt
to contain:</font>
<br>
<br><font size=2 face="sans-serif"> PROJECT(executable_b)</font>
<br>
<br><font size=2 face="sans-serif"> ADD_SUBDIRECTORY(../../components/b
b)</font>
<br>
<br><font size=2 face="sans-serif">And /products/executable_c/CMakeLists.txt
to contain:</font>
<br>
<br><font size=2 face="sans-serif"> PROJECT(executable_c)</font>
<br>
<br><font size=2 face="sans-serif"> ADD_SUBDIRECTORY(../../components/a
a)</font>
<br><font size=2 face="sans-serif"> ADD_SUBDIRECTORY(../../components/b
b)</font>
<br>
<br><font size=2 face="sans-serif">So I have each executable using ADD_SUBDIRECTORY
to get the components it needs. The problem obviously is that the CMakeLists.txt
for components a and b are included twice, producing duplicate targets
that CMake doesn't like. I was thinking that this was similar to header
files in C/C++, and in that world every header files uses an include guard
to prevent duplication. So is there a way in CMake to implement include
guards, or rather ADD_SUBDIRECTORY guards?</font>
<br>
<br><font size=2 face="sans-serif">Or, am I headed down the wrong path
entirely?</font>
<br>
<br><font size=2 face="sans-serif">---------------------------------------------------------<br>
Aaron Wright</font>