<html><head><meta name="qrichtext" content="1" /></head><body style="font-size:9pt;font-family:Sans Serif">
<p><span style="font-family:FreeMono">Hello.</span></p>
<p></p>
<p><span style="font-family:FreeMono">I have a project that has roughly the following structure:</span></p>
<p></p>
<p><span style="font-family:FreeMono">root/dir/</span></p>
<p><span style="font-family:FreeMono">  +-- common/</span></p>
<p><span style="font-family:FreeMono">  |    +-- include/   #.h files</span></p>
<p><span style="font-family:FreeMono">  |    |    +-- Config.h</span></p>
<p><span style="font-family:FreeMono">  |    +-- src/       #.cpp files</span></p>
<p><span style="font-family:FreeMono">  |    |    +-- Config.cpp</span></p>
<p><span style="font-family:FreeMono">  |    +-- CMakeLists.txt</span></p>
<p><span style="font-family:FreeMono">  |</span></p>
<p><span style="font-family:FreeMono">  +-- moduleA/</span></p>
<p><span style="font-family:FreeMono">  |    +-- include/   #.h files</span></p>
<p><span style="font-family:FreeMono">  |    +-- src/       #.cpp files</span></p>
<p><span style="font-family:FreeMono">  |    |    +-- app.cpp</span></p>
<p><span style="font-family:FreeMono">  |    +-- CMakeLists.txt</span></p>
<p><span style="font-family:FreeMono">  |</span></p>
<p><span style="font-family:FreeMono">  +-- #potentially more modules</span></p>
<p><span style="font-family:FreeMono">  |</span></p>
<p><span style="font-family:FreeMono">  +-- CMakeLists.txt</span></p>
<p></p>
<p><span style="font-family:FreeMono">So I have a class that is defined in root/dir/common/include/Config.h and implemented in root/dir/common/src/Config.cpp and then I have a program in /root/dir/moduleA/src/app.cpp.</span></p>
<p></p>
<p><span style="font-family:FreeMono">app.cpp includes Config.h.</span></p>
<p></p>
<p><span style="font-family:FreeMono">root/dir/CMakeLists.txt only includes all subdirectories:</span></p>
<p><span style="font-family:FreeMono">ADD_SUBDIRECTORIES( common )</span></p>
<p><span style="font-family:FreeMono">ADD_SUBDIRECTORIES( moduleA )</span></p>
<p></p>
<p><span style="font-family:FreeMono">root/dir/common/CMakeLists.txt only has:</span></p>
<p><span style="font-family:FreeMono">PROJECT( COMMON )</span></p>
<p><span style="font-family:FreeMono">INCLUDE_DIRECTORIES (</span></p>
<p><span style="font-family:FreeMono">    include/</span></p>
<p><span style="font-family:FreeMono">)</span></p>
<p></p>
<p><span style="font-family:FreeMono">root/dir/moduleA/CMakeLists.txt has:</span></p>
<p><span style="font-family:FreeMono">PROJECT( MODULEA )</span></p>
<p><span style="font-family:FreeMono">INCLUDE_DIRECTORIES (</span></p>
<p><span style="font-family:FreeMono">    include/</span></p>
<p><span style="font-family:FreeMono">    ${COMMON_SOURCE_DIR}/include</span></p>
<p><span style="font-family:FreeMono">)</span></p>
<p><span style="font-family:FreeMono">ADD_EXECUTABLE( app src/app.cpp )</span></p>
<p></p>
<p><span style="font-family:FreeMono">When app.cpp is compiled I get an error complaining that there is an &quot;undefined reference to Config::Config()&quot;.</span></p>
<p></p>
<p><span style="font-family:FreeMono">So (finally) my question is: Since common has no executables, how exactly should I tell CMake that it needs to compile Config.cpp before moduleA compiles its executable for app.cpp to get rid of this error?</span></p>
<p></p>
<p><span style="font-family:FreeMono">Do I need to add something to the common CMakeLists.txt file (which would be the cleanest solution IMHO), and then what exactly is it that I need to add, or should I somehow indicate that this file needs to be compiled in the moduleA CMakeLists.txt (which feels a bit wrong since the idea about the common project is to be referenced by more than one module). I guess I could use ADD_LIBRARY like in the example, but is that the right thing to do? I mean, basically I just want to reference the files from my modules, it's not exactly a library, just some common files. Maybe this is my mistake?</span></p>
<p></p>
<p><span style="font-family:FreeMono">I hope I've made myself understood and I apologize for the length of this email. Any help would be appreciated.</span></p>
<p></p>
<p><span style="font-family:FreeMono">Kind regards, Stefan Freyr.</span></p>
</body></html>