Skip to content
Permalink
Browse files

Add custom CMake function to check for Python module

  • Loading branch information...
geographika committed Nov 25, 2018
1 parent 4bfd0c5 commit 5a8ad7f34f7a24f02371d693950927d61b9df4dc
Showing with 29 additions and 0 deletions.
  1. +4 −0 CMakeLists.txt
  2. +24 −0 cmake/FindPythonModule.cmake
  3. +1 −0 mapscript/python/CMakeLists.txt
@@ -33,6 +33,10 @@ endif(MapServer_IS_DEV_VERSION)
MATH(EXPR MapServer_VERSION_NUM "${MapServer_VERSION_MAJOR}*10000+${MapServer_VERSION_MINOR}*100+${MapServer_VERSION_REVISION}")

SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})

# Add custom function to check Python modules are installed
include(FindPythonModule)

if (APPLE)
set(CMAKE_FIND_FRAMEWORK "LAST")
endif (APPLE)
@@ -0,0 +1,24 @@
# Find if a Python module is installed
# Found at http://www.cmake.org/pipermail/cmake/2011-January/041666.html
# To use do: find_python_module(PyQt4 REQUIRED)
function(find_python_module module)
string(TOUPPER ${module} module_upper)
if(NOT PY_${module_upper})
if(ARGC GREATER 1 AND ARGV1 STREQUAL "REQUIRED")
set(${module}_FIND_REQUIRED TRUE)
endif()
# A module's location is usually a directory, but for binary modules
# it's a .so file.
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import re, ${module}; print(re.compile('/__init__.py.*').sub('',${module}.__file__))"
RESULT_VARIABLE _${module}_status
OUTPUT_VARIABLE _${module}_location
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT _${module}_status)
set(PY_${module_upper} ${_${module}_location} CACHE STRING
"Location of Python module ${module}")
endif(NOT _${module}_status)
endif(NOT PY_${module_upper})
find_package_handle_standard_args(PY_${module} DEFAULT_MSG PY_${module_upper})
endfunction(find_python_module)
@@ -1,6 +1,7 @@
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(PythonInterp)
find_python_module(setuptools REQUIRED)

# Python library/header finding doesn't seem to honor the python
# interpreter that was found beforehand, and defaults to the system

0 comments on commit 5a8ad7f

Please sign in to comment.
You can’t perform that action at this time.