summaryrefslogtreecommitdiffstats
path: root/FindErlang.cmake
blob: 6b4d8d808813d49b4fb2d510bba705dd03e75934 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
find_program(ERL_EXECUTABLE NAMES erl)
find_program(ERLC_EXECUTABLE NAMES erlc)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Erlang DEFAULT_MSG ERL_EXECUTABLE ERLC_EXECUTABLE)
mark_as_advanced(ERL_EXECUTABLE)
mark_as_advanced(ERLC_EXECUTABLE)

if(ERLANG_FOUND)
    execute_process(COMMAND ${ERL_EXECUTABLE} "-noinput" "-eval" "io:format(\"~s\", [code:root_dir()])" "-eval" "halt()"
		    OUTPUT_VARIABLE "ERLANG_ROOT_DIR")
    execute_process(COMMAND ${ERL_EXECUTABLE} "-noinput" "-eval" "io:format(\"~s\", [code:lib_dir()])" "-eval" "halt()"
		    OUTPUT_VARIABLE "ERLANG_LIB_DIR")
endif(ERLANG_FOUND)


macro(erl_check_library name)
    find_package(Erlang REQUIRED)

    if(NOT ${name}_FOUND)

        foreach(arg ${ARGN})
            if (arg STREQUAL "REQUIRED")
                set(required 1)
            elseif (arg STREQUAL "QUIET")
                set(quiet 1)
            endif (arg STREQUAL "REQUIRED")
        endforeach(arg ${ARGN})

        set(pkgs ${ARGN})
        list(REMOVE_ITEM pkgs "REQUIRED")
        list(REMOVE_ITEM pkgs "QUIET")

        list(GET pkgs 0 lib)

        if(NOT quiet)
            message("-- checking for Erlang library '${lib}'")
        endif(NOT quiet)

        execute_process(COMMAND ${ERL_EXECUTABLE} "-noinput"
                        "-eval" "Dir=code:lib_dir('${lib}'), if is_list(Dir) -> io:format(\"~s\", [Dir]); true -> ok end"
                        "-eval" "halt()" OUTPUT_VARIABLE "${name}_dir")

        if(NOT quiet)
            if(NOT ${name}_DIR STREQUAL "")
                message("--   found ${lib}")
            else(NOT ${name}_DIR STREQUAL "")
                message("--   library '${lib}' not found")
            endif(NOT ${name}_DIR STREQUAL "")
        endif(NOT quiet)

        if(${name}_DIR STREQUAL "")
            if(required)
                message(SEND_ERROR "A required library was not found")
            endif(required)
        else(${name}_DIR STREQUAL "")
            set(${name}_FOUND 1 CACHE INTERNAL "")
            set(${name}_DIR "${${name}_dir}" CACHE INTERNAL "")
            set(${name}_INCLUDE_DIR "${${name}_dir}/include" CACHE INTERNAL "")
            set(${name}_LIBRARY_DIR "${${name}_dir}/lib" CACHE INTERNAL "")
        endif(${name}_DIR STREQUAL "")

    endif(NOT ${name}_FOUND)
endmacro(erl_check_library)