Skip to content

Commit

Permalink
Squashed 'wrap/' changes from 20e8e8b7a..6476fd710
Browse files Browse the repository at this point in the history
6476fd710 Merge pull request #16 from borglab/feature/better-find-python
8ac1296a0 use setup.py to install dependencies
e9ac473be install dependencies and support versions of CMake<3.12
cf272dbd2 Merge pull request #15 from borglab/feature/utils
ffc9cc4f7 new utils to reduce boilerplate

git-subtree-dir: wrap
git-subtree-split: 6476fd710e6dac7eb96d47fd69cd56ddca6a2e07
  • Loading branch information
varunagrawal committed Dec 29, 2020
1 parent 95d875d commit 2845021
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 51 deletions.
61 changes: 20 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,63 +1,42 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.10)

# Set the project name and version
project(GTwrap VERSION 1.0)

##############################
# ##############################################################################
# General configuration

# Sets the path to the interface parser.
set(GTWRAP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

set(WRAP_PYTHON_VERSION "Default"
CACHE STRING
"The Python version to use for wrapping")
set(WRAP_PYTHON_VERSION
"Default"
CACHE STRING "The Python version to use for wrapping")

# Unset these cached variables to avoid surprises when the python
# in the current environment are different from the cached!
unset(PYTHON_EXECUTABLE CACHE)
unset(PYTHON_INCLUDE_DIR CACHE)
unset(PYTHON_MAJOR_VERSION CACHE)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GtwrapUtils.cmake)
gtwrap_get_python_version(${WRAP_PYTHON_VERSION})

# Allow override from command line
if(WRAP_PYTHON_VERSION STREQUAL "Default")
# Check for Python3 or Python2 in order
find_package(Python COMPONENTS Interpreter Development)

set(WRAP_PYTHON_VERSION "${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}"
CACHE
STRING
"The version of Python to build the wrappers against."
FORCE)

else()
find_package(Python ${WRAP_PYTHON_VERSION}
COMPONENTS Interpreter Development
EXACT
REQUIRED)
endif()


##############################
# ##############################################################################
# Install the CMake file to be used by other projects
if(WIN32 AND NOT CYGWIN)
set(SCRIPT_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/CMake")
set(SCRIPT_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/CMake")
else()
set(SCRIPT_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib/cmake")
set(SCRIPT_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib/cmake")
endif()

configure_file(cmake/PybindWrap.cmake.in
${CMAKE_CURRENT_SOURCE_DIR}/cmake/PybindWrap.cmake @ONLY)
# Install scripts
install(FILES
cmake/PybindWrap.cmake cmake/gtwrapConfig.cmake
DESTINATION "${SCRIPT_INSTALL_DIR}/gtwrap")

install(FILES cmake/PybindWrap.cmake cmake/gtwrapConfig.cmake
cmake/GtwrapUtils.cmake
DESTINATION "${SCRIPT_INSTALL_DIR}/gtwrap")

##############################
# ##############################################################################
# Install the Python package
find_package(Python ${WRAP_PYTHON_VERSION}
COMPONENTS Interpreter REQUIRED)
find_package(
Python ${WRAP_PYTHON_VERSION}
COMPONENTS Interpreter
REQUIRED)

# Detect virtualenv and set Pip args accordingly
# https://www.scivision.dev/cmake-install-python-package/
Expand All @@ -67,7 +46,7 @@ else()
set(_pip_args "--user")
endif()

# We install in development mode (-e flag) so any updates
# to the package are automatically propagated.
# We install in development mode (-e flag) so any updates to the package are
# automatically propagated.
execute_process(COMMAND ${Python_EXECUTABLE} -m pip install -e . ${_pip_args}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
95 changes: 95 additions & 0 deletions cmake/GtwrapUtils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Utilities to help with wrapping.

function(get_python_version)
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
# Use older version of cmake's find_python
find_package(PythonInterp)

if(NOT ${PYTHONINTERP_FOUND})
message(
FATAL_ERROR
"Cannot find Python interpreter. Please install Python >= 3.6.")
endif()

find_package(PythonLibs ${PYTHON_VERSION_STRING})

set(Python_VERSION_MAJOR
${PYTHON_VERSION_MAJOR}
PARENT_SCOPE)
set(Python_VERSION_MINOR
${PYTHON_VERSION_MINOR}
PARENT_SCOPE)
set(Python_EXECUTABLE
${PYTHON_EXECUTABLE}
PARENT_SCOPE)

else()
# Get info about the Python3 interpreter
# https://cmake.org/cmake/help/latest/module/FindPython3.html#module:FindPython3
find_package(Python3 COMPONENTS Interpreter Development)

if(NOT ${Python3_FOUND})
message(
FATAL_ERROR
"Cannot find Python3 interpreter. Please install Python >= 3.6.")
endif()

set(Python_VERSION_MAJOR
${Python3_VERSION_MAJOR}
PARENT_SCOPE)
set(Python_VERSION_MINOR
${Python3_VERSION_MINOR}
PARENT_SCOPE)

endif()
endfunction()

# Set the Python version for the wrapper and set the paths to the executable and
# include/library directories. WRAP_PYTHON_VERSION can be "Default" or a
# specific major.minor version.
function(gtwrap_get_python_version WRAP_PYTHON_VERSION)
# Unset these cached variables to avoid surprises when the python in the
# current environment are different from the cached!
unset(Python_EXECUTABLE CACHE)
unset(Python_INCLUDE_DIRS CACHE)
unset(Python_VERSION_MAJOR CACHE)
unset(Python_VERSION_MINOR CACHE)

# Allow override
if(${WRAP_PYTHON_VERSION} STREQUAL "Default")
# Check for Python3 or Python2 in order
get_python_version()

set(WRAP_PYTHON_VERSION
"${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}"
CACHE STRING "The version of Python to build the wrappers against."
FORCE)

# message("========= ${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}")
# message("========= WRAP_PYTHON_VERSION=${WRAP_PYTHON_VERSION}")
# message("========= Python_EXECUTABLE=${Python_EXECUTABLE}")

else()
find_package(
Python ${WRAP_PYTHON_VERSION}
COMPONENTS Interpreter Development
EXACT REQUIRED)
endif()

set(WRAP_PYTHON_VERSION
${WRAP_PYTHON_VERSION}
PARENT_SCOPE)
set(Python_FOUND
${Python_FOUND}
PARENT_SCOPE)
set(Python_EXECUTABLE
${Python_EXECUTABLE}
PARENT_SCOPE)
set(Python_INCLUDE_DIRS
${Python_INCLUDE_DIRS}
PARENT_SCOPE)
set(Python_LIBRARY_DIRS
${Python_LIBRARY_DIRS}
PARENT_SCOPE)

endfunction()
13 changes: 11 additions & 2 deletions cmake/gtwrapConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# This config file modifies CMAKE_MODULE_PATH so that the wrap cmake files may be included
# This file also allows the use of `find_package(gtwrap)` in CMake.
# This config file modifies CMAKE_MODULE_PATH so that the wrap cmake files may
# be included This file also allows the use of `find_package(gtwrap)` in CMake.

set(GTWRAP_DIR "${CMAKE_CURRENT_LIST_DIR}")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")

if(WIN32 AND NOT CYGWIN)
set(SCRIPT_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/CMake")
else()
set(SCRIPT_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib/cmake")
endif()

include(${SCRIPT_INSTALL_DIR}/gtwrap/PybindWrap.cmake)
include(${SCRIPT_INSTALL_DIR}/gtwrap/GtwrapUtils.cmake)
13 changes: 5 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"""Setup file for the GTwrap package"""

import os
import sys

try:
from setuptools import find_packages, setup
except ImportError:
Expand All @@ -14,10 +11,10 @@
name='gtwrap',
description='Library to wrap C++ with Python and Matlab',
version='1.0.0',
author="",
author_email="",
license='',
keywords="",
author="Frank Dellaert et. al.",
author_email="dellaert@gatech.edu",
license='BSD',
keywords="wrap, bindings, cpp, python",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
python_requires=">=3.6",
Expand All @@ -35,5 +32,5 @@
],
packages=packages,
platforms="any",
# install_requires=["gtsam>=4", "opencv"],
install_requires=open("requirements.txt").readlines(),
)

0 comments on commit 2845021

Please sign in to comment.