Thanks Julien :)
[apps/madmutt.git] / cmake / Modules / 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} ${_c}
13                 MAIN_DEPENDENCY ${_abs}
14                 COMMAND ${madmutt_SOURCE_DIR}/tools/cpkg2c ${_abs} ${_li} ${_c}
15                 COMMENT "Preprocessing ${_abs}"
16             )
17             list(APPEND ${_result} ${_li} ${_c})
18             list(APPEND ${_gen} ${_li} ${_c})
19         else (_ext STREQUAL ".cpkg")
20             if (_ext STREQUAL ".gperf")
21                 add_custom_command(
22                     OUTPUT ${_h}
23                     MAIN_DEPENDENCY ${_abs}
24                     COMMAND sh ${_abs} ${_h} || \(${RM} ${_h}; exit 1\)
25                     COMMENT "Generating ${_h} from ${_abs}"
26                 )
27                 add_custom_command(
28                     OUTPUT ${_c}
29                     MAIN_DEPENDENCY ${_abs}
30                     COMMAND sh ${_abs} ${_c} || \(${RM} ${_c}; exit 1\)
31                     COMMENT "Generating ${_c} from ${_abs}"
32                 )
33                 list(APPEND ${_result} ${_h} ${_c})
34                 list(APPEND ${_gen} ${_h} ${_c})
35             else (_ext STREQUAL ".gperf")
36                 list(APPEND ${_result} ${_current_FILE})
37             endif (_ext STREQUAL ".gperf")
38         endif (_ext STREQUAL ".cpkg")
39     endforeach(_current_FILE)
40 endmacro (MADMUTT_SOURCES)
41