Skip to content
This repository was archived by the owner on Apr 13, 2021. It is now read-only.

Commit c4203a8

Browse files
committed
update cmake with new plover compiler, example code
1 parent c942a03 commit c4203a8

File tree

10 files changed

+698
-117
lines changed

10 files changed

+698
-117
lines changed

include/libswiftnav/plover/ambiguity_test.h

Lines changed: 0 additions & 13 deletions
This file was deleted.

plover/AmbiguityTest.hs

Lines changed: 0 additions & 33 deletions
This file was deleted.

plover/CMakeLists.txt

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,76 @@ set (PLOVER_GENERATED_H_DIR ${CMAKE_SOURCE_DIR}/include/libswiftnav/plover CACHE
88
file(MAKE_DIRECTORY ${PLOVER_GENERATED_H_DIR})
99

1010
# 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)
1214

1315
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})
1618
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}.")
1826
endif ()
1927

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
2331
)
2432

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
2840
)
2941

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("\nFound 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("")
3474

35-
if (CMAKE_cabal)
36-
message("\nFound 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})
4275
else ()
43-
message("\nNo Haskell toolchain (cabal) found. Code generation with Plover is disabled.\n")
76+
message("\nNo Plover toolchain found. Code generation is disabled.\n")
4477
endif ()
4578

46-
add_custom_target(clean_generate
79+
add_custom_target(clean-generate
4780
COMMAND ${CMAKE_COMMAND} -E remove_directory ${PLOVER_DIR}/dist
4881
COMMAND ${CMAKE_COMMAND} -E remove ${PLOVER_GENERATED_C_DIR}/*
4982
COMMAND ${CMAKE_COMMAND} -E remove ${PLOVER_GENERATED_H_DIR}/*
5083
)
51-
52-
# Main project depends on generated code
53-
add_custom_target(generate DEPENDS ${plover_SRCS} ${plover_HDRS})
54-

plover/Main.hs

Lines changed: 0 additions & 18 deletions
This file was deleted.

plover/README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
requires installation of https://github.com/swift-nav/plover for code generation
2+
3+
new plover files should be added to the local CMakeLists.txt file. see `PLOVER_UNITS`

plover/libswiftnav-generate.cabal

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)