Commit ad5ad185 authored by Roel Aaij's avatar Roel Aaij
Browse files

Fix build with system packages.

parent 5150b85b
......@@ -156,23 +156,12 @@ if(ENABLE_PYTHON)
endif()
# pybind11 headers
if("${PYBIND11_INCLUDE_DIR}" STREQUAL "")
find_package(pybind11 QUIET)
if (NOT pybind11_FOUND)
message(FAILURE "PYBIND11_INCLUDE_DIR is not set and pybind11 cannot be found")
else()
target_include_directories(k40gen PRIVATE ${PYBIND11_INCLUDE_DIR})
endif()
else()
endif()
find_package(pybind11 REQUIRED)
target_include_directories(k40gen PRIVATE ${pybind11_INCLUDE_DIRS})
# numpy headers
if("${NUMPY_INCLUDE_DIR}" STREQUAL "")
message(STATUS "Assuming numpy headers are installed in python site packages location")
target_include_directories(k40gen PRIVATE ${PYTHON_SITE_PACKAGES}/numpy/core/include)
else()
target_include_directories(k40gen PRIVATE ${NUMPY_INCLUDE_DIR})
endif()
find_package(NumPy REQUIRED)
target_include_directories(k40gen PRIVATE ${NUMPY_INCLUDE_DIRS})
endif()
if(ENABLE_TESTS)
......
......@@ -40,51 +40,58 @@
#============================================================================
# Finding Pybind11 involves calling the Python interpreter
if(Pybind11_FIND_REQUIRED)
find_package(PythonInterp REQUIRED)
find_package(pybind11 CONFIG QUIET)
if (pybind11_FOUND)
set(PYBIND11_FOUND TRUE)
else()
if(Pybind11_FIND_REQUIRED)
find_package(PythonInterp REQUIRED)
else()
find_package(PythonInterp)
endif()
endif()
if(NOT PYTHONINTERP_FOUND)
if(NOT PYTHONINTERP_FOUND)
set(PYBIND11_FOUND FALSE)
endif()
endif()
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import pybind11 as pb; print(pb.__version__); print(pb.get_include());"
RESULT_VARIABLE _PYBIND11_SEARCH_SUCCESS
OUTPUT_VARIABLE _PYBIND11_VALUES
ERROR_VARIABLE _PYBIND11_ERROR_VALUE
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT _PYBIND11_SEARCH_SUCCESS MATCHES 0)
if(NOT _PYBIND11_SEARCH_SUCCESS MATCHES 0)
if(Pybind11_FIND_REQUIRED)
message(FATAL_ERROR
"pybind11 import failure:\n${_PYBIND11_ERROR_VALUE}")
message(FATAL_ERROR
"pybind11 import failure:\n${_PYBIND11_ERROR_VALUE}")
endif()
set(PYBIND11_FOUND FALSE)
endif()
# Convert the process output into a list
string(REGEX REPLACE ";" "\\\\;" _PYBIND11_VALUES ${_PYBIND11_VALUES})
string(REGEX REPLACE "\n" ";" _PYBIND11_VALUES ${_PYBIND11_VALUES})
list(GET _PYBIND11_VALUES 0 PYBIND11_VERSION)
list(GET _PYBIND11_VALUES 1 PYBIND11_INCLUDE_DIRS)
else()
set(PYBIND11_FOUND TRUE)
endif()
# Make sure all directory separators are '/'
string(REGEX REPLACE "\\\\" "/" PYBIND11_INCLUDE_DIRS ${PYBIND11_INCLUDE_DIRS})
if (PYBIND11_FOUND)
# Convert the process output into a list
string(REGEX REPLACE ";" "\\\\;" _PYBIND11_VALUES ${_PYBIND11_VALUES})
string(REGEX REPLACE "\n" ";" _PYBIND11_VALUES ${_PYBIND11_VALUES})
list(GET _PYBIND11_VALUES 0 PYBIND11_VERSION)
list(GET _PYBIND11_VALUES 1 PYBIND11_INCLUDE_DIRS)
# Get the major and minor version numbers
string(REGEX REPLACE "\\." ";" _PYBIND11_VERSION_LIST ${PYBIND11_VERSION})
list(GET _PYBIND11_VERSION_LIST 0 PYBIND11_VERSION_MAJOR)
list(GET _PYBIND11_VERSION_LIST 1 PYBIND11_VERSION_MINOR)
list(GET _PYBIND11_VERSION_LIST 2 PYBIND11_VERSION_PATCH)
string(REGEX MATCH "[0-9]*" PYBIND11_VERSION_PATCH ${PYBIND11_VERSION_PATCH})
math(EXPR PYBIND11_VERSION_DECIMAL
"(${PYBIND11_VERSION_MAJOR} * 10000) + (${PYBIND11_VERSION_MINOR} * 100) + ${PYBIND11_VERSION_PATCH}")
# Make sure all directory separators are '/'
string(REGEX REPLACE "\\\\" "/" PYBIND11_INCLUDE_DIRS ${PYBIND11_INCLUDE_DIRS})
find_package_message(PYBIND11
"Found Pybind11: version \"${PYBIND11_VERSION}\" ${PYBIND11_INCLUDE_DIRS}"
"${PYBIND11_INCLUDE_DIRS}${PYBIND11_VERSION}")
# Get the major and minor version numbers
string(REGEX REPLACE "\\." ";" _PYBIND11_VERSION_LIST ${PYBIND11_VERSION})
list(GET _PYBIND11_VERSION_LIST 0 PYBIND11_VERSION_MAJOR)
list(GET _PYBIND11_VERSION_LIST 1 PYBIND11_VERSION_MINOR)
list(GET _PYBIND11_VERSION_LIST 2 PYBIND11_VERSION_PATCH)
string(REGEX MATCH "[0-9]*" PYBIND11_VERSION_PATCH ${PYBIND11_VERSION_PATCH})
math(EXPR PYBIND11_VERSION_DECIMAL
"(${PYBIND11_VERSION_MAJOR} * 10000) + (${PYBIND11_VERSION_MINOR} * 100) + ${PYBIND11_VERSION_PATCH}")
set(PYBIND11_FOUND TRUE)
find_package_message(PYBIND11
"Found Pybind11: version \"${PYBIND11_VERSION}\" ${PYBIND11_INCLUDE_DIRS}"
"${PYBIND11_INCLUDE_DIRS}${PYBIND11_VERSION}")
endif()
endif()
......@@ -6,8 +6,6 @@ import os
import re
import platform
import subprocess
import numpy as np
import pybind11
__version__ = '0.0.1'
......@@ -41,8 +39,6 @@ class CMakeBuild(build_ext):
os.path.dirname(self.get_ext_fullpath(ext.name)))
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
'-DPYTHON_EXECUTABLE=' + sys.executable]
cmake_args += ['-DNUMPY_INCLUDE_DIR=' + np.get_include()]
cmake_args += ['-DPYBIND11_INCLUDE_DIR=' + pybind11.get_include()]
cfg = 'Debug' if self.debug else 'Release'
build_args = ['--config', cfg]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment