Skip to content

Commit

Permalink
Basic CMake build system
Browse files Browse the repository at this point in the history
* Update to OSRM 5.18
* Fix build dependencies

Signed-off-by: Francis Giraldeau <[email protected]>
  • Loading branch information
giraldeau committed Jul 2, 2018
1 parent 3d1caab commit 20962e6
Show file tree
Hide file tree
Showing 21 changed files with 129 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "3rdparty/qhttp"]
path = 3rdparty/qhttp
url = https://github.com/giraldeau/qhttp.git
[submodule "3rdparty/rapidjson"]
path = 3rdparty/rapidjson
url = https://github.com/miloyip/rapidjson
1 change: 1 addition & 0 deletions 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(qhttp)
1 change: 1 addition & 0 deletions 3rdparty/rapidjson
Submodule rapidjson added at 7e68aa
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.10)

project(EvNav)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_AUTOMOC ON)

include(GNUInstallDirs)
find_package(Threads REQUIRED)
find_package(Qt5 COMPONENTS Core Network Test REQUIRED)
find_package(LibOSRM REQUIRED)
link_directories(${LibOSRM_LIBRARY_DIRS})

enable_testing()

add_subdirectory(3rdparty)
add_subdirectory(libevnav)
add_subdirectory(evnav-srv)
add_subdirectory(evnav-cli)
add_subdirectory(example)
add_subdirectory(tests)
63 changes: 63 additions & 0 deletions cmake/FindLibOSRM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# - Try to find LibOSRM
# Once done this will define
# LibOSRM_FOUND - System has LibOSRM
# LibOSRM_LIBRARIES - The libraries and ldflags needed to use LibOSRM
# LibOSRM_DEPENDENT_LIBRARIES - The libraries and ldflags need to link LibOSRM dependencies
# LibOSRM_LIBRARY_DIRS - The libraries paths needed to find LibOSRM
# LibOSRM_CXXFLAGS - Compiler switches required for using LibOSRM

find_package(PkgConfig)
pkg_search_module(PC_LibOSRM QUIET libosrm)

function(JOIN VALUES GLUE OUTPUT)
string (REPLACE ";" "${GLUE}" _TMP_STR "${VALUES}")
set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
endfunction()

list(REMOVE_ITEM PC_LibOSRM_CFLAGS " ")
JOIN("${PC_LibOSRM_CFLAGS}" " " output)

set(LibOSRM_CXXFLAGS ${output})
set(LibOSRM_LIBRARY_DIRS ${PC_LibOSRM_LIBRARY_DIRS})

find_path(LibOSRM_INCLUDE_DIR osrm/osrm.hpp
PATH_SUFFIXES osrm include/osrm include
HINTS ${PC_LibOSRM_INCLUDEDIR} ${PC_LibOSRM_INCLUDE_DIRS}
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/opt/local
/opt)

find_library(TEST_LibOSRM_STATIC_LIBRARY Names osrm.lib libosrm.a
PATH_SUFFIXES osrm lib/osrm lib
HINTS ${PC_LibOSRM_LIBDIR} ${PC_LibOSRM_LIBRARY_DIRS}
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/opt/local
/opt)
find_library(TEST_LibOSRM_DYNAMIC_LIBRARY Names libosrm.dylib libosrm.so
PATH_SUFFIXES osrm lib/osrm lib
HINTS ${PC_LibOSRM_LIBDIR} ${PC_LibOSRM_LIBRARY_DIRS}
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/opt/local
/opt)

set(LibOSRM_DEPENDENT_LIBRARIES ${PC_LibOSRM_STATIC_LDFLAGS})
set(LibOSRM_LIBRARIES ${PC_LibOSRM_LDFLAGS})

include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LIBOSRM_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(LibOSRM DEFAULT_MSG
LibOSRM_LIBRARY_DIRS
LibOSRM_CXXFLAGS
LibOSRM_LIBRARIES
LibOSRM_DEPENDENT_LIBRARIES
LibOSRM_INCLUDE_DIR)
3 changes: 3 additions & 0 deletions evnav-cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_executable(evnav-cli main.cpp)
target_link_libraries(evnav-cli evnavcore)
install(TARGETS evnav-cli DESTINATION bin)
2 changes: 1 addition & 1 deletion evnav-cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int main(int argc, char *argv[])
ChargerProvider provider;
provider.loadJson(args.at(1));

ChargerProvider dcfc = provider.filter(provider.fastChargerFilter());
ChargerProvider dcfc = provider.filter(ChargerProvider::fastChargerFilter);

qDebug() << "chargers loaded:" << provider.size();
qDebug() << "fast chargers:" << dcfc.size();
Expand Down
3 changes: 3 additions & 0 deletions evnav-srv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_executable(evnav-srv main.cpp)
target_link_libraries(evnav-srv evnavcore)
install(TARGETS evnav-srv DESTINATION bin)
2 changes: 1 addition & 1 deletion evnav-srv/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main(int argc, char *argv[])
qDebug() << "loading chargers...";
ChargerProvider provider;
provider.loadJson(args.at(1));
ChargerProvider dcfc = provider.filter(provider.fastChargerFilter());
ChargerProvider dcfc = provider.filter(ChargerProvider::fastChargerFilter);
qDebug() << "fast chargers found:" << dcfc.size();

evnav.setChargerProvider(&dcfc);
Expand Down
2 changes: 2 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_executable(minievnav main.cpp)
target_link_libraries(minievnav evnavcore)
3 changes: 1 addition & 2 deletions example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ int main(int argc, char *argv[])
config.storage_config = {argv[1]};
config.use_shared_memory = false;

qDebug() << config.storage_config.core_data_path.c_str();
qDebug() << config.storage_config.file_index_path.c_str();
qDebug() << config.storage_config.base_path.c_str();
qDebug() << config.storage_config.IsValid();
qDebug() << config.IsValid();

Expand Down
6 changes: 6 additions & 0 deletions libevnav/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
file(GLOB EVNAVCORE_SOURCES "*.cpp" "*.h")

add_library(evnavcore ${EVNAVCORE_SOURCES})
target_link_libraries(evnavcore PUBLIC Qt5::Core qhttp Threads::Threads ${LibOSRM_LIBRARIES} ${LibOSRM_DEPENDENT_LIBRARIES})
target_include_directories(evnavcore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${LibOSRM_INCLUDE_DIR} "${LibOSRM_INCLUDE_DIR}/osrm")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LibOSRM_CXXFLAGS}")
2 changes: 1 addition & 1 deletion libevnav/charger.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <osrm/util/coordinate.hpp>
#include <osrm/coordinate.hpp>

#include "edge.h"

Expand Down
5 changes: 5 additions & 0 deletions libevnav/chargerprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ ChargerProvider ChargerProvider::filter(std::function<bool (Charger &)> predicat
}
return ChargerProvider(filtered);
}

bool ChargerProvider::fastChargerFilter(Charger &charger)
{
return charger.level() == 3;
}
7 changes: 1 addition & 6 deletions libevnav/chargerprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ class ChargerProvider
int size() { return m_chargers.size(); }
QList<Charger> chargers() { return m_chargers.values(); }
Charger charger(VertexId id) { return m_chargers[id]; }


ChargerProvider filter(std::function<bool (Charger &)> predicate);

auto fastChargerFilter() {
return [](Charger &c){ return c.level() == 3; };
}

static bool fastChargerFilter(Charger &charger);
signals:

public slots:
Expand Down
2 changes: 2 additions & 0 deletions libevnav/evnav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#define _USE_MATH_DEFINES
#include <cmath>

using namespace osrm;

Evnav::Evnav(const QString &osrm)
{
Q_UNUSED(osrm);
Expand Down
4 changes: 1 addition & 3 deletions libevnav/evnav.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#include "evnavrequest.h"
#include "graph.h"

using namespace osrm;

class Trip {
public:
int dist_m;
Expand All @@ -35,7 +33,7 @@ class Evnav
void route(EvnavRequest &req, QJsonObject &result);
void write(QVector<Edge> &path, QJsonObject &json);

engine::Status computeTrip(const Coordinate &src, const Coordinate &dst, Trip &t);
engine::Status computeTrip(const osrm::util::Coordinate &src, const osrm::util::Coordinate &dst, Trip &t);
void chargerMatrix(std::function<void (Charger &, Charger &, Trip &)> cb);
void computeDistanceHistogram(QVector<int> &hist, int bin);

Expand Down
6 changes: 3 additions & 3 deletions libevnav/shortestpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ double ShortestPath::distTo(VertexId dst)
{
if (m_distTo.contains(dst))
return m_distTo[dst];
return INFINITY;
return Q_INFINITY;
}

bool ShortestPath::hasPathTo(VertexId dst)
Expand All @@ -49,8 +49,8 @@ QList<Edge> ShortestPath::pathTo(VertexId dst)

void ShortestPath::relax(Edge &e)
{
double old_dist = INFINITY;
double new_dist = INFINITY;
double old_dist = Q_INFINITY;
double new_dist = Q_INFINITY;
VertexId v = e.from();
VertexId w = e.to();
if (m_distTo.contains(v))
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(graph)
4 changes: 4 additions & 0 deletions tests/graph/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_executable(tst_graphtest tst_graphtest.cpp)
target_link_libraries(tst_graphtest evnavcore Qt5::Test)
#target_include_directories(tst_graphtest PRIVATE "${LibOSRM_INCLUDE_DIRS}")
target_compile_definitions(tst_graphtest PRIVATE TOPSRCDIR="${CMAKE_SOURCE_DIR}")
2 changes: 1 addition & 1 deletion tests/graph/tst_graphtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void GraphTest::testLoadCharger()
QString path(TOPSRCDIR "/res/result_circuit_electrique_20161019165359.json");
provider.loadJson(path);
QVERIFY2(provider.size() > 0, "failed to load the charger list");
ChargerProvider dcfc = provider.filter(provider.fastChargerFilter());
ChargerProvider dcfc = provider.filter(ChargerProvider::fastChargerFilter);
QVERIFY2(dcfc.size() > 0, "failed to filter chargers");
}

Expand Down

0 comments on commit 20962e6

Please sign in to comment.