CMakeLists.txt 2.28 KB
Newer Older
Maximilien Naveau's avatar
Maximilien Naveau committed
1
cmake_minimum_required(VERSION 3.5)
Pierre Gergondet's avatar
Pierre Gergondet committed
2

Guilhem Saurel's avatar
Guilhem Saurel committed
3
set(PROJECT_ORG stack-of-tasks)
olivier stasse's avatar
olivier stasse committed
4
set(PROJECT_NAME dynamic_graph_bridge_msgs)
Guilhem Saurel's avatar
Guilhem Saurel committed
5
6
set(PROJECT_DESCRIPTION "Dynamic graph bridge msgs ")
set(PROJECT_URL "https://github.com/${PROJECT_ORG}/${PROJECT_NAME}")
olivier stasse's avatar
olivier stasse committed
7

8
9
10
11
12
if(DEFINED ENV{ROS_VERSION})
  set(ROS_VERSION $ENV{ROS_VERSION})
else()
  set(ROS_VERSION 1)
endif()
olivier stasse's avatar
olivier stasse committed
13

14
15
16
17
18
if(ROS_VERSION EQUAL 1) # if ROS1
  # Here we use the jrl-cmakemodules to package things properly.
  set(CUSTOM_HEADER_DIR dynamic_graph_bridge_msgs)
  set(PROJECT_USE_CMAKE_EXPORT TRUE)
  include(cmake/base.cmake)
olivier stasse's avatar
olivier stasse committed
19

20
21
  COMPUTE_PROJECT_ARGS(PROJECT_ARGS LANGUAGES CXX C)
  project(${PROJECT_NAME} ${PROJECT_ARGS})
Pierre Gergondet's avatar
Pierre Gergondet committed
22

23
24
  # Declare build dependencies
  find_package(catkin REQUIRED COMPONENTS message_generation std_msgs)
Pierre Gergondet's avatar
Pierre Gergondet committed
25

26
27
  # Add message files
  add_message_files(DIRECTORY msg FILES Matrix.msg Vector.msg)
Pierre Gergondet's avatar
Pierre Gergondet committed
28

29
30
31
32
33
  # Add service files
  add_service_files(
      DIRECTORY srv
      FILES RunCommand.srv RunPythonCommand.srv RunPythonFile.srv
  )
olivier stasse's avatar
olivier stasse committed
34

35
36
  # And now generate the messages
  generate_messages(DEPENDENCIES ${MESSAGE_DEPENDENCIES})
olivier stasse's avatar
olivier stasse committed
37

38
  add_library(${PROJECT_NAME} INTERFACE)
Maximilien Naveau's avatar
Maximilien Naveau committed
39

40
  install(TARGETS ${PROJECT_NAME} EXPORT ${TARGETS_EXPORT_NAME} DESTINATION lib)
Maximilien Naveau's avatar
Maximilien Naveau committed
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
else() # if ROS2
  # Here ament is doing things ok.
  project(${PROJECT_NAME})

  find_package(ament_cmake REQUIRED)
  find_package(ament_cmake_python REQUIRED)
  find_package(rosidl_default_generators REQUIRED)
  rosidl_generate_interfaces(${PROJECT_NAME}
    "msg/Matrix.msg"
    "msg/Vector.msg"
    "srv/RunCommand.srv"
    "srv/RunPythonCommand.srv"
    "srv/RunPythonFile.srv"
  )
  ament_export_dependencies(rosidl_default_runtime)
  ament_package()
endif()
Maximilien Naveau's avatar
Maximilien Naveau committed
59

Guilhem Saurel's avatar
Guilhem Saurel committed
60
61
install(FILES package.xml DESTINATION share/${PROJECT_NAME})

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
if(BUILD_TESTING)
  if(ROS_VERSION EQUAL 1) # if ROS1
    find_package(rostest REQUIRED)
    add_rostest(tests/ros1/unit_test_ros.test)
  else() # if ROS-2
    include(CTest)
    include(cmake/python.cmake)
    findpython()
    add_test(
      NAME test_${PROJECT_NAME}_python
      COMMAND ${PYTHON_EXECUTABLE} -m pytest -v
      WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests/ros2)
    set_tests_properties(
      test_${PROJECT_NAME}_python
      PROPERTIES
        ENVIRONMENT
        "PYTHONPATH=${CMAKE_BINARY_DIR}/rosidl_generator_py/:${CMAKE_BINARY_DIR}:$ENV{PYTHONPATH}"
Maximilien Naveau's avatar
Maximilien Naveau committed
79
80
    )
  endif()
81
endif() # BUILD_TESTING