Skip to content

Commit

Permalink
fixed a few more swig setup (Project-OSRM#2)
Browse files Browse the repository at this point in the history
* building

* first version

* py3

* fix swig python bug

* delete ununsed

* adding

* minor fix

* fix

Co-authored-by: yu.w <[email protected]>
  • Loading branch information
wyBrian and yu.w authored Jul 24, 2020
1 parent 6f2971e commit 58cd831
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
15 changes: 8 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/include/)
include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include/)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/third_party/sol2/)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/third_party/variant/include)

set(BOOST_COMPONENTS date_time chrono filesystem iostreams program_options regex system thread unit_test_framework)

configure_file(
Expand Down Expand Up @@ -183,11 +182,12 @@ if (ENABLE_SWIG_JNI_BINDINGS OR ENABLE_SWIG_PYTHON_BINDINGS)
include_directories(SYSTEM "${JAVA_INCLUDE_PATH2}")
endif()
if (ENABLE_SWIG_PYTHON_BINDINGS)
find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
find_package(PythonInterp 3 REQUIRED)
find_package(PythonLibs 3 REQUIRED)
include_directories(SYSTEM "${PYTHON_INCLUDE_PATH}")
endif()
include(${SWIG_USE_FILE})

# set_source_files_properties(swig/osrm.i PROPERTIES CPLUSPLUS ON COMPILE_OPTIONS -includeall)
set_source_files_properties(swig/osrm.i PROPERTIES CPLUSPLUS ON)

Expand All @@ -213,14 +213,14 @@ if (ENABLE_SWIG_JNI_BINDINGS OR ENABLE_SWIG_PYTHON_BINDINGS)
SOURCES ${SwigSourcesGlob}
)
set_target_properties (
_pyosrm PROPERTIES
pyosrm PROPERTIES
SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE
OUTPUT_NAME _osrm
OUTPUT_NAME libosrm
LIBRARY_OUTPUT_DIRECTORY ${SWIG_PYTHON_OUTPUT_DIR}
ARCHIVE_OUTPUT_DIRECTORY ${SWIG_PYTHON_OUTPUT_DIR}
RUNTIME_OUTPUT_DIRECTORY ${SWIG_PYTHON_OUTPUT_DIR}
)
target_link_libraries(_pyosrm PRIVATE osrm ${PYTHON_LIBRARY})
target_link_libraries(pyosrm PRIVATE osrm ${PYTHON_LIBRARY})
endif()
if (ENABLE_SWIG_JNI_BINDINGS)
set(SWIG_JNI_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/swig/java")
Expand Down Expand Up @@ -606,6 +606,7 @@ if(ENABLE_MASON)
else()

find_package(Boost 1.54 REQUIRED COMPONENTS ${BOOST_COMPONENTS})

add_dependency_includes(${Boost_INCLUDE_DIRS})
if(WIN32 AND Boost_VERSION VERSION_LESS 106200)
message(FATAL_ERROR "Building with MSVC needs Boost 1.62 with CXX11_CONSTEXPR support")
Expand Down Expand Up @@ -861,7 +862,7 @@ if (ENABLE_SWIG_JNI_BINDINGS)
install(TARGETS SWIG_JNI DESTINATION lib)
endif()
if (ENABLE_SWIG_PYTHON_BINDINGS)
install(TARGETS _pyosrm DESTINATION lib)
install(TARGETS pyosrm DESTINATION lib)
endif()

# Install profiles and support library to /usr/local/share/osrm/profiles by default
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,15 @@ When using the code in a (scientific) publication, please cite
address = {New York, NY, USA},
}
```


## Build On MacOS
```bash
mkdir -p build
cd build
sudo cmake .. -DCMAKE_BUILD_TYPE=Release -DENABLE_MASON=ON -DBUILD_PACKAGE=OFF
sudo cmake --build .
```



1 change: 1 addition & 0 deletions swig/osrm.i
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#endif

#ifdef SWIGPYTHON
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif

%include <stl.i>
Expand Down
15 changes: 9 additions & 6 deletions swig/swig_osrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ osrm::engine::api::RouteParameters ServiceHandler::translate(const RouteParamete

auto transformed_radiuses = std::vector<boost::optional<double>>(raw.radiuses.size());
std::transform(raw.radiuses.begin(), raw.radiuses.end(), transformed_radiuses.begin(), ([] (Radius r) -> boost::optional<double>{
return boost::optional<double>((double)r.radius);
return boost::optional<double>(r.radius);
}));
params.radiuses = std::move(transformed_radiuses);

Expand All @@ -80,7 +80,7 @@ osrm::engine::api::TableParameters ServiceHandler::translate(const TableParamete

auto transformed_radiuses = std::vector<boost::optional<double>>(raw.radiuses.size());
std::transform(raw.radiuses.begin(), raw.radiuses.end(), transformed_radiuses.begin(), ([] (Radius r) -> boost::optional<double>{
return boost::optional<double>((double)r.radius);
return boost::optional<double>(r.radius);
}));
params.radiuses = std::move(transformed_radiuses);

Expand Down Expand Up @@ -109,7 +109,7 @@ osrm::engine::api::NearestParameters ServiceHandler::translate(const NearestPara

auto transformed_radiuses = std::vector<boost::optional<double>>(raw.radiuses.size());
std::transform(raw.radiuses.begin(), raw.radiuses.end(), transformed_radiuses.begin(), ([] (Radius r) -> boost::optional<double>{
return boost::optional<double>((double)r.radius);
return boost::optional<double>(r.radius);
}));
params.radiuses = std::move(transformed_radiuses);

Expand Down Expand Up @@ -140,7 +140,7 @@ osrm::engine::api::TripParameters ServiceHandler::translate(const TripParameters

auto transformed_radiuses = std::vector<boost::optional<double>>(raw.radiuses.size());
std::transform(raw.radiuses.begin(), raw.radiuses.end(), transformed_radiuses.begin(), ([] (Radius r) -> boost::optional<double>{
return boost::optional<double>((double)r.radius);
return boost::optional<double>(r.radius);
}));
params.radiuses = std::move(transformed_radiuses);

Expand All @@ -166,10 +166,13 @@ osrm::engine::api::MatchParameters ServiceHandler::translate(const MatchParamete
params.geometries = raw.returnGeoJson ? osrm::engine::api::RouteParameters::GeometriesType::GeoJSON : osrm::engine::api::RouteParameters::GeometriesType::Polyline;
params.steps = raw.steps;
params.overview = raw.returnOverview ? osrm::engine::api::RouteParameters::OverviewType::Full : osrm::engine::api::RouteParameters::OverviewType::False;
params.gaps = raw.gaps ? osrm::engine::api::MatchParameters::GapsType::Split : osrm::engine::api::MatchParameters::GapsType::Ignore;
params.tidy = raw.tidy;


auto transformed_radiuses = std::vector<boost::optional<double>>(raw.radiuses.size());
std::transform(raw.radiuses.begin(), raw.radiuses.end(), transformed_radiuses.begin(), ([] (Radius r) -> boost::optional<double>{
return boost::optional<double>((double)r.radius);
return boost::optional<double>(r.radius);
}));
params.radiuses = std::move(transformed_radiuses);

Expand All @@ -187,7 +190,7 @@ osrm::engine::api::MatchParameters ServiceHandler::translate(const MatchParamete

auto transformed_timestamps = std::vector<unsigned>(raw.timestamps.size());
std::transform(raw.timestamps.begin(), raw.timestamps.end(), transformed_timestamps.begin(), ([] (long ts) -> unsigned{
return ts / 1000;
return ts;
}));
params.timestamps = std::move(transformed_timestamps);

Expand Down
4 changes: 3 additions & 1 deletion swig/swig_osrm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Bearing {
};

struct Radius {
unsigned radius;
double radius;
};

struct BaseParameters {
Expand Down Expand Up @@ -117,6 +117,8 @@ struct TripParameters : public BaseParameters {
};

struct MatchParameters : public BaseParameters {
bool gaps = true;
bool tidy = false;
bool steps = false;
bool annotations = false;
bool returnGeoJson = true;
Expand Down

0 comments on commit 58cd831

Please sign in to comment.