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}) set(deps "") set(current "") set(uses false) foreach(src ${ARGS_DEFAULT_ARGS}) if(src STREQUAL "USING") set(uses true) else(src STREQUAL "USING") if(uses) list(APPEND deps "${CMAKE_CURRENT_BINARY_DIR}/${src}.beam") set(uses false) else(uses) if(current) set(in_file "${CMAKE_CURRENT_SOURCE_DIR}/${current}") string(REPLACE ".erl" ".beam" current ${current}) set(out_file "${CMAKE_CURRENT_BINARY_DIR}/${current}") add_custom_command( OUTPUT ${out_file} COMMAND ${ERLC_EXECUTABLE} "-o" ${CMAKE_CURRENT_BINARY_DIR} "-pz" ${CMAKE_CURRENT_BINARY_DIR} ${ARGS_OPTIONS} ${in_file} DEPENDS ${in_file} ${headers} ${deps} ) list(APPEND out_files "${CMAKE_CURRENT_BINARY_DIR}/${current}") endif(current) set(current ${src}) set(deps "") endif(uses) endif(src STREQUAL "USING") endforeach(src ${ARGS_DEFAULT_ARGS}) set(in_file "${CMAKE_CURRENT_SOURCE_DIR}/${current}") string(REPLACE ".erl" ".beam" current ${current}) set(out_file "${CMAKE_CURRENT_BINARY_DIR}/${current}") add_custom_command( OUTPUT ${out_file} COMMAND ${ERLC_EXECUTABLE} "-o" ${CMAKE_CURRENT_BINARY_DIR} "-pz" ${CMAKE_CURRENT_BINARY_DIR} ${ARGS_OPTIONS} ${in_file} DEPENDS ${in_file} ${headers} ${deps} ) list(APPEND out_files "${CMAKE_CURRENT_BINARY_DIR}/${current}") add_custom_target( ${name} ALL DEPENDS ${out_files} ) endmacro(erl_target)