Commit a97950c5 authored by Guilhem Saurel's avatar Guilhem Saurel

[CMake] clean: keep minimal required instructions

parent 65fd0c43
......@@ -2,46 +2,74 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
SET(PROJECT_NAMESPACE stack-of-tasks)
# Project properties
SET(PROJECT_ORG stack-of-tasks)
SET(PROJECT_NAME dynamic-graph-python)
SET(PROJECT_DESCRIPTION "Dynamic graph library Python bindings")
SET(PROJECT_URL "http://github.com/${PROJECT_NAMESPACE}/${PROJECT_NAME}")
SET(PROJECT_URL "https://github.com/${PROJECT_ORG}/${PROJECT_NAME}")
# Project options
OPTION(SUFFIX_SO_VERSION "Suffix library name with its version" ON)
# Project configuration
SET(PROJECT_USE_CMAKE_EXPORT TRUE)
SET(CUSTOM_HEADER_DIR "dynamic-graph/python")
SET(CXX_DISABLE_WERROR TRUE)
SET(DOXYGEN_USE_MATHJAX YES)
# JRL-cmakemodule setup
INCLUDE(cmake/base.cmake)
INCLUDE(cmake/boost.cmake)
INCLUDE(cmake/eigen.cmake)
INCLUDE(cmake/python.cmake)
INCLUDE(cmake/test.cmake)
INCLUDE(cmake/sphinx.cmake)
SET(PKG_CONFIG_ADDITIONAL_VARIABLES plugindir ${PKG_CONFIG_ADDITIONAL_VARIABLES})
OPTION(SUFFIX_SO_VERSION
"Suffix shared library name by a string depending on git status of project"
ON)
# Project definition
COMPUTE_PROJECT_ARGS(PROJECT_ARGS LANGUAGES CXX)
PROJECT(${PROJECT_NAME} ${PROJECT_ARGS})
# Project dependencies
FINDPYTHON()
INCLUDE_DIRECTORIES(SYSTEM ${PYTHON_INCLUDE_DIRS})
ADD_PROJECT_DEPENDENCY(Eigen3 REQUIRED PKG_CONFIG_REQUIRES eigen3)
ADD_PROJECT_DEPENDENCY(dynamic-graph REQUIRED PKG_CONFIG_REQUIRES dynamic-graph)
PKG_CONFIG_APPEND_LIBS("dynamic-graph-python")
SET(BOOST_COMPONENTS filesystem system thread program_options unit_test_framework python)
SEARCH_FOR_BOOST()
# Main Library
SET(${PROJECT_NAME}_HEADERS
include/${CUSTOM_HEADER_DIR}/api.hh
include/${CUSTOM_HEADER_DIR}/convert-dg-to-py.hh
include/${CUSTOM_HEADER_DIR}/dynamic-graph-py.hh
include/${CUSTOM_HEADER_DIR}/exception.hh
include/${CUSTOM_HEADER_DIR}/exception-python.hh
include/${CUSTOM_HEADER_DIR}/interpreter.hh
include/${CUSTOM_HEADER_DIR}/python-compat.hh
include/${CUSTOM_HEADER_DIR}/signal-wrapper.hh
)
SET(${PROJECT_NAME}_SOURCES
src/interpreter.cc
src/dynamic_graph/python-compat.cc
)
ADD_LIBRARY(${PROJECT_NAME} SHARED
${${PROJECT_NAME}_SOURCES} ${${PROJECT_NAME}_HEADERS})
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} SYSTEM PUBLIC ${PYTHON_INCLUDE_DIRS})
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC $<INSTALL_INTERFACE:include>)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${Boost_LIBRARIES}
${PYTHON_LIBRARY} ${Boost_PYTHON_LIBRARIES} dynamic-graph::dynamic-graph)
IF(SUFFIX_SO_VERSION)
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION})
ENDIF(SUFFIX_SO_VERSION)
TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} PRIVATE PYTHON_LIBRARY="${PYTHON_LIBRARY}")
INSTALL(TARGETS ${PROJECT_NAME} EXPORT ${TARGETS_EXPORT_NAME} DESTINATION lib)
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(include/${CUSTOM_HEADER_DIR})
ADD_SUBDIRECTORY(doc)
ADD_SUBDIRECTORY(unitTesting)
ADD_SUBDIRECTORY(tests)
PKG_CONFIG_APPEND_LIBS(${PROJECT_NAME})
INSTALL(FILES package.xml DESTINATION share/${PROJECT_NAME})
Subproject commit 4514454f5f9462047b5c29f61b6c3e0db731c416
Subproject commit 321eb1ccf1d94570eb564f3659b13ef3ef82239e
# Copyright 2010-2019, Florent Lamiraux, Guilhem Saurel, LAAS-CNRS
SET(${PROJECT_NAME}_HEADERS
api.hh
convert-dg-to-py.hh
dynamic-graph-py.hh
exception.hh
exception-python.hh
interpreter.hh
python-compat.hh
signal-wrapper.hh
)
INSTALL(FILES ${${PROJECT_NAME}_HEADERS} DESTINATION include/${CUSTOM_HEADER_DIR})
CONFIG_FILES(link-to-python.hh)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/link-to-python.hh DESTINATION include/${CUSTOM_HEADER_DIR})
// -*- mode: c++ -*-
// Copyright 2011, Florent Lamiraux, CNRS.
#ifdef WIN32
#include <Windows.h>
#else
#include <dlfcn.h>
#endif
namespace dynamicgraph {
namespace python {
std::string libpython("@PYTHON_LIBRARY@");
} // namespace python
} // namespace dynamicgraph
# Copyright 2010-2020, Florent Lamiraux, Thomas Moulard, Olivier Stasse, Guilhem Saurel, JRL, CNRS/AIST, LAAS-CNRS
#
#
# Python interpreter
#
#
SET(LIBRARY_NAME ${PROJECT_NAME})
ADD_LIBRARY(${LIBRARY_NAME} SHARED interpreter.cc dynamic_graph/python-compat.cc)
TARGET_INCLUDE_DIRECTORIES(${LIBRARY_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/../include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/>
INTERFACE
$<INSTALL_INTERFACE:include>
)
TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${PYTHON_LIBRARY})
IF(UNIX)
TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${Boost_LIBRARIES})
TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${Boost_PYTHON_LIBRARIES})
TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${CMAKE_DL_LIBS})
ENDIF(UNIX)
IF (SUFFIX_SO_VERSION)
SET_TARGET_PROPERTIES(${LIBRARY_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION})
ENDIF ()
TARGET_LINK_LIBRARIES(${LIBRARY_NAME} dynamic-graph::dynamic-graph)
INSTALL(TARGETS ${LIBRARY_NAME}
EXPORT ${TARGETS_EXPORT_NAME}
PUBLIC_HEADER
INCLUDES DESTINATION include
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
#
#
# Python bindings
#
#
ADD_SUBDIRECTORY(dynamic_graph)
SET (PYTHON_SOURCES
__init__.py
attrpath.py
entity.py
signal_base.py
script_shortcuts.py
tools.py
)
SET(PYTHON_SOURCES
__init__.py
attrpath.py
entity.py
signal_base.py
script_shortcuts.py
tools.py
)
FOREACH (SOURCE ${PYTHON_SOURCES})
PYTHON_INSTALL_ON_SITE(dynamic_graph ${SOURCE})
ENDFOREACH (SOURCE)
FOREACH(source ${PYTHON_SOURCES})
PYTHON_INSTALL_ON_SITE(dynamic_graph ${source})
ENDFOREACH(source)
# --- ADD the wrap on the dg modules
# Tracer plugin
IF(WIN32)
SET(TRACER_PLUGIN ${DYNAMIC_GRAPH_PLUGINDIR}/tracer${CMAKE_STATIC_LIBRARY_SUFFIX})
ELSE(WIN32)
SET(TRACER_PLUGIN ${DYNAMIC_GRAPH_PLUGINDIR}/tracer${CMAKE_SHARED_LIBRARY_SUFFIX})
ENDIF(WIN32)
DYNAMIC_GRAPH_PYTHON_MODULE("tracer" ${TRACER_PLUGIN} tracer-wrap)
# TracerRealTime plugin
IF(WIN32)
SET(TRACERREALTIME_PLUGIN ${DYNAMIC_GRAPH_PLUGINDIR}/tracer-real-time${CMAKE_STATIC_LIBRARY_SUFFIX})
ELSE(WIN32)
SET(TRACERREALTIME_PLUGIN ${DYNAMIC_GRAPH_PLUGINDIR}/tracer-real-time${CMAKE_SHARED_LIBRARY_SUFFIX})
ENDIF(WIN32)
DYNAMIC_GRAPH_PYTHON_MODULE("tracer_real_time" ${TRACERREALTIME_PLUGIN} tracer_real_time-wrap)
LINK_DIRECTORIES(${DYNAMIC_GRAPH_PLUGINDIR})
DYNAMIC_GRAPH_PYTHON_MODULE("tracer" tracer tracer-wrap)
DYNAMIC_GRAPH_PYTHON_MODULE("tracer_real_time" tracer-real-time tracer_real_time-wrap)
......@@ -2,27 +2,26 @@
SET(PYTHON_MODULE wrap)
ADD_LIBRARY(${PYTHON_MODULE}
MODULE
convert-dg-to-py.cc
debug-py.cc
dynamic-graph-py.cc
entity-py.cc
exception-python.cc
factory-py.cc
pool-py.cc
python-compat.cc
signal-base-py.cc
signal-caster-py.cc
signal-wrapper.cc
)
ADD_LIBRARY(${PYTHON_MODULE} MODULE
convert-dg-to-py.cc
debug-py.cc
dynamic-graph-py.cc
entity-py.cc
exception-python.cc
factory-py.cc
pool-py.cc
python-compat.cc
signal-base-py.cc
signal-caster-py.cc
signal-wrapper.cc
)
TARGET_LINK_LIBRARIES(${PYTHON_MODULE} ${PYTHON_LIBRARY})
TARGET_LINK_LIBRARIES(${PYTHON_MODULE} dynamic-graph::dynamic-graph)
TARGET_INCLUDE_DIRECTORIES(${PYTHON_MODULE} SYSTEM PUBLIC ${PYTHON_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(${PYTHON_MODULE} ${PYTHON_LIBRARY}
dynamic-graph::dynamic-graph)
# Remove prefix lib
SET_TARGET_PROPERTIES(${PYTHON_MODULE}
PROPERTIES PREFIX "")
SET_TARGET_PROPERTIES(${PYTHON_MODULE} PROPERTIES PREFIX "")
INSTALL(TARGETS ${PYTHON_MODULE}
EXPORT ${TARGETS_EXPORT_NAME}
......
// -*- mode: c++ -*-
// Copyright 2011, Florent Lamiraux, CNRS.
#ifdef WIN32
#include <Windows.h>
#else
#include <dlfcn.h>
#endif
#include <iostream>
#include "dynamic-graph/debug.h"
#include "dynamic-graph/python/interpreter.hh"
#include "dynamic-graph/python/link-to-python.hh"
std::ofstream dg_debugfile("/tmp/dynamic-graph-traces.txt", std::ios::trunc& std::ios::out);
......@@ -61,7 +66,7 @@ Interpreter::Interpreter() {
// load python dynamic library
// this is silly, but required to be able to import dl module.
#ifndef WIN32
dlopen(libpython.c_str(), RTLD_LAZY | RTLD_GLOBAL);
dlopen(PYTHON_LIBRARY, RTLD_LAZY | RTLD_GLOBAL);
#endif
Py_Initialize();
PyEval_InitThreads();
......
# Copyright 2010-2020, Florent Lamiraux, Thomas Moulard, Olivier Stasse, Guilhem Saurel, JRL, CNRS/AIST, LAAS-CNRS
# Test the interpreter
SET(EXECUTABLE_NAME interpreter-test)
ADD_EXECUTABLE(${EXECUTABLE_NAME} interpreter-test.cc)
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} dynamic-graph-python)
ADD_TEST(${EXECUTABLE_NAME} ${EXECUTABLE_NAME})
ADD_UNIT_TEST(interpreter-test interpreter-test.cc)
TARGET_LINK_LIBRARIES(interpreter-test ${PROJECT_NAME})
# Test runfile
SET(EXECUTABLE_NAME interpreter-test-runfile)
ADD_EXECUTABLE(${EXECUTABLE_NAME} interpreter-test-runfile.cc)
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} dynamic-graph-python)
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} ${PYTHON_LIBRARY})
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} ${Boost_LIBRARIES})
ADD_TEST(${EXECUTABLE_NAME} ${EXECUTABLE_NAME})
ADD_CUSTOM_COMMAND(TARGET interpreter-test-runfile POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/unitTesting/test_python-ok.py
${CMAKE_BINARY_DIR}/unitTesting
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/unitTesting/test_python-name_error.py
${CMAKE_BINARY_DIR}/unitTesting
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/unitTesting/test_python-syntax_error.py
${CMAKE_BINARY_DIR}/unitTesting
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/unitTesting/test_python-restart_interpreter.py
${CMAKE_BINARY_DIR}/unitTesting
)
ADD_UNIT_TEST(interpreter-test-runfile interpreter-test-runfile.cc)
TARGET_LINK_LIBRARIES(interpreter-test-runfile ${PYTHON_LIBRARY} ${Boost_LIBRARIES} ${PROJECT_NAME})
TARGET_COMPILE_DEFINITIONS(interpreter-test-runfile PRIVATE PATH="${CMAKE_CURRENT_LIST_DIR}/")
# Test the module generation
## Create an entity
SET(LIBRARY_NAME "custom_entity")
ADD_LIBRARY(${LIBRARY_NAME} SHARED ${LIBRARY_NAME}.cpp)
IF (SUFFIX_SO_VERSION)
ADD_LIBRARY(${LIBRARY_NAME} SHARED "${LIBRARY_NAME}.cpp")
IF(SUFFIX_SO_VERSION)
SET_TARGET_PROPERTIES(${LIBRARY_NAME}
PROPERTIES SOVERSION ${PROJECT_VERSION})
ENDIF ()
SET_TARGET_PROPERTIES(${LIBRARY_NAME}
PROPERTIES
PREFIX ""
INSTALL_RPATH ${DYNAMIC_GRAPH_PLUGINDIR})
ENDIF(SUFFIX_SO_VERSION)
target_link_libraries(${LIBRARY_NAME} dynamic-graph::dynamic-graph)
......@@ -46,21 +26,21 @@ target_link_libraries(${LIBRARY_NAME} dynamic-graph::dynamic-graph)
CONFIGURE_FILE(
${PROJECT_SOURCE_DIR}/cmake/dynamic_graph/submodule/__init__.py.cmake
${PROJECT_BINARY_DIR}/unitTesting/${LIBRARY_NAME}/__init__.py
${CMAKE_CURRENT_BINARY_DIR}/${LIBRARY_NAME}/__init__.py
)
SET(PYTHON_MODULE "${LIBRARY_NAME}-wrap")
SET(SOURCE_PYTHON_MODULE "cmake/dynamic_graph/python-module-py.cc")
ADD_LIBRARY(${PYTHON_MODULE} MODULE ${PROJECT_SOURCE_DIR}/${SOURCE_PYTHON_MODULE})
SET_TARGET_PROPERTIES(${PYTHON_MODULE}
PROPERTIES PREFIX ""
OUTPUT_NAME ${LIBRARY_NAME}/wrap
)
SET_TARGET_PROPERTIES(${PYTHON_MODULE} PROPERTIES
PREFIX ""
OUTPUT_NAME ${LIBRARY_NAME}/wrap)
TARGET_LINK_LIBRARIES(${PYTHON_MODULE} ${PUBLIC_KEYWORD} "-Wl,--no-as-needed")
TARGET_LINK_LIBRARIES(${PYTHON_MODULE} ${PUBLIC_KEYWORD} ${LIBRARY_NAME} ${PYTHON_LIBRARY})
TARGET_LINK_LIBRARIES(${PYTHON_MODULE} "-Wl,--no-as-needed")
TARGET_LINK_LIBRARIES(${PYTHON_MODULE} ${LIBRARY_NAME} ${PYTHON_LIBRARY})
TARGET_INCLUDE_DIRECTORIES(${PYTHON_MODULE} SYSTEM PUBLIC ${PYTHON_INCLUDE_DIRS})
## Test it
ADD_PYTHON_UNIT_TEST("test-custom-entity" "unitTesting/test_custom_entity.py" src unitTesting)
ADD_PYTHON_UNIT_TEST("test-custom-entity" "tests/test_custom_entity.py" src tests)
# also test other bindings, using this custom entity
ADD_PYTHON_UNIT_TEST("test-bindings" "unitTesting/test_bindings.py" src unitTesting)
ADD_PYTHON_UNIT_TEST("test-bindings" "tests/test_bindings.py" src tests)
/*
* Copyright
*/
#include <iostream>
#include "dynamic-graph-python-test.hh"
GraphTest::GraphTest() { std::cout << "Constructor of unitTesting object of class Graph." << std::endl; }
......@@ -49,18 +49,18 @@ int main(int argc, char** argv) {
// This test succeeds only because it is launched before "test_python-ok.py"
// because re as been imported in a previous test and it is not
// safe to delete imported module...
res = testFile("test_python-name_error.py",
res = testFile(PATH "test_python-name_error.py",
std::string("Traceback (most recent call last):\n"
" File \"test_python-name_error.py\", line 7, in <module>\n"
" File \"" PATH "test_python-name_error.py\", line 7, in <module>\n"
" pathList = re.split(':', pkgConfigPath) # noqa\n"
"NameError: name 're' is not defined\n"),
numTest) &&
res;
res = testFile("test_python-ok.py", "", numTest) && res;
res = testFile("unexistant_file.py", "unexistant_file.py cannot be open", numTest) && res;
res = testFile("test_python-syntax_error.py",
std::string(" File \"test_python-syntax_error.py\", line 2\n"
res = testFile(PATH "test_python-ok.py", "", numTest) && res;
res = testFile(PATH "unexistant_file.py", PATH "unexistant_file.py cannot be open", numTest) && res;
res = testFile(PATH "test_python-syntax_error.py",
std::string(" File \"" PATH "test_python-syntax_error.py\", line 2\n"
" hello world\n"
#if PY_MINOR_VERSION >= 8
" ^\n"
......@@ -70,6 +70,6 @@ int main(int argc, char** argv) {
"SyntaxError: invalid syntax\n"),
numTest) &&
res;
res = testInterpreterDestructor("test_python-restart_interpreter.py", "") && res;
res = testInterpreterDestructor(PATH "test_python-restart_interpreter.py", "") && res;
return (res ? 0 : 1);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment