cpkg2c improvements.
[apps/madmutt.git] / cmake / Cpkg2c.cmake
1 macro (MADMUTT_SOURCES _result _gen)
2     foreach (_current_FILE ${ARGN})
3         get_filename_component(_ext      ${_current_FILE} EXT)
4         get_filename_component(_abs      ${_current_FILE} ABSOLUTE)
5         get_filename_component(_basename ${_current_FILE} NAME_WE)
6         get_filename_component(_basename ${_current_FILE} NAME_WE)
7         set(_li ${CMAKE_CURRENT_SOURCE_DIR}/${_basename}.li)
8         set(_h  ${CMAKE_CURRENT_SOURCE_DIR}/${_basename}.h)
9         set(_c  ${CMAKE_CURRENT_SOURCE_DIR}/${_basename}.c)
10         if (_ext STREQUAL ".cpkg")
11             add_custom_command(
12                 OUTPUT ${_li}
13                 MAIN_DEPENDENCY ${_abs}
14                 COMMAND ${madmutt_SOURCE_DIR}/tools/cpkg2c -h ${_abs} -o ${_li}
15                 COMMENT "Generating ${_li} from ${_abs}"
16             )
17             add_custom_command(
18                 OUTPUT ${_c}
19                 MAIN_DEPENDENCY ${_abs}
20                 COMMAND ${madmutt_SOURCE_DIR}/tools/cpkg2c -c ${_abs} -o ${_c}
21                 COMMENT "Generating ${_c} from ${_abs}"
22             )
23             list(APPEND ${_result} ${_li} ${_c})
24             list(APPEND ${_gen} ${_li} ${_c})
25         else (_ext STREQUAL ".cpkg")
26             if (_ext STREQUAL ".gperf")
27                 add_custom_command(
28                     OUTPUT ${_h}
29                     MAIN_DEPENDENCY ${_abs}
30                     COMMAND sh ${_abs} ${_h} || \(${RM} ${_h}; exit 1\)
31                     COMMENT "Generating ${_h} from ${_abs}"
32                 )
33                 add_custom_command(
34                     OUTPUT ${_c}
35                     MAIN_DEPENDENCY ${_abs}
36                     COMMAND sh ${_abs} ${_c} || \(${RM} ${_c}; exit 1\)
37                     COMMENT "Generating ${_c} from ${_abs}"
38                 )
39                 list(APPEND ${_result} ${_h} ${_c})
40                 list(APPEND ${_gen} ${_h} ${_c})
41             else (_ext STREQUAL ".gperf")
42                 list(APPEND ${_result} ${_current_FILE})
43             endif (_ext STREQUAL ".gperf")
44         endif (_ext STREQUAL ".cpkg")
45     endforeach(_current_FILE)
46 endmacro (MADMUTT_SOURCES)
47