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

Commit 2df1226

Browse files
committed
add plover build functionality, check_qr test
1 parent c942a03 commit 2df1226

File tree

17 files changed

+1534
-117
lines changed

17 files changed

+1534
-117
lines changed

include/libswiftnav/plover/ambiguity_test.h

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

include/libswiftnav/plover/prelude.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#ifndef PLOVER_GENERATED_prelude
2+
#define PLOVER_GENERATED_prelude
3+
4+
5+
#include <assert.h>
6+
7+
#include <stdint.h>
8+
#include <stdbool.h>
9+
#include <inttypes.h>
10+
#ifndef COMMON_INT_TYPES
11+
#define COMMON_INT_TYPES
12+
/** \defgroup common_inttypes Integer types
13+
* Specified-width integer type definitions for shorter and nicer code.
14+
*
15+
* These should be used in preference to unspecified width types such as
16+
* `int` which can lead to portability issues between different platforms.
17+
* \{ */
18+
19+
/** Signed 8-bit integer. */
20+
typedef int8_t s8;
21+
/** Signed 16-bit integer. */
22+
typedef int16_t s16;
23+
/** Signed 32-bit integer. */
24+
typedef int32_t s32;
25+
/** Signed 64-bit integer. */
26+
typedef int64_t s64;
27+
/** Unsigned 8-bit integer. */
28+
typedef uint8_t u8;
29+
/** Unsigned 16-bit integer. */
30+
typedef uint16_t u16;
31+
/** Unsigned 32-bit integer. */
32+
typedef uint32_t u32;
33+
/** Unsigned 64-bit integer. */
34+
typedef uint64_t u64;
35+
36+
#endif
37+
38+
/** \} */
39+
40+
#include <float.h>
41+
#include <stdio.h>
42+
#include <stdlib.h>
43+
#include <math.h>
44+
int ipow(int base, int exp);
45+
double dipow(double base, int exp);
46+
double rand_uniform(void);
47+
double rand_normal (void);
48+
double norm (const s32 n, const double * v);
49+
void normalize (const s32 n, const double * v, double * result);
50+
void print_vec (const s32 n, const double * v);
51+
void print_mat (const s32 n, const s32 m, const double * A);
52+
s32 matrix_inv (const s32 n, const double * A, double * B);
53+
double det (const s32 n, const double * A);
54+
55+
56+
#endif /* PLOVER_GENERATED_prelude */

include/libswiftnav/plover/qr.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef PLOVER_GENERATED_qr
2+
#define PLOVER_GENERATED_qr
3+
4+
#include "libswiftnav/plover/prelude.h"
5+
6+
s8 qr_solve (const s32 m, const s32 n, double * A, double * b, double * solution, double * const residual);
7+
void qr_update (const s32 m, const s32 n, double * b, double * A);
8+
9+
10+
#endif /* PLOVER_GENERATED_qr */

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)