[CMake] How to deal with silly custom Gnu Make recipes with CMake

kent williams nkwmailinglists at gmail.com
Thu May 15 12:01:02 EDT 2008


I won't name the package because I find this construction really
stupid, but I'm writing CMakeLists.txt files for a package we want to
use and came across this:


%_floof: %.c
    $(CC) $(CFLAGS) -DFLOOF -o $@ -lfloof

So I don't really see how CMake could do something like this.  And
that doesn't even adding C Preprocessor definitions to the command
line, which is hard to do portably.

What I ended up doing is this Unix-only workaround:

PROJECT(EXAMPLE)
add_custom_command(OUTPUT test_floof.c
                          COMMAND echo '\#define FLOOF 1' >
${EXAMPLE_BINARY_DIR}/test_floof.c
                          COMMAND cat ${EXAMPLE_SOURCE_DIR}/test.c >>
${EXAMPLE_BINARY_DIR}/test_floof.c
                          DEPENDS ${EXAMPLE_SOURCE_DIR}/test.c
)

ADD_EXECUTABLE(test_floof ${EXAMPLE_BINARY_DIR}/test_floof.c)
TARGET_LINK_LIBRARIES(test_floof floof)

This seems incredibly rickety.  Is there an elegant way to do this?

And am I missing something in the CMake documentation, but it's
confusing to me how you'd write a custom command that would be general
-- i.e. replace the Gnu Make pattern rules as given above.


More information about the CMake mailing list