Skip to content

Commit

Permalink
add catkin-pip-package-virtualenv.cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
k-okada committed Feb 8, 2018
1 parent 73c56a5 commit e82f666
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
68 changes: 68 additions & 0 deletions cmake/catkin-pip-package-virtualenv.cmake.in
Original file line number Diff line number Diff line change
@@ -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()

4 changes: 4 additions & 0 deletions cmake/catkin-pip-package.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions cmake/catkin-pip.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e82f666

Please sign in to comment.