From 0a0bfa56d0d0df5917bb3858ec614d8f37d32309 Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Sat, 23 Jul 2011 16:34:25 -0700 Subject: [PATCH] Add Python check in cmake process to allow optional resource.dat creation. --- Sources/Plasma/Apps/plClient/CMakeLists.txt | 16 +++++++++++- cmake/FindPythonModule.cmake | 29 +++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 cmake/FindPythonModule.cmake diff --git a/Sources/Plasma/Apps/plClient/CMakeLists.txt b/Sources/Plasma/Apps/plClient/CMakeLists.txt index fd4ccd22..6ae04615 100644 --- a/Sources/Plasma/Apps/plClient/CMakeLists.txt +++ b/Sources/Plasma/Apps/plClient/CMakeLists.txt @@ -15,6 +15,18 @@ include_directories(${OPENSSL_INCLUDE_DIR}) include_directories(${PYTHON_INCLUDE_DIR}) include_directories(${CURL_INCLUDE_DIR}) +# Test for Python Interpreter, which will be used for extra build scripts if available +find_package(PythonInterp) +if(PYTHONINTERP_FOUND) + include(FindPythonModule) + # Test for Python modules needed to build resource.dat + find_python_module(rsvg) + find_python_module(Image) + if((DEFINED PY_RSVG) AND (DEFINED PY_IMAGE)) + set(BUILD_RESOURCE_DAT ON) + endif((DEFINED PY_RSVG) AND (DEFINED PY_IMAGE)) +endif(PYTHONINTERP_FOUND) + add_subdirectory(external) set(plClient_HEADERS @@ -51,7 +63,9 @@ set(plClient_RESOURCES add_executable(plClient WIN32 ${plClient_SOURCES} ${plClient_HEADERS} ${plClient_TEXT} ${plClient_RESOURCES}) -add_dependencies(plClient externalResources) +if(BUILD_RESOURCE_DAT) + add_dependencies(plClient externalResources) +endif(BUILD_RESOURCE_DAT) if(PLASMA_EXTERNAL_RELEASE) set_target_properties(plClient PROPERTIES OUTPUT_NAME "UruExplorer") diff --git a/cmake/FindPythonModule.cmake b/cmake/FindPythonModule.cmake new file mode 100644 index 00000000..d17cefb1 --- /dev/null +++ b/cmake/FindPythonModule.cmake @@ -0,0 +1,29 @@ +# Test for the existence of a specified Python Module +# +# From http://ompl.hg.sourceforge.net/hgweb/ompl/ompl/file/tip/CMakeModules/FindPython.cmake + + +if(DEFINED PYTHON_EXECUTABLE) + +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) + +endif(DEFINED PYTHON_EXECUTABLE)