From 859c157a0fdd475304fb2549ebe81f73341735d3 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Thu, 17 Sep 2020 21:26:11 -0400 Subject: [PATCH 1/2] Use cmake to identify best Python version if Default requested --- CMakeLists.txt | 17 +++++++++++++++++ cmake/FindNumPy.cmake | 12 ++---------- cmake/GtsamMatlabWrap.cmake | 22 +++++++++------------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa6082cb3d..82adbc99f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,11 @@ set (GTSAM_VERSION_PATCH 0) math (EXPR GTSAM_VERSION_NUMERIC "10000 * ${GTSAM_VERSION_MAJOR} + 100 * ${GTSAM_VERSION_MINOR} + ${GTSAM_VERSION_PATCH}") set (GTSAM_VERSION_STRING "${GTSAM_VERSION_MAJOR}.${GTSAM_VERSION_MINOR}.${GTSAM_VERSION_PATCH}") +set (CMAKE_PROJECT_VERSION ${GTSAM_VERSION_STRING}) +set (CMAKE_PROJECT_VERSION_MAJOR ${GTSAM_VERSION_MAJOR}) +set (CMAKE_PROJECT_VERSION_MINOR ${GTSAM_VERSION_MINOR}) +set (CMAKE_PROJECT_VERSION_PATCH ${GTSAM_VERSION_PATCH}) + ############################################################################### # Gather information, perform checks, set defaults @@ -113,6 +118,18 @@ if(GTSAM_INSTALL_MATLAB_TOOLBOX AND NOT BUILD_SHARED_LIBS) endif() if(GTSAM_BUILD_PYTHON) + # 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() + + if(${GTSAM_PYTHON_VERSION} STREQUAL "Default") + set(GTSAM_PYTHON_VERSION "${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}" CACHE STRING "The version of Python to build the wrappers against." FORCE) + endif() + if(GTSAM_UNSTABLE_BUILD_PYTHON) if (NOT GTSAM_BUILD_UNSTABLE) message(WARNING "GTSAM_UNSTABLE_BUILD_PYTHON requires the unstable module to be enabled.") diff --git a/cmake/FindNumPy.cmake b/cmake/FindNumPy.cmake index 4f5743aa65..d55a760c6a 100644 --- a/cmake/FindNumPy.cmake +++ b/cmake/FindNumPy.cmake @@ -40,17 +40,9 @@ # Finding NumPy involves calling the Python interpreter if(NumPy_FIND_REQUIRED) - if(GTSAM_PYTHON_VERSION STREQUAL "Default") - find_package(PythonInterp REQUIRED) - else() - find_package(PythonInterp ${GTSAM_PYTHON_VERSION} EXACT REQUIRED) - endif() + find_package(PythonInterp ${GTSAM_PYTHON_VERSION} EXACT REQUIRED) else() - if(GTSAM_PYTHON_VERSION STREQUAL "Default") - find_package(PythonInterp) - else() - find_package(PythonInterp ${GTSAM_PYTHON_VERSION} EXACT) - endif() + find_package(PythonInterp ${GTSAM_PYTHON_VERSION} EXACT) endif() if(NOT PYTHONINTERP_FOUND) diff --git a/cmake/GtsamMatlabWrap.cmake b/cmake/GtsamMatlabWrap.cmake index 111114a7bc..4c44d2cb38 100644 --- a/cmake/GtsamMatlabWrap.cmake +++ b/cmake/GtsamMatlabWrap.cmake @@ -215,19 +215,15 @@ function(wrap_library_internal interfaceHeader linkLibraries extraIncludeDirs ex # Set up generation of module source file file(MAKE_DIRECTORY "${generated_files_path}") - if(GTSAM_PYTHON_VERSION STREQUAL "Default") - find_package(PythonInterp REQUIRED) - find_package(PythonLibs REQUIRED) - else() - find_package(PythonInterp - ${GTSAM_PYTHON_VERSION} - EXACT - REQUIRED) - find_package(PythonLibs - ${GTSAM_PYTHON_VERSION} - EXACT - REQUIRED) - endif() + find_package(PythonInterp + ${GTSAM_PYTHON_VERSION} + EXACT + REQUIRED) + find_package(PythonLibs + ${GTSAM_PYTHON_VERSION} + EXACT + REQUIRED) + set(_ignore gtsam::Point2 gtsam::Point3) From 25eb4a13fd9dac20efe8decca3855f2c90e77be0 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 18 Sep 2020 11:49:03 -0400 Subject: [PATCH 2/2] minor formatting --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82adbc99f6..a45c176775 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,7 +127,11 @@ if(GTSAM_BUILD_PYTHON) endif() if(${GTSAM_PYTHON_VERSION} STREQUAL "Default") - set(GTSAM_PYTHON_VERSION "${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}" CACHE STRING "The version of Python to build the wrappers against." FORCE) + set(GTSAM_PYTHON_VERSION "${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}" + CACHE + STRING + "The version of Python to build the wrappers against." + FORCE) endif() if(GTSAM_UNSTABLE_BUILD_PYTHON)