diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 41e3a70865bdfbd60e238b7911ce99a4c977ec18..c430eab4dac8e174f368d3cbfffe350ceaa83b8f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -71,3 +71,12 @@ pages: - docker only: - master@pycodegen/pystencils-sfg + +cmake-standalone: + stage: deploy + needs: [] + script: + - echo "Publishing Cmake standalone" + artifacts: + paths: + - standalone diff --git a/src/pystencilssfg/cmake/FindPystencilsSfg.cmake b/src/pystencilssfg/cmake/FindPystencilsSfg.cmake index 20a3fd596d99cf2db18e346609b8060bf86d32bc..5efae7ad3b0b415f1655400ad762fe22bc5e9b47 100644 --- a/src/pystencilssfg/cmake/FindPystencilsSfg.cmake +++ b/src/pystencilssfg/cmake/FindPystencilsSfg.cmake @@ -48,7 +48,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) diff --git a/standalone/CMakeLists.txt b/standalone/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8963be33c93d0b3b350bf24d66c406162d6d43c8 --- /dev/null +++ b/standalone/CMakeLists.txt @@ -0,0 +1,73 @@ +cmake_minimum_required( VERSION 3.24 ) +project(PystencilsSfg_Standalone) + +if (DEFINED CACHE{PystencilsSfg_PYTHON_INTERPRETER}) + set( _use_venv_init OFF) +elseif(DEFINED PystencilsSfg_PYTHON_PATH) + set( _use_venv_init OFF) +else() + set( _use_venv_init ON ) +endif() + +set(CODEGEN_PRIVATE_VENV ${_use_venv_init} + CACHE BOOL + "Create a private virtual Python environment inside the build tree for code generation" +) + +function(codegen_venv_install) + if(NOT CODEGEN_PRIVATE_VENV) + return() + endif() + + if(NOT _sfg_private_venv_done) + message( FATAL_ERROR "The private virtual environment for code generation was not initialized yet" ) + endif() + + execute_process( + COMMAND ${PystencilsSfg_PYTHON_INTERPRETER} -m pip install ${ARGV} + ) +endfunction() + + +if (CODEGEN_PRIVATE_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) + set(CODEGEN_VENV_PYTHON ${_venv_python_exe}) + + 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() + message( WARNING "Could not find ${CODEGEN_VENV_REQUIREMENTS}" ) + 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}) + set(PystencilsSfg_PYTHON_INTERPRETER ${_sfg_cache_python_init} CACHE PATH "Path to the Python executable used to run pystencils-sfg") +endif() + +# get the find pystencils-sfg file +execute_process( + COMMAND ${PystencilsSfg_PYTHON_INTERPRETER} -m pystencilssfg cmake make-find-module + WORKING_DIRECTORY ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR} +) +# renaming it +file(RENAME ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/FindPystencilsSfg.cmake ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/pystencilssfg-config.cmake) + +# Find it +find_package( PystencilsSfg REQUIRED ) diff --git a/standalone/requirements.txt b/standalone/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..82b06ee7fc62937816f4a585427bbaef42e1f7ac --- /dev/null +++ b/standalone/requirements.txt @@ -0,0 +1,5 @@ +py-cpuinfo +# pystencils 2.0 Development Branch +git+https://i10git.cs.fau.de/pycodegen/pystencils.git@4876f0b774d38fe7644f2b64f80f1291ffa0fa08 +# pystencils-sfg +git+https://i10git.cs.fau.de/pycodegen/pystencils-sfg.git@dcb77258670abe5bc87f2bd80761594eb304cb90