[Cmake] Help with first project

Brad King brad.king at kitware.com
Mon, 23 Feb 2004 09:39:08 -0500


Brad King wrote:
> Matt Junkemail wrote:
> 
>> Hi,
>>
>> I'm new at using CMake (and I really like what I see!)
>>  Here is a question I haven't been able to solve.
>>
>> I have a project that I've been working on for a while
>> in Visual C++.  I
>> would like to work on the same project within Linux
>> using gcc and CMake.
>>
>> I have several files within the project's root
>> directory and several sub-directories that contain
>> source files as well.
>>
>> The project is named "Engine" and resides in a
>> directory called Engine, which contains Engine.cpp and
>> Engine.h files.  Within this directory, the two
>> sub-directories are called "Tag" and "SOE", both
>> containing several matching .h and .cpp files.
>>
>> I have in the Engine directory a CMakeLists.txt file
>> that contains the
>> following:
>>
>> PROJECT(Engine)
>>
>> SUBDIRS(Tag SOE)
>> INCLUDE_DIRECTORIES(Tag SOE)
>> SET(Engine_source Engine.cpp)
>>
>> ADD_EXECUTABLE(Engine ${Engine_source})
>>
>> The Tag and SOE directories also contain
>> CMakeLists.txt files.  They add to the Engine_source
>> variable:
>>
>> SET(Engine_source ${Engine_source} Tag.cpp)
>>
>> and:
>>
>> SET(Engine_source ${Engine_source} SOE.cpp)
>>
>> That's the only command in the file.
>>
>> CMake generates a make file, but uponing making it, I
>> receive errors that within Engine.o, I have an
>> undefined reference to Tag.
>>
>> Within the Tag and SOE directories, there are no .o
>> files.  So these files are not being compiled.
>>
>> I have also tried using the AUX_SOURCE_DIRECTORY
>> command
>> within the root CMakeLists.txt file.
>>
>> So basically I need to compile a "main" file in the
>> main directory that uses objects from classes in
>> separate source files (.cpp and .h) that reside in
>> sub-directories.  I don't want to compile and link the
>> sub-directory files as libraries.
>>
>> Can somebody help with the scripts?
> 
> 
> Directories in CMake projects may currently only depend on parent 
> directories, not children.  You can solve your problem by moving the 
> Engine executable source file into a third subdirectory.

Oops, I misread what you want to do.  Please disregard my suggestion and 
take Andy's instead.

-Brad