From 0be81316066dfa7d075d15d95628e10405e7641a Mon Sep 17 00:00:00 2001 From: Nicholas O'Connor Date: Thu, 23 Mar 2017 14:23:22 -0700 Subject: [PATCH] cmake checks for cogapp module now thanks to a module I found on the Internet --- CMakeLists.txt | 6 ++++++ cmake/Modules/FindPythonModule.cmake | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 cmake/Modules/FindPythonModule.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e3b04d4..3c53543 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,9 @@ project(cellar CXX) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# local cmake modules +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/Modules) + # for installation rules, from CMake wiki SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/cellar") @@ -11,6 +14,9 @@ SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/cellar") SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) find_package(PythonInterp) +find_package(PythonModule) +find_python_module(cogapp REQUIRED) + find_package(Boost 1.63 REQUIRED COMPONENTS filesystem) find_package(PkgConfig) diff --git a/cmake/Modules/FindPythonModule.cmake b/cmake/Modules/FindPythonModule.cmake new file mode 100644 index 0000000..a024118 --- /dev/null +++ b/cmake/Modules/FindPythonModule.cmake @@ -0,0 +1,25 @@ +# 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) +