summaryrefslogtreecommitdiffstats
path: root/kalzium/src/solver/CMakeLists.txt
blob: aef745d41128f1cfbe23cadbad541db9d6e47835 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
##### macro to build ocaml sources

macro( tde_add_ocaml_source _target _ml )

    get_filename_component( basename "${_ml}" NAME_WE )

    if( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${basename}.mli )
      add_custom_command(
        OUTPUT
            ${CMAKE_CURRENT_BINARY_DIR}/${basename}.cmi

        COMMENT "Compile ${basename}.mli"

        COMMAND ${OCAMLC_EXECUTABLE}
            -o ${CMAKE_CURRENT_BINARY_DIR}/${basename}.cmi
            -I ${FACILE_INCLUDE_DIR}
            -c ${CMAKE_CURRENT_SOURCE_DIR}/${basename}.mli

        DEPENDS
            ${CMAKE_CURRENT_SOURCE_DIR}/${basename}.ml
            ${ARGN}

        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
      )

      set( _build_cmi ${CMAKE_CURRENT_BINARY_DIR}/${basename}.cmi )
    else( )
      set( _build_cmi "" )
    endif( )

    add_custom_command(
        OUTPUT
            ${CMAKE_CURRENT_BINARY_DIR}/${basename}.cmx

        COMMENT "Compile ${basename}.ml"

        COMMAND ${OCAMLOPT_EXECUTABLE}
            -o ${CMAKE_CURRENT_BINARY_DIR}/${basename}.cmx
            -I ${FACILE_INCLUDE_DIR}
            -c ${CMAKE_CURRENT_SOURCE_DIR}/${basename}.ml

        DEPENDS
            ${CMAKE_CURRENT_SOURCE_DIR}/${basename}.ml
            ${_build_cmi}
            ${ARGN}

        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    )

    list( APPEND ${_target}-ocaml
        ${CMAKE_CURRENT_BINARY_DIR}/${basename}.cmx
    )
endmacro( )


# build kalzium ocaml solver

tde_add_ocaml_source( kalzium_solver chemset.ml )

tde_add_ocaml_source( kalzium_solver datastruct.ml
    ${CMAKE_CURRENT_BINARY_DIR}/chemset.cmi
)

tde_add_ocaml_source( kalzium_solver chem.ml
    ${CMAKE_CURRENT_BINARY_DIR}/chemset.cmi
    ${CMAKE_CURRENT_BINARY_DIR}/datastruct.cmi
)

tde_add_ocaml_source( kalzium_solver parser.ml
    ${CMAKE_CURRENT_BINARY_DIR}/chemset.cmi
)

tde_add_ocaml_source( kalzium_solver lexer.ml
    ${CMAKE_CURRENT_BINARY_DIR}/chemset.cmi
    ${CMAKE_CURRENT_BINARY_DIR}/parser.cmi
)

tde_add_ocaml_source( kalzium_solver calc.ml
    ${CMAKE_CURRENT_BINARY_DIR}/chem.cmi
    ${CMAKE_CURRENT_BINARY_DIR}/chemset.cmi
    ${CMAKE_CURRENT_BINARY_DIR}/datastruct.cmi
    ${CMAKE_CURRENT_BINARY_DIR}/parser.cmi
    ${CMAKE_CURRENT_BINARY_DIR}/lexer.cmx
)

add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/modwrap.o

    COMMAND ${OCAMLOPT_EXECUTABLE}
        -I ${FACILE_INCLUDE_DIR}
        -c ${CMAKE_CURRENT_SOURCE_DIR}/modwrap.c

    DEPENDS
        ${CMAKE_CURRENT_SOURCE_DIR}/modwrap.c
        ${CMAKE_CURRENT_BINARY_DIR}/solver.o

    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/solver.o

    COMMAND ${OCAMLOPT_EXECUTABLE} -output-obj
        -o ${CMAKE_CURRENT_BINARY_DIR}/solver.o
        ${FACILE_INCLUDE_DIR}/facile.cmxa
        ${kalzium_solver-ocaml}

    DEPENDS
        ${kalzium_solver-ocaml}

    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

add_custom_target( kalzium_solver
    DEPENDS
        ${CMAKE_CURRENT_BINARY_DIR}/modwrap.o
        ${CMAKE_CURRENT_BINARY_DIR}/solver.o
)