diff --git a/CMakeLists.txt b/CMakeLists.txt index a2a04a9d..94477349 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,9 +8,14 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-backtrace-limit=0") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") - -find_package(Boost REQUIRED COMPONENTS python-py35 serialization system filesystem) -find_package(PythonLibs 3.5 REQUIRED) # sets ${PYTHON_INCLUDE_DIRS} +option(USE_PYTHON3 "Use python 3 to build libraries." ON) +if (USE_PYTHON3) + find_package(Boost REQUIRED COMPONENTS python-py35 serialization system filesystem) + find_package(PythonLibs 3.5 REQUIRED) # sets ${PYTHON_INCLUDE_DIRS} +else() + find_package(Boost REQUIRED COMPONENTS python serialization system filesystem) + find_package(PythonLibs 2.7 REQUIRED) # sets ${PYTHON_INCLUDE_DIRS} +endif() find_package(Eigen3 QUIET) if(NOT EIGEN3_FOUND) find_package(PkgConfig REQUIRED) @@ -65,7 +70,6 @@ foreach(SUBMODULE ${MODUELS}) lanelet2_python/python_api/${SUBMODULE}.cpp # binding codes ) target_compile_definitions(${API_LIBRARY_NAME} PRIVATE -DPYTHON_API_MODULE_NAME=lib${API_LIBRARY_NAME}) - #target_compile_options(${API_LIBRARY_NAME} PRIVATE -Wl,-rpath='$ORIGIN') target_link_libraries(${API_LIBRARY_NAME} ${Boost_LIBRARIES} ${PYTHON_LIBRARY} diff --git a/README.md b/README.md index 2884e2ee..e8ab5f3a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # lanelet2_standalone ## Overview -This is a standalone lanelet2 **python3** package for the [Lanelet2](https://github.com/fzi-forschungszentrum-informatik/Lanelet2) library, which **does not** require the ROS and catkin. +This is a standalone lanelet2 **python3/python2** package for the [Lanelet2](https://github.com/fzi-forschungszentrum-informatik/Lanelet2) library, which **does not** require the ROS and catkin. ## Installation pylanelet2 uses cmake and setuptools for building and packaging and is targeted towards Linux. @@ -10,13 +10,13 @@ At least C++14 is required. ### Tested Configuration * `Ubuntu 16.04 LTS` -* `python3.5` +* `python2.7/python3.5` ### Dependencies * `Boost` (from 1.58, for lanelet2_io) * `eigen3` * `pugixml` (for lanelet2_io) -* `boost-python/python3` +* `boost-python2/python3` * `geographiclib` (for lanelet2_projection) For Ubuntu: @@ -25,13 +25,22 @@ sudo apt-get install -y cmake libboost-all-dev libeigen3-dev libgeographic-dev l ``` ### Installing -In the repo root folder, +* Building +```bash +git clone https://github.com/yuzhangbit/lanelet2_standalone.git +cd lanelet2_standalone +``` +* Install lanelet2 for system python3: ```shell sudo python3 setup.py install ``` -or +* Or install lanelet2 for system python2: ```bash -/path/to/your/python3 setup.py install +sudo python setup.py install +``` +* Or install lanelet2 for other python version: +``` +/path/to/python setup.py install ``` ## Usage @@ -49,7 +58,7 @@ p.id = getId() ``` **Note: -Importing submodules from the raw `liblanelet2_core_pyapi.so` library like below is not supported.** +Importing submodules from the raw `liblanelet2_core_pyapi.so` library like below is not supported.** If you do this, ```python from lanelet2.liblanelet2_core_pyapi import AttributeMap # not supported!!! diff --git a/setup.py b/setup.py index 9d8d1c94..91fc8369 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python3 +#! /usr/bin/env python from setuptools import setup, Extension from io import open import subprocess @@ -25,12 +25,18 @@ def run(self): def build_extension(self, ext): extdir = os.path.abspath( os.path.dirname(self.get_ext_fullpath(ext.name))) + # python version + self.python_version = sys.version_info.major cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, '-DPYTHON_EXECUTABLE=' + sys.executable] cfg = 'Debug' if self.debug else 'Release' build_args = ['--config', cfg] cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] + if self.python_version == 3: + cmake_args += ['-DUSE_PYTHON3=ON'] + else: + cmake_args += ['-DUSE_PYTHON3=OFF'] build_args += ['--', '-j4'] env = os.environ.copy() @@ -54,6 +60,7 @@ def build_extension(self, ext): 'Intended Audience :: Developers', 'Topic :: Software Development :: autonomous driving', 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 2.7', ], license='BSD 3-Clause', packages=['lanelet2'],