[CMake] Multiple source directories.
Stefán Freyr Stefánsson
stefan at ru.is
Thu Oct 23 20:22:25 EDT 2008
Hello.
I have a project that has roughly the following structure:
root/dir/
+-- common/
| +-- include/ #.h files
| | +-- Config.h
| +-- src/ #.cpp files
| | +-- Config.cpp
| +-- CMakeLists.txt
|
+-- moduleA/
| +-- include/ #.h files
| +-- src/ #.cpp files
| | +-- app.cpp
| +-- CMakeLists.txt
|
+-- #potentially more modules
|
+-- CMakeLists.txt
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.
app.cpp includes Config.h.
root/dir/CMakeLists.txt only includes all subdirectories:
ADD_SUBDIRECTORIES( common )
ADD_SUBDIRECTORIES( moduleA )
root/dir/common/CMakeLists.txt only has:
PROJECT( COMMON )
INCLUDE_DIRECTORIES (
include/
)
root/dir/moduleA/CMakeLists.txt has:
PROJECT( MODULEA )
INCLUDE_DIRECTORIES (
include/
${COMMON_SOURCE_DIR}/include
)
ADD_EXECUTABLE( app src/app.cpp )
When app.cpp is compiled I get an error complaining that there is an "undefined reference to Config::Config()".
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?
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?
I hope I've made myself understood and I apologize for the length of this email. Any help would be appreciated.
Kind regards, Stefan Freyr.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20081024/9c43dd40/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 481 bytes
Desc: This is a digitally signed message part.
URL: <http://www.cmake.org/pipermail/cmake/attachments/20081024/9c43dd40/attachment.pgp>
More information about the CMake
mailing list