diff options
-rw-r--r-- | ErlangTarget.cmake | 72 |
1 files changed, 40 insertions, 32 deletions
diff --git a/ErlangTarget.cmake b/ErlangTarget.cmake index de5fd92..5562d86 100644 --- a/ErlangTarget.cmake +++ b/ErlangTarget.cmake @@ -1,37 +1,45 @@ find_package(Erlang REQUIRED) macro(erl_target name) - parse_arguments(ARGS "HEADERS;OPTIONS" "" ${ARGN}) - - set(headers "") - set(out_files "") - - foreach(header ${ARGS_HEADERS}) - list(APPEND headers "${CMAKE_CURRENT_SOURCE_DIR}/${header}") - endforeach(header ${ARGS_HEADERS}) - - foreach(src ${ARGS_DEFAULT_ARGS}) - set(in_file "${CMAKE_CURRENT_SOURCE_DIR}/${src}") - string(REPLACE ".erl" ".beam" src ${src}) - set(out_file "${CMAKE_CURRENT_BINARY_DIR}/${src}") - - add_custom_command( + parse_arguments(ARGS "HEADERS;OPTIONS" "" ${ARGN}) + + set(headers "") + set(out_files "") + + foreach(header ${ARGS_HEADERS}) + list(APPEND headers "${CMAKE_CURRENT_SOURCE_DIR}/${header}") + endforeach(header ${ARGS_HEADERS}) + + set(before "") + + foreach(src ${ARGS_DEFAULT_ARGS}) + if(src STREQUAL "BEFORE") + set(before ${out_files}) + else(src STREQUAL "BEFORE") + set(in_file "${CMAKE_CURRENT_SOURCE_DIR}/${src}") + string(REPLACE ".erl" ".beam" src ${src}) + set(out_file "${CMAKE_CURRENT_BINARY_DIR}/${src}") + + add_custom_command( OUTPUT - ${out_file} - COMMAND - ${ERLC_EXECUTABLE} - "-o" ${CMAKE_CURRENT_BINARY_DIR} - ${ARGS_OPTIONS} - ${in_file} - DEPENDS - ${in_file} - ${headers} - ) - - list(APPEND out_files "${CMAKE_CURRENT_BINARY_DIR}/${src}") - endforeach(src ${ARGS_DEFAULT_ARGS}) - - add_custom_target( - ${name} ALL DEPENDS ${out_files} - ) + ${out_file} + COMMAND + ${ERLC_EXECUTABLE} + "-o" ${CMAKE_CURRENT_BINARY_DIR} + "-pz" ${CMAKE_CURRENT_BINARY_DIR} + ${ARGS_OPTIONS} + ${in_file} + DEPENDS + ${in_file} + ${headers} + ${before} + ) + + list(APPEND out_files "${CMAKE_CURRENT_BINARY_DIR}/${src}") + endif(src STREQUAL "BEFORE") + endforeach(src ${ARGS_DEFAULT_ARGS}) + + add_custom_target( + ${name} ALL DEPENDS ${out_files} + ) endmacro(erl_target) |