12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- function(find_python_module module)
-
- string(TOUPPER ${module} module_upper)
- string(TOLOWER ${module} module_lower)
- unset(${module_upper}_VERSION)
-
-
-
-
- if(PYTHONINTERP_FOUND)
- if (NOT ${module} STREQUAL "__future__")
- execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
- "import ${module_lower} as n; print(n.__version__);"
- RESULT_VARIABLE __result
- OUTPUT_VARIABLE __output
- ERROR_QUIET
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- if(__result MATCHES 0)
- string(REGEX REPLACE ";" "\\\\;" __values ${__output})
- string(REGEX REPLACE "\r?\n" ";" __values ${__values})
- list(GET __values 0 ${module_upper}_VERSION)
- string(REGEX MATCH "^([0-9])+\\.([0-9])+\\.([0-9])+" __ver_check "${${module_upper}_VERSION}")
- if(NOT "${__ver_check}" STREQUAL "")
- set(${module_upper}_VERSION_MAJOR ${CMAKE_MATCH_1})
- set(${module_upper}_VERSION_MINOR ${CMAKE_MATCH_2})
- set(${module_upper}_VERSION_PATCH ${CMAKE_MATCH_3})
- math(EXPR ${module_upper}_VERSION_DECIMAL
- "(${CMAKE_MATCH_1} * 10000) + (${CMAKE_MATCH_2} * 100) + ${CMAKE_MATCH_3}")
- else()
- unset(${module_upper}_VERSION)
- message(STATUS "Requested ${module_lower} version, but got instead:\n${__output}\n")
- endif()
- find_package_handle_standard_args(${module_upper}
- FOUND_VAR ${module_upper}_FOUND
- REQUIRED_VARS ${module_upper}_VERSION
- VERSION_VAR ${module_upper}_VERSION)
- endif()
- else()
- execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
- "import ${module_lower} as n"
- RESULT_VARIABLE __result
- OUTPUT_VARIABLE __output
- ERROR_QUIET
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- if(NOT __result)
- set(${module_upper}_FOUND ON)
- endif()
- message(STATUS "Found Python __FUTURE__")
- endif()
- else()
- message(STATUS "Python interpreter not found. To find ${module} you need the Python interpreter.")
- endif()
-
- if(${module_upper}_FOUND)
- set(${module_upper}_FOUND ON PARENT_SCOPE)
- if (NOT ${module} STREQUAL "__future__")
- set(${module_upper}_VERSION ${${module_upper}_VERSION} PARENT_SCOPE)
- set(${module_upper}_VERSION_MAJOR ${${module_upper}_VERSION_MAJOR} PARENT_SCOPE)
- set(${module_upper}_VERSION_MINOR ${${module_upper}_VERSION_MINOR} PARENT_SCOPE)
- set(${module_upper}_VERSION_PATCH ${${module_upper}_VERSION_PATCH} PARENT_SCOPE)
- set(${module_upper}_VERSION_DECIMAL ${${module_upper}_VERSION_DECIMAL} PARENT_SCOPE)
- endif()
- endif()
-
- osqp_clear_vars(__result __output __values __ver_check)
- endfunction(find_python_module)
|