@@ -8,47 +8,76 @@ set (PLOVER_GENERATED_H_DIR ${CMAKE_SOURCE_DIR}/include/libswiftnav/plover CACHE
8
8
file (MAKE_DIRECTORY ${PLOVER_GENERATED_H_DIR} )
9
9
10
10
# Find default cabal
11
- find_program (CMAKE_cabal NAMES cabal )
11
+ find_program (CMAKE_CABAL NAMES cabal )
12
+ # Find plover executable
13
+ find_program (CMAKE_PLOVER NAMES plover )
12
14
13
15
if (DEFINED ENV{CABAL} )
14
- message ("Saw cabal flag: $ENV{CABAL} " )
15
- set (CMAKE_cabal $ENV{CABAL} )
16
+ message ("Saw CABAL flag: $ENV{CABAL} " )
17
+ set (CMAKE_CABAL $ENV{CABAL} )
16
18
else ()
17
- message ("Environment variable 'CABAL' not set. Defaulting to ${CMAKE_cabal} ." )
19
+ message ("Environment variable 'CABAL' not set. Defaulting to ${CMAKE_CABAL} ." )
20
+ endif ()
21
+ if (DEFINED ENV{PLOVER} )
22
+ message ("Saw PLOVER flag. Using $ENV{PLOVER} " )
23
+ set (CMAKE_PLOVER $ENV{PLOVER} )
24
+ else ()
25
+ message ("Environment variable 'PLOVER' not set. Defaulting to ${CMAKE_PLOVER} ." )
18
26
endif ()
19
27
20
- set ( plover_HS_SRCS
21
- Main.hs
22
- AmbiguityTest.hs
28
+ # Haskell files with macro plover definitions
29
+ # TODO implement build step
30
+ set ( PLOVER_HS_SRCS
23
31
)
24
32
25
- set (plover_SRCS
26
- ${PLOVER_GENERATED_C_DIR} /ambiguity_test.c
27
- CACHE INTERNAL ""
33
+ # For each unit in PLOVER_UNITS:
34
+ # Expects ${unit}.plv in PLOVER_DIR
35
+ # Generates ${unit}.c in PLOVER_GENERATED_C_DIR
36
+ # and ${unit}.h in PLOVER_GENERATED_H_DIR
37
+ set (PLOVER_UNITS
38
+ prelude
39
+ qr
28
40
)
29
41
30
- set (plover_HDRS
31
- ${PLOVER_GENERATED_H_DIR} /ambiguity_test.h
32
- CACHE INTERNAL ""
33
- )
42
+ foreach (unit ${PLOVER_UNITS} )
43
+ list (APPEND PLOVER_CFILES "${PLOVER_GENERATED_C_DIR} /${unit} .c" )
44
+ list (APPEND PLOVER_HFILES "${PLOVER_GENERATED_H_DIR} /${unit} .h" )
45
+ list (APPEND PLOVER_SRC "${PLOVER_DIR} /${unit} .plv" )
46
+ endforeach (unit )
47
+
48
+ # Make available to src/ CMakeLists
49
+ set (PLOVER_CFILES ${PLOVER_CFILES} PARENT_SCOPE )
50
+ set (PLOVER_HFILES ${PLOVER_HFILES} PARENT_SCOPE )
51
+
52
+ # Main project depends on generate. generate depends on generated files.
53
+ add_custom_target (generate DEPENDS ${PLOVER_CFILES} ${PLOVER_HFILES} )
54
+
55
+ if (CMAKE_CABAL AND CMAKE_PLOVER )
56
+ message ("\n Found Plover tools." )
57
+ # Don't add step if no UNITS are specified
58
+ if (PLOVER_CFILES OR PLOVER_HFILES )
59
+ message ("Adding code generation steps, one for each plv unit.\n\
60
+ Will run if plover subproject is modified and after make clean or clean-generate." )
61
+ foreach (unit ${PLOVER_UNITS} )
62
+ add_custom_command (
63
+ OUTPUT "${PLOVER_GENERATED_C_DIR} /${unit} .c" "${PLOVER_GENERATED_H_DIR} /${unit} .h"
64
+ COMMAND ${CMAKE_PLOVER}
65
+ -I "${PLOVER_DIR} "
66
+ --cdir "${PLOVER_GENERATED_C_DIR} " --hdir "${PLOVER_GENERATED_H_DIR} "
67
+ --libprefix "libswiftnav/plover"
68
+ "${PLOVER_DIR} /${unit} .plv"
69
+ WORKING_DIRECTORY ${PLOVER_DIR}
70
+ DEPENDS "${PLOVER_DIR} /${unit} .plv" )
71
+ endforeach (unit )
72
+ endif ()
73
+ message ("" )
34
74
35
- if (CMAKE_cabal )
36
- message ("\n Found Haskell tools. Adding code generation step (to be run if Haskell subproject is modified).\n " )
37
- add_custom_command (
38
- OUTPUT ${plover_SRCS} ${plover_HDRS}
39
- COMMAND ${CMAKE_cabal} run "${PLOVER_GENERATED_C_DIR} " "${PLOVER_GENERATED_H_DIR} "
40
- WORKING_DIRECTORY ${PLOVER_DIR}
41
- DEPENDS ${plover_HS_SRCS} )
42
75
else ()
43
- message ("\n No Haskell toolchain (cabal) found. Code generation with Plover is disabled.\n " )
76
+ message ("\n No Plover toolchain found. Code generation is disabled.\n " )
44
77
endif ()
45
78
46
- add_custom_target (clean_generate
79
+ add_custom_target (clean-generate
47
80
COMMAND ${CMAKE_COMMAND} -E remove_directory ${PLOVER_DIR} /dist
48
81
COMMAND ${CMAKE_COMMAND} -E remove ${PLOVER_GENERATED_C_DIR} /*
49
82
COMMAND ${CMAKE_COMMAND} -E remove ${PLOVER_GENERATED_H_DIR} /*
50
83
)
51
-
52
- # Main project depends on generated code
53
- add_custom_target (generate DEPENDS ${plover_SRCS} ${plover_HDRS} )
54
-
0 commit comments