[CMake] Avoiding error when using add_subdirectory twice on same path (CMake 2.6.4)
Tyler Roscoe
tyler at cryptio.net
Tue Jun 16 19:26:57 EDT 2009
On Tue, Jun 16, 2009 at 07:19:52PM -0400, Michael Jackson wrote:
> myApp:
>
> project(myApp)
>
> add_subdirectory(commonLib)
> add_subdirectory(lib1)
> add_subdirectory(lib2)
>
> add_executable(myApp ${files})
> target_link_libraries(myApp lib1 lib2)
>
>
> lib1/lib2:
>
> project(lib1)
>
> add_library(lib1 ${files})
> target_link_libraries(lib1 commonLib)
>
> I am doing exactly this currently in a project and it seems to work
> fine. YMMV.
Right, but this doesn't work in the case where I go down and run CMake
on lib1/CMakeLists.txt instead of running it from myApp/CMakeLists.txt.
I also feel that this is less clear than the example I posted because if
I'm reading lib1's CMakeLists, I will have a wtf moment when I encounter
commonLib since it is not defined in lib1. Instead, I have to "just
know" that commonLib gets pulled in by this myApp thing which happens to
be the thing that causes CMake to process lib1.
Like I said, my thought process here is influenced by our (apparently
goofy?) object-oriented design.
Thanks,
tyler
More information about the CMake
mailing list