[Cmake] AUX_SOURCE_DIRECTORY bug ?

Brad King brad.king at kitware.com
Fri, 06 Feb 2004 22:34:09 -0500


hilary oliver wrote:
> Hi all,
> 
> I first tried CMake yesterday (cmake-1.8.3 on Red Hat Linux 9); it seems
> a lot saner than gnu autotools, but I think I've found a bug already.  
> 
> Some directories in my source tree exist for cosmetic reasons,
> essentially, so there's no good reason to build them all into separate
> libraries.  From the CMake documentation it looks like 
> AUX_SOURCE_DIRECTORY is used for building the source from multiple dirs
> into a single library.

AUX_SOURCE_DIRECTORY is not meant for this purpose.  What documentation 
led you to believe this?  It is meant for directories containing a whole 
bunch of small source files used for explicit template instantiation so 
that not every instantiation needs to be listed in the CMakeLists.txt file.

> To test it, I tried to convert the CMake "Hello"
> example by putting
> 
> (1) AUX_SOURCE_DIRECTORY(${HELLO_SOURCE_DIR}/Hello SRCS} 
>  ADD_EXECUTABLE(helloDemo demo demo_b ${SRCS})
> 
> in the Demo/CMakeLists.txt, instead of building the Hello sub-dir into a
> library.  First, I can (presumably) write the AUX_... line as above, or
> as, 
> 
> (2) AUX_SOURCE_DIRECTORY(/home/hilary/CMakeExample/Hello SRCS} 
> (3) AUX_SOURCE_DIRECTORY(../Hello SRCS} 
> 
> Of these, (1) and (2) fail (nothing ends up in ${SRCS}) while (3)
> results in ${SRCS} == /home/hilary/CMakeExample2/Hello/hello. 

The command is left over from the very early days of CMake before the 
current design philosophy was adopted and remains for backward 
compatibility.  It works only when specifying a relative path one 
directory below the directory containing the listfile.  In your case, 
the CMakeExample directory would contain a CMakeLists.txt file with the 
command

   AUX_SOURCE_DIRECTORY(Hello SRCS)

However, there are much better ways of compiling source files from 
multiple directories (see below).

> This is odd because ADD_EXECUTABLE (as above) does not need explicit
> file extensions for files in the same directory as CMakeLists.txt
> (Demo/, that is), only for the extra files. I imagine that
> AUX_SOURCE_DIRECTORY must be used pretty frequently, so perhaps I am
> just using it incorrectly, or is this a bug in CMake ????

ADD_EXECUTABLE will guess file extensions for backward compatibility, 
but giving file extensions is preferred.

What you probably want is a CMakeLists.txt file in CMakeExample 
containing code like

ADD_EXECUTABLE(myExe Hello/src1.cxx Hello/src2.cxx
                      World/src3.cxx World/src4.cxx)

-Brad