[CMake] Include Guard to Stop Duplicate Targets?

Aaron_Wright at selinc.com Aaron_Wright at selinc.com
Fri Oct 23 18:09:25 EDT 2009


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.

 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:

   /
      projects/
         00-0000/
            CMakeLists.txt
      products/
         executable_a/
            src/
            include/
           CMakeLists.txt
         executable_b/
            src/
            include/
           CMakeLists.txt
         executable_c/
            src/
            include/
           CMakeLists.txt
      components/
         a/
            src/
            include/
            CMakeLists.txt
         b/
            src/
            include/
            CMakeLists.txt

I would like /projects/00-0000/CMakeLists.txt to be the top level 
CMakeLists.txt file and to contain:

   PROJECT(00-0000)

   ADD_SUBDIRECTORY(../../products/executable_a executable_a)
   ADD_SUBDIRECTORY(../../products/executable_b executable_b)
   ADD_SUBDIRECTORY(../../products/executable_c executable_c)

And /products/executable_a/CMakeLists.txt to contain:

   PROJECT(executable_a)

   ADD_SUBDIRECTORY(../../components/a a)

And /products/executable_b/CMakeLists.txt to contain:

   PROJECT(executable_b)

   ADD_SUBDIRECTORY(../../components/b b)

And /products/executable_c/CMakeLists.txt to contain:

   PROJECT(executable_c)

   ADD_SUBDIRECTORY(../../components/a a)
   ADD_SUBDIRECTORY(../../components/b b)

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?

Or, am I headed down the wrong path entirely?

---------------------------------------------------------
Aaron Wright
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20091023/1c4eda5d/attachment.htm>


More information about the CMake mailing list