[CMake] add_custom_target: always built during "make" and "make install"
Romain CHANU
romainchanu at gmail.com
Mon Nov 2 21:22:14 EST 2009
Hi,
I have done some experiments and I have found something interesting.
Let's take my old example:
=== root/src/CMakeLists.txt === (build a shared library)
# Compilation
add_library(
${CMAKE_PROJECT_NAME} SHARED
${CMAKE_BINARY_DIR}/xsd/mapping_file.cxx)
# XML mapping source files are generated
set_source_files_properties(
${CMAKE_BINARY_DIR}/xsd/mapping_file.cxx
PROPERTIES GENERATED 1)
# Make sure the source files are generated before the executable builds.
add_dependencies(${CMAKE_PROJECT_NAME} cxx_xml_mapping)
=== root/xsd/CMakeLists.txt === (generates C++ / XML mapping files using
code synthesis XSD)
# Add a custom target to manage dependencies
add_custom_target(cxx_xml_mapping DEPENDS xml_mapping)
add_custom_command(
OUTPUT xml_mapping
COMMAND ${XSD_EXECUTABLE} ARGS ${XSD_ARGS}
${CMAKE_CURRENT_SOURCE_DIR}/*.xsd
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.xsd
COMMENT "Generating C++ / XML mapping files")
Instead of putting "xml_mapping" (i.e a logical name) as the name of the
OUTPUT in the add_custom_command, I put the list of file names generated by
the command, and I put the same list in the add_custom_target. Now it is
working, the compilation is done only once (during "make").
I would expect to be able to define a logical name for the OUTPUT variable.
When you have a huge list of files generated by a particular command, it is
very troublesome to list them all. In another case, I am using XJC compiler
and I got about 80 files generated from a few XML schemas... It will not
make sense to hard-code them in the list of OUTPUT.
Is there any other way to implement such things? If not, I would suggest an
improvement of these two commands to CMake developers. @Bill: any comments
on this matter?
Cheers,
Romain Chanu
2009/11/2 Tyler Roscoe <tyler at cryptio.net>
> On Mon, Nov 02, 2009 at 11:28:08PM +0800, Romain CHANU wrote:
> > 1. If there is a restriction / condition regarding the "out-of-date"
> > behavior, it might be good to update the documentation.
>
> Agreed, but I don't understand the behavior so I can't help with that.
>
> > 3. I am not 100% sure also... Anyone to give us an advice on that
> matter??
>
> Why don't you experiment with an explicit list and see if the behavior
> changes? Science to the rescue!
>
> tyler
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20091103/66ec0693/attachment-0001.htm>
More information about the CMake
mailing list