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.

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to