[Cmake] AUX_SOURCE_DIRECTORY bug ?

hilary oliver hilary.oliver at paradise.net.nz
Sat, 07 Feb 2004 15:23:16 +1300


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. 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. 

This appears to be caused by  cmAuxSourceDirectoryCommand.cxx appending
the whole AUX directory string to the "current directory" string.  The
relative path works out ok because "Demo/../Hello/" == "Hello/". So I
removed a few lines from cmAuxSourceDirectoryCommand.cxx:

% cat cmAuxSourceDirectoryCommand.cxx.diff
34,36c34,37
<   std::string tdir = m_Makefile->GetCurrentDirectory();
<   tdir += "/";
<   tdir += templateDirectory;
---
>   //  std::string tdir = m_Makefile->GetCurrentDirectory();
>   //  tdir += "/";
>   //  tdir += templateDirectory;
>   std::string tdir = templateDirectory;

With this patch, (3) doesn't work anymore, but (1) and (2) give the same
result (in this simple case) as 
 
SET(SRCS ${HELLO_SOURCE_DIR}/Hello/hello}

which is presumably what should happen. However, the example program
still does not build! It only works if explicit file extensions are
supplied with the AUX files:

SET(SRCS ${HELLO_SOURCE_DIR}/Hello/hello.cxx)

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 ????

Thanks,
Hilary

-- 
hilary james oliver <hilary.oliver at paradise.net.nz>
Lard Ass Software Corporation