Skip to content

Commit f08e88c

Browse files
authored
Android and Windows (MSVC2019, MinGW32/64) ready, and other minor improvements (#76)
* Fix out-of-source build Now `cmake -B target-dir -S .` works fine * Remove obsolete options and other garbage, improve warnings TODO: fix warnings * _REENTRANT is dead since POSIX 1995 * -O3 should not be turned on for all compilers, but is on by default for fresh GCC * -g for Debug is redundant (-ggdb3 or something like this is preferable in some cases) * _XOPEN_SOURCE for better cross-platform compatibility * CMake does not need `distclean`: just remove the whole directory. In case of mistake when build is located in the source tree just stick to `git clean -dfx` * -Wextra provides useful warnings * Set target directories from build script * Fix types: avoid system id_t, use size_t instead Now can build for MinGW * Avoid implicit copy in for-loops * Fix potentially uninitialized POD-fields And few minor code improvements * Update Eigen submodule to the next patch 3.3.9 * MSVC2019 compatiblity But missing corresponding CI at the moment * Update PyBind module to 2.6.2 * Fix CI build problem: use correct full-featured git with ssh Also few warnings fixed in code * Android-ready version
1 parent fdbb0cf commit f08e88c

30 files changed

+115
-151
lines changed

.circleci/config.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ jobs:
2020
- run:
2121
name: "Configure and build native mrob library with Python bindings"
2222
command: |
23-
mkdir -p build && pushd build
24-
cmake $(dirs -l +1) && make -j 4
25-
popd
23+
mkdir -p build
24+
cmake -S $PWD -B $PWD/build \
25+
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=$PWD/bin \
26+
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$PWD/lib \
27+
&& cmake --build build -j $(nproc)
2628
- run:
2729
name: "Run FGraph_2d"
2830
command: |
@@ -62,6 +64,9 @@ jobs:
6264
docker:
6365
- image: quay.io/pypa/manylinux2010_x86_64
6466
steps:
67+
- run:
68+
name: "Install additional utils"
69+
command: yum install -y chrpath git openssh-clients
6570
- checkout
6671
- run:
6772
name: "Install fresh CMake into ManyLinux container"
@@ -71,9 +76,6 @@ jobs:
7176
- run:
7277
name: "Clone submodules"
7378
command: git submodule update --init --recursive
74-
- run:
75-
name: "Install additional utils"
76-
command: yum install -y chrpath
7779
- run:
7880
name: "Build Python wheels"
7981
command: scripts/build-wheels.sh
@@ -136,14 +138,14 @@ jobs:
136138
when: always
137139
publish-github-release:
138140
docker:
139-
- image: cibuilds/github:0.10
141+
- image: cibuilds/github:0.13
140142
steps:
141143
- attach_workspace:
142144
at: ~/
143145
- run:
144146
name: "Publish Release on GitHub"
145147
command: |
146-
VERSION=v$(ls ~/project/build/wheelhouse/*.whl | awk -F"-" '{ print $2 }')
148+
VERSION=v$(ls ~/project/build/wheelhouse/*.whl | cut -f2 -d-)
147149
ghr -t "${GITHUB_TOKEN}" \
148150
-u "${CIRCLE_PROJECT_USERNAME}" \
149151
-r "${CIRCLE_PROJECT_REPONAME}" \

.github/workflows/wheels.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Build macOS wheels
22

3-
on: [push, pull_request]
3+
on: [push, pull_request, workflow_dispatch]
44

55
jobs:
66
build_wheel:
@@ -19,7 +19,7 @@ jobs:
1919
run: brew install coreutils
2020

2121
- name: Build wheel
22-
run: sudo ./scripts/build-wheels-macOS.sh
22+
run: ./scripts/build-wheels-macOS.sh
2323

2424
- uses: actions/upload-artifact@v2
2525
with:

CMakeLists.txt

Lines changed: 19 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,31 @@ if(COMMAND cmake_policy)
66
cmake_policy(SET CMP0003 NEW)
77
endif(COMMAND cmake_policy)
88

9-
# The project name and the type of project
109
PROJECT(mrob)
11-
#MESSAGE(Project\ name:\ ${PROJECT_NAME})
12-
13-
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
14-
SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
15-
SET(CMAKE_INSTALL_PREFIX /usr/local)
1610

1711
IF (NOT CMAKE_BUILD_TYPE)
1812
SET(CMAKE_BUILD_TYPE "Release")
1913
ENDIF (NOT CMAKE_BUILD_TYPE)
2014

21-
# flag _REENTRANT for safe threads and NDEBUG to disable asserts
22-
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -D_REENTRANT")
23-
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -D_REENTRANT -DNDEBUG")
24-
#SET(CMAKE_CXX_STANDARD 11)
2515
SET(CMAKE_CXX_STANDARD 14)
16+
SET(CMAKE_CXX_EXTENSIONS ON)
17+
18+
IF(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
19+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") #TODO: /Wall but disable noisy warnings
20+
ADD_COMPILE_DEFINITIONS(_USE_MATH_DEFINES)
21+
SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
22+
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
23+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
24+
ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
25+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wno-inconsistent-missing-override")
26+
ELSE()
27+
ENDIF(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
28+
29+
2630

2731
# ===================================================================
28-
# DEPENDENCIES: locate the necessary dependencies for the project
29-
# DEPENDENCIES: Eigen (submodule pointing to 3.3.7)
30-
SET(Eigen_INCLUDE_DIRS ./external/Eigen)
31-
INCLUDE_DIRECTORIES(${Eigen_INCLUDE_DIRS})
32+
INCLUDE_DIRECTORIES(SYSTEM ./external/Eigen)
3233

33-
# DEPENDENCIES: pybind11 (submodule)
34-
SET(PYBIND11_CPP_STANDARD -std=c++14)
35-
ADD_SUBDIRECTORY(./external/pybind11)
3634

3735

3836
# ===================================================================
@@ -57,42 +55,7 @@ ADD_SUBDIRECTORY(./src/PCRegistration)
5755

5856
# New modules should be included here
5957

60-
# MROB python bingins, defined here:
61-
ADD_SUBDIRECTORY(./mrobpy)
62-
63-
64-
65-
ADD_CUSTOM_TARGET (distclean @echo cleaning cmake files)
66-
67-
IF (UNIX)
68-
ADD_CUSTOM_COMMAND(
69-
COMMENT "distribution clean"
70-
COMMAND make ARGS clean
71-
COMMAND rm ARGS -rf ${CMAKE_SOURCE_DIR}/build/*
72-
73-
TARGET distclean
74-
)
75-
ELSE(UNIX)
76-
ADD_CUSTOM_COMMAND(
77-
COMMENT "distclean only implemented in unix"
78-
TARGET distclean
79-
)
80-
ENDIF(UNIX)
81-
82-
ADD_CUSTOM_TARGET (uninstall @echo uninstall package)
83-
84-
IF (UNIX)
85-
ADD_CUSTOM_COMMAND(
86-
COMMENT "uninstall package"
87-
COMMAND xargs ARGS rm < install_manifest.txt
88-
89-
TARGET uninstall
90-
)
91-
ELSE(UNIX)
92-
ADD_CUSTOM_COMMAND(
93-
COMMENT "uninstall only implemented in unix"
94-
TARGET uninstall
95-
)
96-
ENDIF(UNIX)
97-
98-
58+
IF(NOT ANDROID)
59+
ADD_SUBDIRECTORY(./external/pybind11)
60+
ADD_SUBDIRECTORY(./mrobpy)
61+
ENDIF(NOT ANDROID)

external/Eigen

Submodule Eigen updated from 21ae2af to 0fd6b4f

external/pybind11

Submodule pybind11 updated 157 files

mrobpy/FGraphPy.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ using namespace mrob;
5858
class FGraphPy : public FGraphSolve
5959
{
6060
public:
61+
using id_t = Factor::id_t;
6162
/**
6263
* Constructor for the python binding. By default uses the Cholesky adjoint solving type, and some estimated number of nodes and factors.
6364
*/

scripts/build-wheels-macOS.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/bin/bash
12
# Copyright (c) 2018, Skolkovo Institute of Science and Technology (Skoltech)
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,7 +21,6 @@
2021
# miloslubov@gmail.com
2122
#
2223

23-
#!/bin/bash
2424
set -euo pipefail
2525
export LC_ALL=C
2626
export MACOSX_DEPLOYMENT_TARGET=10.9
@@ -40,10 +40,10 @@ do
4040
cmake .. -DPYTHON_EXECUTABLE:FILEPATH=$PYBIN \
4141
-DCMAKE_MACOSX_RPATH=ON \
4242
-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE \
43-
-DCMAKE_INSTALL_RPATH="@loader_path"
44-
make -j $NUMPROC
45-
46-
mv ../lib/* ../mrob
43+
-DCMAKE_INSTALL_RPATH="@loader_path" \
44+
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=$PWD/../bin \
45+
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$PWD/../mrob \
46+
&& cmake --build . -j $NUMPROC
4747
done
4848

4949
cd ../

scripts/build-wheels.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/bin/bash
12
# Copyright (c) 2018, Skolkovo Institute of Science and Technology (Skoltech)
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,7 +21,6 @@
2021
# miloslubov@gmail.com
2122
#
2223

23-
#!/bin/bash
2424
set -euo pipefail
2525
export LC_ALL=C
2626

@@ -34,23 +34,23 @@ cp ./__init__.py ./mrob/__init__.py
3434

3535
cd ./build
3636

37-
NUMPROC=$(grep -Ec '^processor\s+:' /proc/cpuinfo)
37+
NUMPROC=$(nproc)
3838
echo "Running $NUMPROC parallel jobs"
3939

4040
LATEST=""
4141

4242
for PYBIN in /opt/python/cp3*/bin/
4343
do
4444
LATEST=${PYBIN}
45-
46-
cmake .. -DPYTHON_EXECUTABLE:FILEPATH=${PYBIN}python3
47-
make -j $NUMPROC
48-
49-
mv --verbose ../lib/* ../mrob
45+
cmake -S .. -B . \
46+
-DPYTHON_EXECUTABLE:FILEPATH=${PYBIN}python3 \
47+
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=$PWD/../bin \
48+
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$PWD/../mrob \
49+
&& cmake --build . -j $(nproc)
5050
done
5151

5252
chrpath -r '$ORIGIN' ../mrob/mrob.*.so
53-
${LATEST}python3 -m pip install --user -q pep517
53+
${LATEST}python3 -m pip install $([[ -n "$VIRTUAL_ENV" ]] || echo "--user") -q pep517 auditwheel
5454
${LATEST}python3 -m pep517.build ../
5555
auditwheel repair ../dist/*.whl
5656

src/FGraph/factor_graph.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ FGraph::FGraph() :
3535
FGraph::~FGraph()
3636
{
3737
// clear every node's list of neigbours factors
38-
for (auto n: nodes_)
38+
for (auto &&n: nodes_)
3939
n->clear();
4040
factors_.clear();
4141
nodes_.clear();
@@ -45,8 +45,8 @@ bool FGraph::add_factor(std::shared_ptr<Factor> &factor)
4545
{
4646
factor->set_id(factors_.size());
4747
factors_.push_back(factor);
48-
auto list = factor->get_neighbour_nodes();
49-
for( auto n: *list)
48+
auto *list = factor->get_neighbour_nodes();
49+
for( auto &&n: *list)
5050
{
5151
n->add_factor(factor);
5252
}
@@ -101,9 +101,9 @@ void FGraph::print(bool completePrint) const
101101

102102
if(completePrint)
103103
{
104-
for (auto n : nodes_)
104+
for (auto &&n : nodes_)
105105
n->print();
106-
for (auto f : factors_)
106+
for (auto &&f : factors_)
107107
f->print();
108108
}
109109
}

src/FGraph/factor_graph_solve.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void FGraphSolve::build_adjacency()
226226
indNodesMatrix.reserve(nodes->size());
227227

228228
N_ = 0;
229-
for (id_t i = 0; i < nodes->size(); ++i)
229+
for (size_t i = 0; i < nodes->size(); ++i)
230230
{
231231
// calculate the indices to access
232232
uint_t dim = (*nodes)[i]->get_dim();
@@ -365,14 +365,14 @@ void FGraphSolve::update_nodes()
365365

366366
void FGraphSolve::synchronize_nodes_auxiliary_state()
367367
{
368-
for (auto n : nodes_)
368+
for (auto &&n : nodes_)
369369
n->set_auxiliary_state(n->get_state());
370370
}
371371

372372

373373
void FGraphSolve::synchronize_nodes_state()
374374
{
375-
for (auto n : nodes_)
375+
for (auto &&n : nodes_)
376376
n->set_state(n->get_auxiliary_state());
377377
}
378378

0 commit comments

Comments
 (0)