Skip to content
Snippets Groups Projects

Adding option to automatically installation

Merged Christoph Alt requested to merge ob28imeq/pystencils-sfg:cmake_setup into master
All threads resolved!
Files
2
@@ -3,6 +3,9 @@ Find-Module for pystencils-sfg.
# Setting the Python interpreter
If the cache CODEGEN_PRIVATE_VENV is true, it will try to create to a own python venv and install the requirements from `CODEGEN_VENV_REQUIREMENTS`.
If this file does not exists it will download pystencilssfg and pystencils from `PystencilsSfg_URL` and `Pystencils_URL`
If the cache entry PystencilsSfg_PYTHON_INTERPRETER is set, e.g. via the commandline
(`-DPystencilsSfg_PYTHON_INTERPRETER=<...>`), its value be taken as the Python interpreter
used to find and run pystencils-sfg.
@@ -14,11 +17,66 @@ If none of these is set, a Python interpreter will be selected using the `FindPy
#]]
set(CODEGEN_PRIVATE_VENV ON
CACHE BOOL
"Create a private virtual Python environment inside the build tree for code generation"
)
if (DEFINED CACHE{PystencilsSfg_PYTHON_INTERPRETER})
set( CODEGEN_PRIVATE_VENV OFF)
elseif(DEFINED PystencilsSfg_PYTHON_PATH)
set( CODEGEN_PRIVATE_VENV OFF)
endif()
if(NOT DEFINED CACHE{PystencilsSfg_PYTHON_INTERPRETER})
# The Python interpreter cache variable is not set externally, so...
if(DEFINED PystencilsSfg_PYTHON_PATH)
# ... either initialize it from the hint variable ...
set( _sfg_cache_python_init ${PystencilsSfg_PYTHON_PATH} )
elseif (CODEGEN_PRIVATE_VENV)
# ... or create an own venv ...
set(CODEGEN_VENV_PATH ${CMAKE_CURRENT_BINARY_DIR}/codegen-venv CACHE PATH "Location of the virtual environment used for code generation")
set(_venv_python_exe ${CODEGEN_VENV_PATH}/bin/python)
find_package( Python COMPONENTS Interpreter REQUIRED )
if(NOT _sfg_private_venv_done)
message( STATUS "Setting up Python virtual environment at ${CODEGEN_VENV_PATH}" )
# Create the venv and register its interpreter with pystencils-sfg
if(NOT EXISTS ${CODEGEN_VENV_PATH})
execute_process(
COMMAND ${Python_EXECUTABLE} -m venv ${CODEGEN_VENV_PATH}
)
endif()
set(CODEGEN_VENV_REQUIREMENTS ${PROJECT_SOURCE_DIR}/requirements.txt CACHE FILEPATH "Location of the requirements installed in the virtual environment used for code generation")
if (EXISTS ${CODEGEN_VENV_REQUIREMENTS})
message( STATUS "Installing required Python packages from ${CODEGEN_VENV_REQUIREMENTS}" )
execute_process( COMMAND ${_venv_python_exe} -m pip install -r ${CODEGEN_VENV_REQUIREMENTS} OUTPUT_QUIET)
else()
set(Pystencils_URL "git+https://i10git.cs.fau.de/pycodegen/pystencils.git@v2.0-dev" CACHE STRING "Location of pystencils to installed in the virtual environment used for code generation")
set(PystencilsSfg_URL "git+https://i10git.cs.fau.de/pycodegen/pystencils-sfg.git" CACHE STRING "Location of pystencils-sfg to installed in the virtual environment used for code generation")
message( STATUS "Installing required Pystencils from ${Pystencils_URL}" )
execute_process(
COMMAND ${_venv_python_exe} -m pip install "${Pystencils_URL}"
OUTPUT_QUIET
)
message( STATUS "Installing required Pystencils-sfg from ${PystencilsSfg_URL}" )
execute_process(
COMMAND ${_venv_python_exe} -m pip install "${PystencilsSfg_URL}"
OUTPUT_QUIET
)
endif()
set( _sfg_private_venv_done TRUE CACHE BOOL "" )
mark_as_advanced(_sfg_private_venv_done)
endif()
set(_sfg_cache_python_init ${_venv_python_exe})
else()
# ... or, if that is also unset, use the system Python
find_package( Python COMPONENTS Interpreter REQUIRED )
@@ -48,7 +106,7 @@ endif()
if(${PystencilsSfg_FOUND})
message( STATUS "Found pystencils Source File Generator (Version ${PystencilsSfg_VERSION})")
message( STATUS "Using Python interpreter ${PystencilsSfg_PYTHON_INTERPRETER} for SFG generator scripts.")
execute_process(COMMAND ${PystencilsSfg_PYTHON_INTERPRETER} -m pystencilssfg cmake modulepath --no-newline
OUTPUT_VARIABLE _PystencilsSfg_CMAKE_MODULE_PATH)