From e82f66663c2132bf78bd1e8f2c7b19f11c0d74ab Mon Sep 17 00:00:00 2001 From: Kei Okada Date: Thu, 8 Feb 2018 20:49:09 +0900 Subject: [PATCH] add catkin-pip-package-virtualenv.cmake --- CMakeLists.txt | 1 + cmake/catkin-pip-package-virtualenv.cmake.in | 68 ++++++++++++++++++++ cmake/catkin-pip-package.cmake.in | 4 ++ cmake/catkin-pip.cmake.in | 6 ++ 4 files changed, 79 insertions(+) create mode 100644 cmake/catkin-pip-package-virtualenv.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 050584f..c4caf72 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,7 @@ catkin_package( catkin-pip.cmake catkin-pip-runcmd.cmake catkin-pip-package.cmake + catkin-pip-package-virtualenv.cmake catkin-pip-prefix.cmake catkin-pip-requirements.cmake pytest.cmake diff --git a/cmake/catkin-pip-package-virtualenv.cmake.in b/cmake/catkin-pip-package-virtualenv.cmake.in new file mode 100644 index 0000000..dc0a28d --- /dev/null +++ b/cmake/catkin-pip-package-virtualenv.cmake.in @@ -0,0 +1,68 @@ +if ( CMAKE_BACKWARDS_COMPATIBILITY LESS 2.8 ) + message ( FATAL_ERROR " CMAKE MINIMUM BACKWARD COMPATIBILITY REQUIRED : 2.8 !" ) +endif( CMAKE_BACKWARDS_COMPATIBILITY LESS 2.8 ) + +# Enforcing one time include https://cmake.org/Wiki/CMake_Performance_Tips#Use_an_include_guard +if(catkin_pip_target_virtualenv_included) + return() +endif(catkin_pip_target_virtualenv_included) +set(catkin_pip_target_virtualenv_included true) + +message(STATUS "Loading catkin-pip-package-virtualenv.cmake from ${CMAKE_CURRENT_LIST_DIR}... ") + + +# catkin_pip_package override catkin_pip_package, otherwise CATKIN_PIP_ENV directory +## ned to call `catkin_pip_requirements` after `catkin_pip_package_virtualenv` +macro(catkin_pip_package_virtualenv package_name) + if (NOT ${package_name} STREQUAL ${PROJECT_NAME}) + message(FATAL_ERROR "We assume package_name(${package_name}) is equal to PROJECT_NAME(${PROJECT_NAME})") + endif() + + unset(CATKIN_VIRTUALENV CACHE) + find_program(CATKIN_VIRTUALENV NAMES virtualenv) + + # catkin_pip_package call catkin_package() to set CATKIN_PACKAGE_SHARE_DESTINATION + catkin_pip_package(${package_name} ${ARGN}) + + if (CATKIN_VIRTUALENV) + #set(CATKIN_VIRTUALENV "${CATKIN_VIRTUALENV} -q") # we can add all default basic options here. + else () + message(FATAL_ERROR "Could not find virtualenv") + endif() + + # runnig the virtualenv command (configure time) + set(CATKIN_VIRTUALENV_PATH_${package_name} ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/catkin_pip_env CACHE PATH "The virtual eivironment for each package") + catkin_pip_runcmd(${CATKIN_VIRTUALENV} --system-site-packages ${CATKIN_VIRTUALENV_PATH_${package_name}}) + + ### HACK somehow virtualenv create local dir + catkin_pip_runcmd(cmake -E remove_directory ${CATKIN_VIRTUALENV_PATH_${package_name}}/local) + + # Setting up our environment (for devel space only) + # Needed in case user call this directly (configure time) + ## NOTE This will set CATKIN_PIP within virtualenv + catkin_pip_setup_prefix(${CATKIN_VIRTUALENV_PATH_${PROJECT_NAME}}) + + ### OVERRIDE CATKIN_PIP_INSTALL_DEVEL_OUTPUTS is defined in catkin_pip_install_devel_target and used within catkin_pip_package + catkin_pip_runcmd(${CATKIN_PIP} install -e ${CMAKE_CURRENT_SOURCE_DIR} --prefix "${CATKIN_VIRTUALENV_PATH_${package_name}}") + +endmacro() + +# Override catkin_pip_requirements to install using virtualenv pip +function(catkin_pip_requirements requirements_txt) + # Setting up our environment (for devel space only) + # Needed in case user call this directly (configure time) + if (CATKIN_VIRTUALENV) + catkin_pip_setup_prefix(${CATKIN_VIRTUALENV_PATH_${PROJECT_NAME}}) + else() + catkin_pip_setup_prefix(${CATKIN_PIP_ENV}) + endif() + + # runnig the pip command (configure time) + if (CATKIN_VIRTUALENV) ## USE VIRTUALENV + catkin_pip_runcmd(${CATKIN_PIP} install ${ARGN} -r ${requirements_txt} --ignore-installed --src ${CMAKE_SOURCE_DIR} --exists-action b) + else() + catkin_pip_runcmd(${CATKIN_PIP} install ${ARGN} -r ${requirements_txt} --ignore-installed --src ${CMAKE_SOURCE_DIR} --exists-action b --prefix "${CATKIN_DEVEL_PREFIX}") + endif() + +endfunction() + diff --git a/cmake/catkin-pip-package.cmake.in b/cmake/catkin-pip-package.cmake.in index b3e30e3..b823bb4 100644 --- a/cmake/catkin-pip-package.cmake.in +++ b/cmake/catkin-pip-package.cmake.in @@ -98,11 +98,15 @@ function(catkin_pip_target package_name) # Note when installing in editable mode (for development) we shouldnt care about already installed versions. # However : https://github.com/asmodehn/catkin_pip/issues/58 if(CATKIN_PIP_NO_DEPS) + if(NOT CATKIN_VIRTUALENV) catkin_pip_install_devel_target(${package_name} ${package_path} --no-dependencies --ignore-installed) #catkin_pip_runcmd(${CATKIN_PIP} install -e ${package_path} --no-dependencies --prefix "${CATKIN_DEVEL_PREFIX}" --ignore-installed) + endif() else() + if(NOT CATKIN_VIRTUALENV) catkin_pip_install_devel_target(${package_name} ${package_path} --ignore-installed) #catkin_pip_runcmd(${CATKIN_PIP} install -e ${package_path} --prefix "${CATKIN_DEVEL_PREFIX}" --ignore-installed) + endif() endif() if(NOT EXISTS ${package_path}/setup.py) diff --git a/cmake/catkin-pip.cmake.in b/cmake/catkin-pip.cmake.in index d5748d9..d390acd 100644 --- a/cmake/catkin-pip.cmake.in +++ b/cmake/catkin-pip.cmake.in @@ -30,6 +30,12 @@ IF ( NOT CATKIN_PIP_PACKAGE_FOUND ) message ( FATAL_ERROR "${CMAKE_CURRENT_LIST_DIR}/catkin-pip-package.cmake Not Found !!!" ) ENDIF ( NOT CATKIN_PIP_PACKAGE_FOUND ) +# protecting against missing cmake file dependency +include ( "${CMAKE_CURRENT_LIST_DIR}/catkin-pip-package-virtualenv.cmake" RESULT_VARIABLE CATKIN_PIP_PACKAGE_VIRTUALENV_FOUND ) +IF ( NOT CATKIN_PIP_PACKAGE_VIRTUALENV_FOUND ) + message ( FATAL_ERROR "${CMAKE_CURRENT_LIST_DIR}/catkin-pip-package-virtualenv.cmake Not Found !!!" ) +ENDIF ( NOT CATKIN_PIP_PACKAGE_VIRTUALENV_FOUND ) + # Setting our paths to package env-hooks provided by catkin-pip if ( NOT CATKIN_PIP_ENV_HOOKS_PATH ) # templates should be found relative to our current path