[CMake] Avoiding error when using add_subdirectory twice on same path (CMake 2.6.4)

Tyler Roscoe tyler at cryptio.net
Tue Jun 16 17:52:22 EDT 2009


On Tue, Jun 16, 2009 at 07:41:20PM +0200, Floca Ralf Omar wrote:
> using CMake 2.6.4 to build one of our projects an error occurred due to
> the repeated usage of add_subdirectory on the same path.
> 
> In former versions of CMake the repeated usage was accepted and worked
> fine.

I'm in the same boat.

CMake devs, what problem is this change designed to address? I don't see
anything in the release notes at
http://www.cmake.org/files/v2.6/CMakeChangeLog-2.6.4.

> provoking this error. Or is there a policy (planed) that controls this
> special behavior? Looking in the documentation I have not found such a
> policy.

This seems like the kind of behavior change that should have a policy
associated with it. Should I open a bug?

> Any suitable solution is appreciated because right now the dilemma seems
> only to be solvable either by discarding a lot of generalization that
> helps to keep this project easy to maintain and to extend or by sticking
> to CMake 2.6.3, which is not preferable on the long run. Thanks.

I, too, am interested in workarounds.

Not sure if it will work with your specialized system, Floca, but you
might try something like:

if (NOT TARGET ${target_defined_in_subdir})
    add_subdirectory(subdir)
endif ()

Thanks,
tyler


More information about the CMake mailing list