Hi,<div><br></div><div>If this has been answered somewhere already in the WIKI or something, please just link me up; it seems like a simple question, but I can&#39;t figure it out.</div><div><br></div><div>So, basically I have my code split into a series of sub-directories:</div>
<div><br></div><div>project/</div><div>project/utils/</div><div>project/common/</div><div>project/desktop/</div><div>etc.</div><div><br></div><div>Each sub directory currently has it&#39;s own CMakeLists.txt, as follows:</div>
<div><div><br></div><div>file(GLOB SOURCE *.c)</div><div>add_library (shared ${SOURCE})</div></div><div><br></div><div>The parent CMakeLists.txt file define these as dependencies:</div><div><br></div><div><div># Shared code</div>
<div>include_directories(&quot;${PROJECT_SOURCE_DIR}/shared&quot;)</div><div>add_subdirectory(shared)</div><div>set (EXTRA_LIBS ${EXTRA_LIBS} shared)</div><div><br></div><div># Utility libraries</div><div>include_directories(&quot;${PROJECT_SOURCE_DIR}/utils&quot;)</div>
<div>add_subdirectory(utils)</div><div>set (EXTRA_LIBS ${EXTRA_LIBS} utils)</div></div><div><br></div><div>...</div><div><br></div><div><div># Source files~</div><div>file(GLOB sources src/*.c)</div><div>add_library (project ${sources})</div>
<div>target_link_libraries (project ${EXTRA_LIBS})</div></div><div><br></div><div>This builds fine. However, it generates a library.a file for each directory, eg.</div><div><br></div><div><div>per-ms006:build douglasl$ du -a |grep &quot;\.a&quot;</div>
<div>./desktop/libdesktop.a</div><div>./libcommon.a</div><div>./shared/libshared.a</div><div>./utils/libutils.a</div></div><div><br></div><div>The problem is that if I want to depend on this with an external project, I can do so via this:</div>
<div><br></div><div><div># Add lib</div><div>include_directories(&quot;/path/to/project/include/&quot;)</div><div>link_directories(&quot;/path/to/project/build/&quot;)</div><div>set(EXTRA_LIBS ${EXTRA_LIBS} project)</div>
</div><div><br></div><div>...but....... obviously this does not link any of the other sub libraries like -lutils -lcommon -ldesktop, so my build fails with a pile of undefined symbol errors. </div><div><br></div><div>So, what&#39;s the way to solve this?</div>
<div><br></div><div>Can I either:</div><div><br></div><div>1) Somehow depend on an external project directory with some kind of add_subdirectory() directive?</div><div><br></div><div>2) Somehow force cmake to combine all the symbols into a single static library for the project, rather than several individual ones?</div>
<div><br></div><div>(The only suggestions I&#39;ve seen so far are (2), where you define a single CMakeLists,txt and list _all_ source files in all directories in it. This is a silly solution, or (2) where you manually uncompress the .a files and recombine all the .o files into a single .a file. This is also just ridiculous. Surely this is a problem that comes up a lot...?)</div>
<div><br></div><div>Cheers,</div><div>Doug.</div><div><br></div><div><br></div>