From 5aefe885ab3fe8e3c9010d1663acd80553f1d662 Mon Sep 17 00:00:00 2001 From: Automated MSK Jenkins User <msk_jenkins@msk-ubuntu1604.desy.de> Date: Fri, 31 Jan 2020 10:51:25 +0000 Subject: [PATCH] automatic merge of project-template --- cmake/Modules/FindMako.cmake | 84 ++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 cmake/Modules/FindMako.cmake diff --git a/cmake/Modules/FindMako.cmake b/cmake/Modules/FindMako.cmake new file mode 100644 index 00000000..c2a85da7 --- /dev/null +++ b/cmake/Modules/FindMako.cmake @@ -0,0 +1,84 @@ +# First check for python executable +if(NOT PYTHON_EXECUTABLE) + find_program(PYTHON_EXECUTABLE python) + if(NOT PYTHON_EXECUTABLE) + message(FATAL_ERROR "Please check for python before searching for mako") + endif() +endif() +# If mako was installed by this process previously, check that it is still there +if(MAKO_EXTERNAL_INSTALL) + execute_process( + COMMAND ${PYTHON_EXECUTABLE} "-c \"import mako\"" + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/external/python + ERROR_VARIABLE DUMMY + OUTPUT_VARIABLE DUMMY + RESULT_VARIABLE MAKO_STILL_THERE + ) + if(MAKO_STILL_THERE) + return() + endif() +endif() +# If mako is not found ... +if(NOT FOUND_MAKO) + # Then look for it by importing it + execute_process( + COMMAND ${PYTHON_EXECUTABLE} -c "import mako" + ERROR_VARIABLE DUMMY + OUTPUT_VARIABLE DUMMY + RESULT_VARIABLE FOUND_MAKO + ) + if(FOUND_MAKO EQUAL 0) + message(STATUS "[Mako] Found") + set(FOUND_MAKO TRUE CACHE INTERNAL "Found mako python package") + set(MAKO_EXTERNAL_INSTALL FALSE CACHE INTERNAL "Manual install of mako") + return() + endif() +else() + # If mako already found then continue + # We have checked that it was still there, if we installed it + return() +endif() + +message(STATUS "[Mako] Not found") +# Now try and install mako using pip +if(NOT PIP_EXECUTABLE) + find_program(PIP_EXECUTABLE pip) +endif() +if(NOT PIP_EXECUTABLE) + message(FATAL_ERROR "cannot install package without pip") +else() + message(STATUS "[pip] found: ${PIP_EXECUTABLE}") +endif() +# We install it in the build directory +execute_process( + COMMAND ${PIP_EXECUTABLE} install mako + --install-option=--install-purelib=${PROJECT_BINARY_DIR}/external/python + --install-option=--install-scripts=${PROJECT_BINARY_DIR}/external/python + --install-option=--prefix=${PROJECT_BINARY_DIR}/external/python + OUTPUT_VARIABLE PIP_OUTPUT + ERROR_VARIABLE PIP_ERROR + RESULT_VARIABLE PIP_INSTALLATION_WORKED +) +if(NOT PIP_INSTALLATION_WORKED EQUAL 0) + message(STATUS "${PIP_OUTPUT}") + message(STATUS "${PIP_ERROR}") + message(FATAL_ERROR "Could not install mako. Please see error message above") +else() + message(STATUS "[Mako] installed in ${PROJECT_BINARY_DIR}/external/python") +endif() + +execute_process( + COMMAND ${PYTHON_EXECUTABLE} -c "import mako" + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/external/python + ERROR_VARIABLE DUMMY + OUTPUT_VARIABLE DUMMY + RESULT_VARIABLE FOUND_MAKO +) +if(FOUND_MAKO EQUAL 0) + message(STATUS "[Mako] now available in build directory") + set(FOUND_MAKO TRUE CACHE INTERNAL "Found mako python package") + set(MAKO_EXTERNAL_INSTALL TRUE CACHE INTERNAL "Manual install of mako") + return() +else() + message(FATAL_ERROR "Could not install mako") +endif() -- GitLab