Skip to content

Commit

Permalink
1.9rc1 python (#2435)
Browse files Browse the repository at this point in the history
* Better handle mixed python 2 and 3 packaging.
Close #2431

* Numpy update.

* More fixes for NumPy.

* More numpy.

* Python3 with new cmake fixes.

* fixups for conda python3
  • Loading branch information
abellgithub committed Apr 2, 2019
1 parent f8fc8b3 commit 2f75651
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 66 deletions.
12 changes: 10 additions & 2 deletions cmake/macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ endmacro(PDAL_ADD_EXECUTABLE)
macro(PDAL_ADD_PLUGIN _name _type _shortname)
set(options)
set(oneValueArgs)
set(multiValueArgs FILES LINK_WITH INCLUDES)
set(multiValueArgs FILES LINK_WITH INCLUDES SYSTEM_INCLUDES)
cmake_parse_arguments(PDAL_ADD_PLUGIN "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})
if(WIN32)
Expand All @@ -137,6 +137,10 @@ macro(PDAL_ADD_PLUGIN _name _type _shortname)
${PDAL_INCLUDE_DIR}
${PDAL_ADD_PLUGIN_INCLUDES}
)
if (PDAL_ADD_PLUGIN_SYSTEM_INCLUDES)
target_include_directories(${${_name}} SYSTEM PRIVATE
${PDAL_ADD_PLUGIN_SYSTEM_INCLUDES})
endif()
target_link_libraries(${${_name}}
PRIVATE
${PDAL_BASE_LIB_NAME}
Expand Down Expand Up @@ -172,7 +176,7 @@ endmacro(PDAL_ADD_PLUGIN)
macro(PDAL_ADD_TEST _name)
set(options)
set(oneValueArgs)
set(multiValueArgs FILES LINK_WITH INCLUDES)
set(multiValueArgs FILES LINK_WITH INCLUDES SYSTEM_INCLUDES)
cmake_parse_arguments(PDAL_ADD_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if (WIN32)
list(APPEND ${PDAL_ADD_TEST_FILES} ${PDAL_TARGET_OBJECTS})
Expand All @@ -188,6 +192,10 @@ macro(PDAL_ADD_TEST _name)
${PROJECT_SOURCE_DIR}/test/unit
${PROJECT_BINARY_DIR}/test/unit
${PROJECT_BINARY_DIR}/include)
if (PDAL_ADD_TEST_SYSTEM_INCLUDES)
target_include_directories(${_name} SYSTEM PRIVATE
${PDAL_ADD_TEST_SYSTEM_INCLUDES})
endif()
set_property(TARGET ${_name} PROPERTY FOLDER "Tests")
target_link_libraries(${_name}
PRIVATE
Expand Down
32 changes: 17 additions & 15 deletions cmake/modules/FindNumPy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,30 @@
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

IF (NUMPY_INCLUDE_DIR)
SET(NUMPY_FIND_QUIETLY TRUE)
endif (NUMPY_INCLUDE_DIR)
if (PYTHON_NUMPY_INCLUDE_DIR)
set(PYTHON_NUMPY_FIND_QUIETLY TRUE)
endif()

# To set the variables PYTHON_EXECUTABLE
FIND_PACKAGE(PythonInterp QUIET REQUIRED)
FIND_PACKAGE(PythonLibs QUIET REQUIRED)
if (NOT PYTHON_EXECUTABLE)
message(FATAL_ERROR "\"PYTHON_EXECUTABLE\" varabile not set before FindNumPy.cmake was run.")
endif()

# Look for the include path
# WARNING: The variable PYTHON_EXECUTABLE is defined by the script FindPythonInterp.cmake
EXECUTE_PROCESS(COMMAND "${PYTHON_EXECUTABLE}" -c "import numpy; print (numpy.get_include()); print (numpy.version.version)"
execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import numpy; print (numpy.get_include()); print (numpy.version.version)"
OUTPUT_VARIABLE NUMPY_OUTPUT
ERROR_VARIABLE NUMPY_ERROR)
message(STATUS "Numpy output: ${NUMPY_OUTPUT}")
IF(NOT NUMPY_ERROR)
if (NOT NUMPY_ERROR)
STRING(REPLACE "\n" ";" NUMPY_OUTPUT ${NUMPY_OUTPUT})
LIST(GET NUMPY_OUTPUT 0 NUMPY_INCLUDE_DIR)
LIST(GET NUMPY_OUTPUT 1 NUMPY_VERSION)
ENDIF(NOT NUMPY_ERROR)
LIST(GET NUMPY_OUTPUT 0 PYTHON_NUMPY_INCLUDE_DIRS)
LIST(GET NUMPY_OUTPUT 1 PYTHON_NUMPY_VERSION)
endif(NOT NUMPY_ERROR)

INCLUDE(FindPackageHandleStandardArgs)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NumPy DEFAULT_MSG PYTHON_NUMPY_VERSION PYTHON_NUMPY_INCLUDE_DIRS)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(NumPy DEFAULT_MSG NUMPY_VERSION NUMPY_INCLUDE_DIR)
set(PYTHON_NUMPY_INCLUDE_DIR ${PYTHON_NUMPY_INCLUDE_DIRS}
CACHE PATH "Location of NumPy include files.")
message("NUMPY include dir = ${PYTHON_NUMPY_INCLUDE_DIR}")
mark_as_advanced(PYTHON_NUMPY_INCLUDE_DIR)

MARK_AS_ADVANCED(NUMPY_INCLUDE_DIR)
50 changes: 34 additions & 16 deletions cmake/python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,40 @@
# Python
#

# Try to find version 3. If not, we fall back to version 2.
find_package(PythonInterp QUIET 3)
find_package(PythonInterp QUIET 2.7)

# Looking for PythonLibs will use the version of the intpreter found to
# tell it which version of the libraries to use.
find_package(PythonLibs QUIET)
#
# Version 3.12 has shiny new FindPython2 and FindPython3 scripts
#
if (NOT (CMAKE_VERSION VERSION_LESS "3.12.0"))
find_package(Python3 COMPONENTS Interpreter Development NumPy)
if (NOT Python3_FOUND)
find_package(Python2 2.7 REQUIRED EXACT
COMPONENTS Interpreter Development NumPy)

set_package_properties(PythonInterp PROPERTIES TYPE REQUIRED)
if(PYTHONLIBS_FOUND)
set(CMAKE_REQUIRED_LIBRARIES "${PYTHON_LIBRARY}")
include_directories(SYSTEM ${PYTHON_INCLUDE_DIR})
add_definitions(-DHAVE_PYTHON=1)
# Since we've required 2.7, these should all be valid
set(PYTHON_LIBRARY ${Python2_LIBRARIES}
CACHE FILEPATH "Python library")
set(PYTHON_INCLUDE_DIR ${Python2_INCLUDE_DIRS}
CACHE PATH "Location of Python include files")
set(PYTHON_NUMPY_INCLUDE_DIR ${Python2_NumPy_INCLUDE_DIRS}
CACHE PATH "Location of NumPy include files.")
else()
set(PYTHON_LIBRARY ${Python3_LIBRARIES}
CACHE FILEPATH "Python library")
set(PYTHON_INCLUDE_DIR ${Python3_INCLUDE_DIRS}
CACHE PATH "Location of Python include files.")
set(PYTHON_NUMPY_INCLUDE_DIR ${Python3_NumPy_INCLUDE_DIRS}
CACHE PATH "Location of NumPy include files.")
endif()
set(PDAL_HAVE_PYTHON 1)
set(PDAL_PYTHON_VERSION_STRING "${PYTHONLIBS_VERSION_STRING}" CACHE STRING "PDAL Python version" FORCE)

find_package(NumPy QUIET 1.5 REQUIRED)
include_directories(SYSTEM ${NUMPY_INCLUDE_DIR})
else()
find_package(PythonInterp 3 QUIET)
find_package(PythonLibs 3 QUIET)
if ((NOT PYTHONINTERP_FOUND) OR (NOT PYTHONLIBS_FOUND))
unset(PYTHON_EXECUTABLE CACHE)
find_package(PythonInterp 2.7 EXACT REQUIRED)
find_package(PythonLibs 2.7 EXACT REQUIRED)
endif()
set(PDAL_HAVE_PYTHON 1)
find_package(NumPy 1.5 REQUIRED)
endif()
set(PYTHON_ALL_INCLUDE_DIRS ${PYTHON_INCLUDE_DIR} ${PYTHON_NUMPY_INCLUDE_DIR})
5 changes: 4 additions & 1 deletion plugins/python/filters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ PDAL_ADD_PLUGIN(python_libname filter python
${PDAL_JSONCPP_LIB_NAME}
${CMAKE_DL_LIBS}
INCLUDES
${PYTHON_INCLUDE_DIR}
${PDAL_JSONCPP_INCLUDE_DIR}
SYSTEM_INCLUDES
${PYTHON_ALL_INCLUDE_DIRS}
)

if (WITH_TESTS)
Expand All @@ -22,5 +23,7 @@ if (WITH_TESTS)
../test/PythonFilterTest.cpp
LINK_WITH
${python_libname} ${PYTHON_LIBRARY}
SYSTEM_INCLUDES
${PYTHON_ALL_INCLUDE_DIRS}
)
endif()
9 changes: 6 additions & 3 deletions plugins/python/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ PDAL_ADD_PLUGIN(numpy_reader reader numpy
LINK_WITH
${PYTHON_LIBRARY}
${CMAKE_DL_LIBS}
INCLUDES
${PYTHON_INCLUDE_DIR}
SYSTEM_INCLUDES
${PYTHON_ALL_INCLUDE_DIRS}
)

# Install headers so Python extension
Expand All @@ -24,5 +24,8 @@ if (WITH_TESTS)
FILES
../test/NumpyReaderTest.cpp
LINK_WITH
${numpy_reader} ${PYTHON_LIBRARY})
${numpy_reader} ${PYTHON_LIBRARY}
SYSTEM_INCLUDES
${PYTHON_ALL_INCLUDE_DIRS}
)
endif()
28 changes: 0 additions & 28 deletions plugins/python/plang/CMakeLists.txt

This file was deleted.

1 change: 1 addition & 0 deletions scripts/appveyor/conda/recipe/bld.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cmake -G "Ninja" ^
-DCMAKE_BUILD_TYPE:STRING=Release ^
-DCMAKE_LIBRARY_PATH="%LIBRARY_LIB%" ^
-DCMAKE_INCLUDE_PATH="%INCLUDE_INC%" \^
-DPython3_ROOT_DIR:FILEPATH="%LIBRARY_PREFIX%" ^
-DBUILD_PLUGIN_GREYHOUND=ON ^
-DBUILD_PLUGIN_PCL=ON ^
-DBUILD_PLUGIN_PYTHON=ON ^
Expand Down
3 changes: 2 additions & 1 deletion scripts/appveyor/test/build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ cmake -G "Ninja" ^
-DPDAL_PLUGIN_INSTALL_PATH:FILEPATH=%PDAL_PLUGIN_INSTALL_PATH% ^
-DWITH_TESTS=%PDAL_BUILD_TESTS% ^
-DCMAKE_VERBOSE_MAKEFILE=%CMAKE_VERBOSE_MAKEFILE% ^
-DCMAKE_LIBRARY_PATH:FILEPATH="=%CONDA_ROOT%/Library/lib" ^
-DCMAKE_LIBRARY_PATH:FILEPATH="%CONDA_ROOT%/Library/lib" ^
-DCMAKE_INCLUDE_PATH:FILEPATH="%CONDA_ROOT%/Library/include" ^
-DPython3_ROOT_DIR:FILEPATH="%CONDA_PREFIX%" ^
-DBUILD_PLUGIN_CPD=OFF ^
-DBUILD_PLUGIN_GREYHOUND=ON ^
-DBUILD_PLUGIN_ICEBRIDGE=ON ^
Expand Down

0 comments on commit 2f75651

Please sign in to comment.