summaryrefslogtreecommitdiffstats
path: root/cmake/erlang/ErlangTarget.cmake
blob: 3a21800bdb518ad1669b4268582dafaf7bd4ba3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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(
	OUTPUT
            ${out_file} 
        COMMAND 
            ${ERLC_EXECUTABLE} 
        ARGS 
            "-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}
    )
endmacro(erl_target)