CMake is nice. Or not?
I am playing with CMake. Specifically, I am trying to replace the simplistic handmade Makefiles for my RA-Plugins project.
The parts about detecting libraries and conditionally compiling plugins based on what you have were surprisingly easy!
Until I ran into ... man pages.
Here is a Makefile that would build all the manpages for the plugins:
MANPAGES=plugins-ra.8 authchecks.8 rcptchecks.8 man: \$(MANPAGES) %.8: %.man.txt txt2man -t \${basename $< .man.txt} < $< > $@
As you can see... trivial. All I need to do in order to add a man page is add whatever.8 to the list, and it will be created from whatever.man.txt.
But... how does one do that using CMake?
I started thinking of using a FILE (GLOB *.man.txt) and then a FOREACH over that, and then... then what? Really, I am stumped. I am a newbie, though, and getting the big, difficult stuff done is enough to switch. I should generate these before distribution anyway.
So, I wrote a wee Makefile.manpages and added this for CMAKE:
ADD_CUSTOM_TARGET ( manpages make -f Makefile.manpages )
But I am curious about finding the cmakeish way.
Currently you can do it e.g. this way:
# add a target, but with no rules:
add_custom_target(man)
# use foreach to generate the rules using the 2nd type of
# add_custom_command(), so that each of these commands
# is executed when the target "man" is built:
foreach(file a.txt b.txt c.txt)
add_custom_command(TARGET man POST_BUILD
COMMAND cp ${file} ${file}.man )
endforeach(file)
(you will have noticed that the cp is not really appropriate to generate man pages, but I guess you get the idea)
It would be easier if it would be possible to use cmake code as command in add_custom_command() and add_custom_target(). I think I'll file a feature request for cmake.
Then you could do something like:
add_custom_target(man
SCRIPT "
FOREACH(file a.txt b.txt c.txt)
EXEC_PROGRAM(cp ${file} ${file}.man)
ENDFOREACH(file a.txt b.txt c.txt)
" )
Alex
P.S. The better way to get a response than blogging is to post either to
1) cmake@cmake.org
2) kde-buildsystem@kde.org
3) post a bug at b.k.o. for product "Buildsystem", component "KDE(cmake)"
Actually, that doesn't work. txt2man works by redirecting stdin and stdout. Of course I could write a wrapper, but in that case I could just write a shell script to generate the things ;-)
As about how it's a better idea to post to those places:
It's not at all KDE related, so 2 and 3 are out.
And I don't want to subscribe to mailing lists anymore, anyway, much less for a product I am just playing with.
So, I just post in my little page, and see if someone can help me. If noone can, I don't bother anyone.
Can you please post a plain example command ?
txt2man -t rcptchecks < rcptchecks.man.txt > rcptchecks.8
No problem there, the redirecting does work in add_custom_command(). You also need get_filename_component() to get the basename of the files.
Alex
Just in case someone googles this someday:
ADD_CUSTOM_TARGET ( manpages )
FILE (GLOB MANSOURCES *.man.txt)
FOREACH ( MANSRC ${MANSOURCES} )
GET_FILENAME_COMPONENT ( MANDST ${MANSRC} NAME_WE )
ADD_CUSTOM_COMMAND ( TARGET manpages POST_BUILD
COMMAND LANG=C txt2man -t ${MANDST} < ${MANSRC} > ${MANDST}.8 )
ENDFOREACH ( MANSRC )