[CMake] ADD_CUSTOM_COMMAND and how to include generated files from
other directories
blinkeye
gentoo at blinkeye.ch
Sun Feb 17 10:36:34 EST 2008
Hi guys
I'm in the process of replacing Makefiles from two large projects with
CMake files. So far it's working great, but now I hit a wall:
I need to generate .cpp and .h files from input files (analogue to the
.ui files of Qt).
Bill Hofmann wrote the following QT4_WRAP_UI macro:
> MACRO (QT4_WRAP_UI outfiles )
> FOREACH (it ${ARGN})
> GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
> GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE)
> SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/ui_${outfile}.h)
> ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
> COMMAND ${QT_UIC_EXECUTABLE}
> ARGS -o ${outfile} ${infile}
> MAIN_DEPENDENCY ${infile})
> SET(${outfiles} ${${outfiles}} ${outfile})
> ENDFOREACH (it)
> ENDMACRO (QT4_WRAP_UI)
I'm using just a slightly adapted form of this macro. The problem is
that our project includes the generated header files from different
subdirectories and I can't figure out on how to include them.
Imagine the following project layout:
src
-sub1
--CMakeLists.txt
--sub1.cpp
--sub1.ui
-sub2
--CMakeLists.txt
--sub2.cpp
${QT_UIC_EXECUTABLE} will read sub1.ui and generate a file like
"ui_sub1.h". sub1.cpp and sub2.cpp both include the file "ui_sub1.h".
While above macro works for sub1 it doesn't work for sub2:
> make
> [ 20%] Generating ui_sub1.h
> [ 40%] Generating moc_sub1.cxx
> Scanning dependencies of target sub1
> [ 60%] Building CXX object src/sub1/CMakeFiles/sub1.dir/sub1.o
> [ 80%] Building CXX object src/sub1/CMakeFiles/sub1.dir/moc_sub1.o
> Linking CXX executable sub1
> [ 80%] Built target sub1
> Scanning dependencies of target sub2
> [100%] Building CXX object src/sub2/CMakeFiles/sub2.dir/sub2.o
> /home/cerberos/Desktop/mutacts/dan/src/sub2/sub2.cpp:4:21: error: ui_sub1.h: No such file or directory
> make[2]: *** [src/sub2/CMakeFiles/sub2.dir/sub2.o] Error 1
> make[1]: *** [src/sub2/CMakeFiles/sub2.dir/all] Error 2
> make: *** [all] Error 2
I tried for hours but I can't figure out a proper (or at least working)
way on how to achieve that. Changing above macro to include the path of
the generated header files doesn't seem to make a difference:
MACRO (QT4_WRAP_UI_CUSTOM outfiles )
FOREACH (it ${ARGN})
GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE)
SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/ui_${outfile}.h)
include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
COMMAND ${QT_UIC_EXECUTABLE}
ARGS -o ${outfile} ${infile}
MAIN_DEPENDENCY ${infile})
SET(${outfiles} ${${outfiles}} ${outfile})
ENDFOREACH (it)
ENDMACRO (QT4_WRAP_UI_CUSTOM)
For some reason the included directory is lost in sub2 again (btw: is
there a way to log the currently included directories besides analysing
the make output?).
I've attached above mentioned mini project.
Thanks for any help.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: demo.zip
Type: application/octet-stream
Size: 3247 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20080217/f910097f/demo-0001.obj
More information about the CMake
mailing list