Skip to content

Commit

Permalink
Install python binding to python packages (#140)
Browse files Browse the repository at this point in the history
Install python package and search for conda python
  • Loading branch information
cyang-kth authored Nov 17, 2020
1 parent 82b301a commit ac8439e
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 123 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ before_install:
install:
- ./travis_install_dependency.sh
script:
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then export PATH=/usr/bin:${PATH}; fi
- mkdir -p build
- cd build
- cmake ..
- make -j 4
- ./fmm
- ./stmatch
- ./ubodt_gen
- export PYTHONPATH=${PYTHONPATH}:$(pwd)/python
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then export PATH=/usr/bin:${PATH}; fi
- sudo make install
- fmm
- stmatch
- ubodt_gen
- cd ../example/python
- which python
- python fmm_test.py
branches:
only:
Expand Down
118 changes: 59 additions & 59 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,25 @@ set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Skip resetting RPATH to empty
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

project(fmm)

set(CMAKE_BUILD_TYPE "Release")
# set(CMAKE_C_FLAGS "-std=c11")
set(CMAKE_CXX_FLAGS "-O3 -DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build")

list(APPEND CMAKE_MODULE_PATH
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/third_party/libosmium/cmake")

find_package(Conda)
if(CONDA_PREFIX)
message(STATUS "Set CONDA_PREFIX ${CONDA_PREFIX}")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CONDA_PREFIX})
else()
message(STATUS "Non conda exist, search library in default path")
endif()

if(NOT OSMIUM_INCLUDE_DIR)
set(OSMIUM_INCLUDE_DIR "third_party/libosmium/include")
endif()
Expand All @@ -61,7 +67,7 @@ else()
message(FATAL_ERROR "GDAL Not Found!")
endif (GDAL_FOUND)

find_package(Boost 1.54.0 REQUIRED serialization)
find_package(Boost 1.56.0 REQUIRED serialization)
if (Boost_FOUND)
message(STATUS "Boost headers found at ${Boost_INCLUDE_DIR}")
message(STATUS "Boost library found at ${Boost_LIBRARIES}")
Expand All @@ -78,7 +84,6 @@ if(OPENMP_FOUND)
message(STATUS "OpenMP_CXX_LIBRARIES found at ${OpenMP_CXX_LIBRARIES}")
endif()


include_directories(third_party)
include_directories(third_party/libosmium/include)
include_directories(third_party/protozero/include)
Expand All @@ -104,50 +109,7 @@ add_library(MM_OBJ OBJECT ${MMGlob})
add_library(FMM_OBJ OBJECT ${FMMGlob})
add_library(STMATCH_OBJ OBJECT ${STMATCHGlob})

add_executable(fmm src/app/fmm.cpp
$<TARGET_OBJECTS:MM_OBJ>
$<TARGET_OBJECTS:CORE>
$<TARGET_OBJECTS:CONFIG>
$<TARGET_OBJECTS:ALGORITHM>
$<TARGET_OBJECTS:UTIL>
$<TARGET_OBJECTS:IO>
$<TARGET_OBJECTS:NETWORK>
$<TARGET_OBJECTS:FMM_OBJ>)
target_link_libraries(fmm ${GDAL_LIBRARIES}
${OSMIUM_LIBRARIES}
${Boost_LIBRARIES}
${OpenMP_CXX_LIBRARIES})

add_executable(ubodt_gen src/app/ubodt_gen_app.cpp
$<TARGET_OBJECTS:MM_OBJ>
$<TARGET_OBJECTS:FMM_OBJ>
$<TARGET_OBJECTS:CORE>
$<TARGET_OBJECTS:CONFIG>
$<TARGET_OBJECTS:ALGORITHM>
$<TARGET_OBJECTS:UTIL>
$<TARGET_OBJECTS:IO>
$<TARGET_OBJECTS:NETWORK>)
target_link_libraries(ubodt_gen
${GDAL_LIBRARIES}
${Boost_LIBRARIES}
${OSMIUM_LIBRARIES}
${OpenMP_CXX_LIBRARIES})

add_executable(stmatch src/app/stmatch.cpp
$<TARGET_OBJECTS:MM_OBJ>
$<TARGET_OBJECTS:STMATCH_OBJ>
$<TARGET_OBJECTS:CORE>
$<TARGET_OBJECTS:CONFIG>
$<TARGET_OBJECTS:ALGORITHM>
$<TARGET_OBJECTS:UTIL>
$<TARGET_OBJECTS:IO>
$<TARGET_OBJECTS:NETWORK>)
target_link_libraries(stmatch
${OSMIUM_LIBRARIES}
${GDAL_LIBRARIES}
${OpenMP_CXX_LIBRARIES})

# Build h3
# Build h3 objects

set(UNCONFIGURED_API_HEADER third_party/h3/src/h3lib/include/h3api.h.in)
set(CONFIGURED_API_HEADER third_party/h3/src/h3lib/include/h3api.h)
Expand All @@ -161,20 +123,58 @@ file(GLOB h3Glob third_party/h3/src/h3lib/lib/*.c)
add_library(H3_OBJ OBJECT ${h3Glob})
target_include_directories(H3_OBJ PUBLIC ${H3_INCLUDE_PATH})

add_executable(h3mm src/app/h3mm.cpp
$<TARGET_OBJECTS:H3_OBJ> $<TARGET_OBJECTS:CONFIG>
$<TARGET_OBJECTS:UTIL>
### Set RPATH properties

set(CMAKE_SKIP_BUILD_RPATH FALSE)

# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)

set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# Creation of FMMLIB
add_library(FMMLIB SHARED
$<TARGET_OBJECTS:MM_OBJ>
$<TARGET_OBJECTS:FMM_OBJ>
$<TARGET_OBJECTS:STMATCH_OBJ>
$<TARGET_OBJECTS:CORE>
$<TARGET_OBJECTS:CONFIG>
$<TARGET_OBJECTS:ALGORITHM>
$<TARGET_OBJECTS:UTIL>
$<TARGET_OBJECTS:NETWORK>
$<TARGET_OBJECTS:IO>
$<TARGET_OBJECTS:CORE>)
$<TARGET_OBJECTS:H3_OBJ>)
target_link_libraries(FMMLIB
${OSMIUM_LIBRARIES}
${GDAL_LIBRARIES} ${Boost_LIBRARIES}
${OpenMP_CXX_LIBRARIES})
install(TARGETS FMMLIB DESTINATION lib)

# Add executables

add_executable(fmm src/app/fmm.cpp)
target_link_libraries(fmm FMMLIB)

add_executable(ubodt_gen src/app/ubodt_gen_app.cpp)
target_link_libraries(ubodt_gen FMMLIB)

add_executable(stmatch src/app/stmatch.cpp)
target_link_libraries(stmatch FMMLIB)

add_executable(h3mm src/app/h3mm.cpp)
target_include_directories(
h3mm PUBLIC ${H3_INCLUDE_PATH})

target_link_libraries(h3mm
${GDAL_LIBRARIES}
${OpenMP_CXX_LIBRARIES})
target_link_libraries(h3mm FMMLIB)

add_subdirectory(python)
add_subdirectory(test EXCLUDE_FROM_ALL)
message(STATUS "Installation folder ${CMAKE_INSTALL_PREFIX}")

install(TARGETS fmm ubodt_gen stmatch h3mm DESTINATION bin)

add_subdirectory(python)
add_subdirectory(test EXCLUDE_FROM_ALL)
10 changes: 4 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ init:
# clone directory
clone_folder: C:/cygwin64/home/appveyor/fmm

before_build:
- '%CYG_SH% "echo \"export PATH=/usr/local/lib:\$PATH\" >> ~/.bash_profile"'

build_script:
- '%CYG_SH% "cd fmm && mkdir build"'
- '%CYG_SH% "cd fmm/build && cmake .. && make -j 4 && make install"'

before_test:
- '%CYG_SH% "echo \"export PATH=/home/appveyor/fmm/build:\$PATH\" >> ~/.bash_profile"'
- '%CYG_SH% "echo \"export PYTHONPATH=/home/appveyor/fmm/build/python:\$PYTHONPATH\" >> ~/.bash_profile"'

test_script:
- '%CYG_SH% "fmm"'
- '%CYG_SH% "echo $PYTHONPATH"'
- '%CYG_SH% "cd fmm/example/python;python fmm_test.py"'

branches:
Expand All @@ -46,4 +44,4 @@ skip_commits:
- docs/*
- '**/*.html'
- '**/*.md'
- img/
- img/
24 changes: 24 additions & 0 deletions cmake/FindConda.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
if(DEFINED ENV{CONDA_PREFIX})
set(CONDA_PREFIX $ENV{CONDA_PREFIX} CACHE PATH "")
else()
# Assuming the active conda environment is on PATH, this finds the path of bin/ in the environment
find_program(CONDA_EXECUTABLE conda
PATHS ${CONDA_PREFIX}/bin ${CONDA_PREFIX}/Scripts ENV PATH
)
if(CONDA_EXECUTABLE)
execute_process(COMMAND ${CONDA_EXECUTABLE} info --root
OUTPUT_VARIABLE out_var
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(COMMAND ${CONDA_EXECUTABLE} info --envs
)
else()
message(STATUS "\nNo conda environment found in PATH!\nPATH=$ENV{PATH}\n")
endif()
set(CONDA_PREFIX ${out_var})
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Conda
REQUIRED_VARS CONDA_PREFIX
)
7 changes: 3 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y \
build-essential software-properties-common\
libboost-dev libboost-serialization-dev \
cmake \
libboost-dev libboost-serialization-dev libssl-dev \
cmake vim\
wget \
make libbz2-dev libexpat1-dev swig python-dev
RUN add-apt-repository -y ppa:ubuntugis/ppa && apt-get -q update
RUN apt-get -y install gdal-bin libgdal-dev
Expand All @@ -15,6 +16,4 @@ RUN mkdir -p build && \
cmake .. && \
make install
EXPOSE 8080
ENV PATH /fmm/build:$PATH
ENV PYTHONPATH /fmm/build/python:$PYTHONPATH
CMD
56 changes: 12 additions & 44 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ else()
message(FATAL_ERROR "Swig not found!\n")
endif()

find_package(PythonInterp 2.7 REQUIRED)
find_package(PythonLibs 2.7 REQUIRED)
if (PYTHONLIBS_FOUND)
message(STATUS "Python header found at ${PYTHON_INCLUDE_DIRS}")
Expand All @@ -16,62 +17,29 @@ else()
message(FATAL_ERROR "Python library not found!\n")
endif()

include_directories(${H3_INCLUDE_PATH})
message(STATUS "Include h3 headers at ${H3_INCLUDE_PATH}")

file(GLOB PYTHONFMMGlob
${PROJECT_SOURCE_DIR}/src/mm/fmm/fmm_algorithm.cpp
${PROJECT_SOURCE_DIR}/src/mm/fmm/ubodt.cpp
${PROJECT_SOURCE_DIR}/src/mm/fmm/ubodt_gen_algorithm.cpp)
file(GLOB PYTHONSTMATCHGlob
${PROJECT_SOURCE_DIR}/src/mm/stmatch/stmatch_algorithm.cpp)
execute_process(
COMMAND python -c "from distutils.sysconfig import get_python_lib;print get_python_lib()"
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Python packages ${PYTHON_SITE_PACKAGES}")

add_library(PYTHONFMM_OBJ OBJECT ${PYTHONFMMGlob})
add_library(PYTHONSTMATCH_OBJ OBJECT ${PYTHONSTMATCHGlob})
include_directories(${H3_INCLUDE_PATH})

set_source_files_properties(
${PROJECT_SOURCE_DIR}/python/fmm.i PROPERTIES INCLUDE_DIRECTORIES
ON ${H3_INCLUDE_PATH})
set_source_files_properties(
${PROJECT_SOURCE_DIR}/python/fmm.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties(
${PROJECT_SOURCE_DIR}/python/fmm.i PROPERTIES SWIG_FLAGS "")

add_library(pyfmmlib SHARED
$<TARGET_OBJECTS:MM_OBJ>
$<TARGET_OBJECTS:PYTHONFMM_OBJ>
$<TARGET_OBJECTS:PYTHONSTMATCH_OBJ>
$<TARGET_OBJECTS:CORE>
$<TARGET_OBJECTS:CONFIG>
$<TARGET_OBJECTS:ALGORITHM>
$<TARGET_OBJECTS:UTIL>
$<TARGET_OBJECTS:IO>
$<TARGET_OBJECTS:NETWORK>
$<TARGET_OBJECTS:H3_OBJ>)

set_property(TARGET pyfmmlib PROPERTY POSITION_INDEPENDENT_CODE ON)
target_link_libraries(pyfmmlib ${GDAL_LIBRARIES} ${Boost_LIBRARIES}
${OSMIUM_LIBRARIES} ${OpenMP_CXX_LIBRARIES})
# Add the target.
if (${CMAKE_VERSION} VERSION_LESS 3.13.0)
message(STATUS "Using swig add module")
set_property(SOURCE ${PROJECT_SOURCE_DIR}/python/fmm.i
PROPERTY SWIG_MODULE_NAME fmm)
SWIG_ADD_MODULE(fmm python ${PROJECT_SOURCE_DIR}/python/fmm.i)
swig_link_libraries(fmm
${PYTHON_LIBRARIES}
${Boost_LIBRARIES}
${OSMIUM_LIBRARIES}
pyfmmlib)
swig_link_libraries(fmm FMMLIB ${PYTHON_LIBRARIES})
install(TARGETS ${SWIG_MODULE_fmm_REAL_NAME} DESTINATION ${PYTHON_SITE_PACKAGES})
else()
message(STATUS "Using swig add library")
SWIG_ADD_LIBRARY(pyfmm
LANGUAGE python
SOURCES ${PROJECT_SOURCE_DIR}/python/fmm.i)
set_property(TARGET pyfmm PROPERTY OUTPUT_NAME fmm)
swig_link_libraries(pyfmm
${PYTHON_LIBRARIES}
${Boost_LIBRARIES}
${OSMIUM_LIBRARIES}
pyfmmlib)
swig_link_libraries(pyfmm FMMLIB ${PYTHON_LIBRARIES})
install(TARGETS pyfmm DESTINATION ${PYTHON_SITE_PACKAGES})
endif()

install(FILES ${CMAKE_BINARY_DIR}/python/fmm.py DESTINATION ${PYTHON_SITE_PACKAGES})
30 changes: 25 additions & 5 deletions src/config/network_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ FMM::CONFIG::NetworkConfig FMM::CONFIG::NetworkConfig::load_from_xml(
std::string id = xml_data.get("config.input.network.id", "id");
std::string source = xml_data.get("config.input.network.source","source");
std::string target = xml_data.get("config.input.network.target","target");
std::string mode = xml_data.get("config.input.network.mode","mode");
std::string mode = xml_data.get("config.input.network.mode","drive");
return FMM::CONFIG::NetworkConfig{file, id, source, target, mode};
};

Expand Down Expand Up @@ -54,14 +54,34 @@ void FMM::CONFIG::NetworkConfig::register_help(std::ostringstream &oss){
oss<<" one of drive|walk|bike|all \n";
};

bool FMM::CONFIG::NetworkConfig::is_osm_format() const {
if (FMM::UTIL::check_file_extension(file,"osm,pbf,bz2,o5m"))
return true;
return false;
};

bool FMM::CONFIG::NetworkConfig::is_shapefile_format() const {
if (FMM::UTIL::check_file_extension(file,"shp"))
return true;
return false;
};

bool FMM::CONFIG::NetworkConfig::validate() const {
if (!UTIL::file_exists(file)){
SPDLOG_CRITICAL("Network file not found {}",file);
return false;
}
if (mode!="drive" && mode!="walk" && mode!="bike" && mode!="all"){
SPDLOG_CRITICAL("Network mode not recognized {}",mode);
return false;
bool osm_format = is_osm_format();
bool shapefile_format = is_shapefile_format();
if (osm_format || shapefile_format){
if (osm_format){
if (mode!="drive" && mode!="walk" && mode!="bike" && mode!="all"){
SPDLOG_CRITICAL("Network mode not recognized {}",mode);
return false;
}
}
return true;
}
return true;
SPDLOG_CRITICAL("Network format not recognized {}",file);
return false;
}
Loading

0 comments on commit ac8439e

Please sign in to comment.