From 6a9c14a29dfbdf88297d148b88d13b2c57bc2d29 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel <guilhem.saurel@gmail.com> Date: Fri, 17 Aug 2018 16:12:06 +0200 Subject: [PATCH] [CMake] add BUILD_PYTHON_INTERFACE option --- CMakeLists.txt | 23 ++++++++++------------- python/CMakeLists.txt | 22 ++++++++++++++++------ src/CMakeLists.txt | 37 +++++++++++++++++-------------------- 3 files changed, 43 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 30e54d7..eaa427d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,10 +20,11 @@ INCLUDE(cmake/boost.cmake) INCLUDE(cmake/eigen.cmake) INCLUDE(cmake/lapack.cmake) INCLUDE(cmake/cpack.cmake) +INCLUDE(cmake/python.cmake) SET(PROJECT_NAME sot-dyninv) SET(PROJECT_DESCRIPTION "control by inverse dynamics.") -SET(PROJECT_URL "http://github.com/laas/sot-dyninv") +SET(PROJECT_URL "http://github.com/stack-of-tasks/sot-dyninv") SET(CUSTOM_HEADER_DIR "${PROJECT_NAME}") SET(DOXYGEN_USE_MATHJAX YES) @@ -135,22 +136,18 @@ foreach(lib solver-op-space solver-dyn-reduced solver-dyn-red2) ENDIF(WIN32) endforeach(lib) +OPTION(BUILD_PYTHON_INTERFACE "Build the python bindings" ON) +IF(BUILD_PYTHON_INTERFACE) + FINDPYTHON() + FIND_NUMPY() + INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIRS}) + ADD_REQUIRED_DEPENDENCY("dynamic-graph-python") +ENDIF(BUILD_PYTHON_INTERFACE) + # Add subdirectories. ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(python) ADD_SUBDIRECTORY(unitTesting) -# Configure some of the python files -CONFIGURE_FILE( - "${CMAKE_CURRENT_SOURCE_DIR}/python/robot_specific.py.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/python/robot_specific.py" -) - -#INCLUDE(cmake/python.cmake) -#INSTALL(FILES -# "${CMAKE_CURRENT_BINARY_DIR}/python/robotSpecific.py" -# DESTINATION ${PYTHON_SITELIB}/dynamic_graph/sot/dyninv -#) - SETUP_PROJECT_FINALIZE() SETUP_PROJECT_CPACK() diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 41ec92f..be13a14 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,8 +1,18 @@ -INCLUDE(../cmake/python.cmake) -FINDPYTHON() +IF(BUILD_PYTHON_INTERFACE) -INSTALL( - FILES ros/sot-concept.py - DESTINATION ${PYTHON_SITELIB}/dynamic_graph/tutorial -) + CONFIGURE_FILE( + "${CMAKE_CURRENT_SOURCE_DIR}/robot_specific.py.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/robot_specific.py" + ) + INSTALL(FILES + ${CMAKE_CURRENT_BINARY_DIR}/robot_specific.py + DESTINATION ${PYTHON_SITELIB}/dynamic_graph/sot/dyninv + ) + + INSTALL( + FILES ros/sot-concept.py + DESTINATION ${PYTHON_SITELIB}/dynamic_graph/tutorial + ) + +ENDIF(BUILD_PYTHON_INTERFACE) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3f1215f..a4412b1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,9 +14,6 @@ # received a copy of the GNU Lesser General Public License along with # sot-dyninv. If not, see <http://www.gnu.org/licenses/>. -INCLUDE(../cmake/python.cmake) -FINDPYTHON() - IF(CMAKE_BUILD_TYPE STREQUAL "DEBUG") ADD_DEFINITIONS(-DDEBUG=2) ENDIF(CMAKE_BUILD_TYPE STREQUAL "DEBUG") @@ -37,7 +34,6 @@ FOREACH(header ${headers}) PERMISSIONS OWNER_READ GROUP_READ WORLD_READ OWNER_WRITE) ENDFOREACH(header) INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/include) -LINK_DIRECTORIES(${PYTHON_LIBRARY_DIRS}) # --- COMPILATION OF PLUGINS FOREACH(lib ${libs}) @@ -62,22 +58,23 @@ FOREACH(lib ${libs}) INSTALL(TARGETS ${lib} DESTINATION ${DYNAMIC_GRAPH_PLUGINDIR}) # build python submodule - STRING(REPLACE - _ PYTHON_LIBRARY_NAME ${lib}) - DYNAMIC_GRAPH_PYTHON_MODULE("sot/dyninv/${PYTHON_LIBRARY_NAME}" - ${lib} - sot-dyninv-${PYTHON_LIBRARY_NAME}-wrap - ) + IF(BUILD_PYTHON_INTERFACE) + STRING(REPLACE - _ PYTHON_LIBRARY_NAME ${lib}) + DYNAMIC_GRAPH_PYTHON_MODULE("sot/dyninv/${PYTHON_LIBRARY_NAME}" + ${lib} + sot-dyninv-${PYTHON_LIBRARY_NAME}-wrap + ) + ENDIF(BUILD_PYTHON_INTERFACE) ENDFOREACH(lib) # Install empty __init__.py files in intermediate directories. -INSTALL(FILES - ${CMAKE_CURRENT_SOURCE_DIR}/dynamic_graph/sot/dyninv/__init__.py - ${CMAKE_CURRENT_SOURCE_DIR}/dynamic_graph/sot/dyninv/meta_task_dyn_6d.py - ${CMAKE_CURRENT_SOURCE_DIR}/dynamic_graph/sot/dyninv/meta_task_dyn_passing_point.py - ${CMAKE_CURRENT_SOURCE_DIR}/dynamic_graph/sot/dyninv/meta_tasks_dyn.py - ${CMAKE_CURRENT_SOURCE_DIR}/dynamic_graph/sot/dyninv/meta_tasks_dyn_relative.py - ${CMAKE_CURRENT_BINARY_DIR}/../python/robot_specific.py - DESTINATION ${PYTHON_SITELIB}/dynamic_graph/sot/dyninv -) - -MESSAGE(STATUS DESTINATION ${PYTHON_SITELIB} ) +IF(BUILD_PYTHON_INTERFACE) + INSTALL(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/dynamic_graph/sot/dyninv/__init__.py + ${CMAKE_CURRENT_SOURCE_DIR}/dynamic_graph/sot/dyninv/meta_task_dyn_6d.py + ${CMAKE_CURRENT_SOURCE_DIR}/dynamic_graph/sot/dyninv/meta_task_dyn_passing_point.py + ${CMAKE_CURRENT_SOURCE_DIR}/dynamic_graph/sot/dyninv/meta_tasks_dyn.py + ${CMAKE_CURRENT_SOURCE_DIR}/dynamic_graph/sot/dyninv/meta_tasks_dyn_relative.py + DESTINATION ${PYTHON_SITELIB}/dynamic_graph/sot/dyninv + ) +ENDIF(BUILD_PYTHON_INTERFACE) -- GitLab