[CMake] WPP and Generated Headers

Mike Roberts MRoberts at redbanaus.com
Thu Jan 28 18:12:40 EST 2010


Hi Everyone,

 

I'm currently having a problem with generated headers in a Visual Studio
2005/2008 project generated with CMake. 

 

Visual Studio is regenerating the headers even when nothing has changed.

 

The project requires headers generated by a tool called 'tracewpp',
which is part of the Windows DDK. In short, it generates a header from a
given C/CPP source file and the header is included in the original
source file. I don't know if this is important but it appears to me that
this is a circular dependency.

 

For example, in 'foo.cpp', there will be an include directive that says:

 

#include <foo.cpp.tmh>

 

and I have written CMake code to generate 'foo.cpp.tmh':

 

---8<---------------Wpp.cmake------

 

function ( tracewpp OUTPUT_VAR INI OUTPUT_DIR SOURCE )

 

                # [mlr] list of .tmh files to be generated -> TMH

                get_filename_component ( FILEN ${SOURCE} NAME )

                set ( TMH_FILEN ${FILEN}.tmh )

                set ( TMH ${CMAKE_CURRENT_BINARY_DIR}/${TMH_FILEN} )

                set ( EXTENSIONS ".h.H.c.C.hpp.HPP.cpp.CPP" )

                

                # [mlr] cmake only converts the command name to the
native path format. the

                # path names to be used in arguments must be converted
manually.

                file ( TO_NATIVE_PATH ${SOURCE} NATIVE_SOURCE )

                file ( TO_NATIVE_PATH ${WPP_DIR} NATIVE_WPP_DIR )

                file ( TO_NATIVE_PATH ${INI} NATIVE_INI )

                file ( TO_NATIVE_PATH ${OUTPUT_DIR} NATIVE_OUTPUT_DIR )

                

                # [mlr] note that if -preserveext: occurs after the
source file specification, it has

                # no effect.

                add_custom_command(

                                OUTPUT ${TMH}

                                COMMAND

 
${WPP_DIR}/bin/tracewpp.exe -ext:${EXTENSIONS}
-preserveext:${EXTENSIONS} -cfgdir:${NATIVE_WPP_DIR} -ini:${NATIVE_INI}
-odir:${NATIVE_OUTPUT_DIR} ${NATIVE_SOURCE} 

                                DEPENDS ${SOURCE}

                                )

                # [mlr] export the value of TMH into OUTPUT_VAR.

                set ( ${OUTPUT_VAR} ${TMH} PARENT_SCOPE )

                

endfunction ()

 

# [mlr] TODO: INI should be an optional argument.

function ( wpp OUTPUT_VAR INI OUTPUT_DIR SOURCES )

 

                # [mlr] invoke tracewpp() for each source file, adding
the resulting file to a list 

                # named TMH.

                foreach ( I ${SOURCES} )

                                tracewpp ( J ${INI} ${OUTPUT_DIR} ${I} )

                                list ( APPEND TMH ${J} )

                endforeach ()

                

                source_group( "WPP Files (generated)" REGULAR_EXPRESSION
".+\\.tmh$" )

                

                # [mlr] export the value of TMH into OUTPUT_VAR.

                set ( ${OUTPUT_VAR} ${TMH} PARENT_SCOPE )

                

endfunction ()

 

---8<---------------Wpp.cmake------

 

The list created by wpp() is added to the source file listing that's
passed into add_library() in CMakeList.txt files elsewhere, as described
in the CMake FAQ.

 

The result is that Visual Studio will regenerate 'foo.cpp.tmh'
regardless of whether 'foo.cpp' has been modified or not. This has the
effect of producing a full rebuild since all files in the project are
integrated with 'tracewpp'.

 

Is there something I'm doing wrong? What can I do to prevent full
rebuilds when they're unnecessary?

 

Thanks,

Mike

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100128/8f5f4f85/attachment.htm>


More information about the CMake mailing list