Am Mittwoch, 26. Januar 2011 schrieb kfj: > Hi all! > > I'm still struggling with cmake for hsi/hpi, and I just can't get my > head round it's strange ways, and what online documentation there is I > don't find helpful either. So maybe someone can help me with this > simple problem: > > I have a C++ header file zz.h in my source directory > > I want this preprocessed by the C preprocessor into a file zz.i in the > target directory > > This is a simple operation, and cmake even generates i-files as > default targets in C++ projects. So if I have a simple CMakeLists.txt > going like > > add_executable(xx xx.cpp) > > (really only this one line!) and xx.cpp is also very simple: > > #define mac "MACRO" > int main ( int argc , char * argv[] ) > { > char * str = mac ; > } > > if i now run > > cmake . > make xx.i > > I get this output: > > Preprocessing CXX source to CMakeFiles/xx.dir/xx.i > > lo and behold, CMakeFiles/xx.dir/xx.i is the C-preprocessed file. I > didn't need to specify anything in the CMakeLists.txt, cmake knows > perfectly well how to invoke the C/C++ preprocessor and make an i-file > from a .cpp file. My question is: how can I get it to uses this > capability on my source file zz.h to get zz.i in the target directory? > So far the answer was to run a custom command, with differentiation > between MSVC and gcc, probably use of a cmake command file - T. Modes > has managed to coerce cmake into doing what's needed for hsi/hpi with > a good dozen lines of code, but I have the feeling this is not at all > needed - and the current code is so obscure that I'm not at all happy > with it, because it's really such a standard task that in a classic > makefile it'd be there by default, like .i .h. But I can't figure it > out. Help!
Sorry, there is no such rule as in makefile. You have to add_custom_commad() for each .h file. If you have a list of files, then you could achieve the effect of ".h.i" rule like this: file(GLOB hlist ${CMAKE_CURRENT_SOURCE_DIR}*.h) foreach(hfile ${hlist}) get_filename_component(hbase ${hfile} NAME_WE) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${hbase}.i" COMMAND ${CMAKE_CXX_COMPILER} ARGS -E ${hfile} > "${CMAKE_CURRENT_BINARY_DIR}/${hbase}.i" DEPENDS ${hfile} ) SET_SOURCE_FILES_PROPERTIES("${CMAKE_CURRENT_BINARY_DIR}/${hbase}.i" GENERATED) endforeach() But, why not rename xx.h into xx.cpp? > I'd also appreciate a link to documentation that explains the concepts > behind cmake. I get the feeling that the online documentation for > cmake is deliberately sketchy to promote the sales of the book which > is featured on the main page. It's either making hello-world-type > projects with three source files and a bit of configuration or > extremely terse 'Documentation' which has no conceptual explanations > or examples. You know what cmake syntax reminds me of? Lisp. and that > has always been good for giving me a headache. There's a down side to > a simple syntax: it's all in semantics. I don't have that either. > Kay > Kornel
signature.asc
Description: This is a digitally signed message part.