ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

cmake execute_process command

asked 2017-10-30 09:41:32 -0600

robo_ninja gravatar image

I have created a /csv and /scripts directories in my /src directory. The /csv directory contains a csv file and /scripts directory contains a Python script to parse the csv file. Now I want to use CMake's execute_process to execute this parsing process. I am passing the path to the Python script and csv file as 2 args. Following is how my CMakelists.txt look -

cmake_minimum_required(VERSION 2.8.3)
project(<package_name>)
find_package(catkin REQUIRED)
add_definitions(-std=c++11)
catkin_package(
  INCLUDE_DIRS include
)

set(HON_SCRIPT "${PROJECT_SOURCE_DIR}/scripts/testparser.py")
set(HON_CSV "${PROJECT_SOURCE_DIR}/csv/alarms.csv")

execute_process(
  COMMAND ${HON_SCRIPT} ${HON_CSV}
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

Is this the best way to do this? I am not sure if I have use COMMAND correctly.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-10-24 18:46:17 -0600

130s gravatar image

updated 2021-04-26 10:45:24 -0600

Catkin (which I assume you're using to build your pkg although I don't see any mention of build tool) is cmake extension and any cmake macro can be used as defined in cmake, and execute_process shouldn't be an exception. With CMakeLists.txt in your sample, cmake should be able to reference to what's defined in ${HON_SCRIPT}, ${HON_CSV}.

I checked with something similar with catkin-tools. Posting pretty much the whole thing as it's short enough.

cmake_minimum_required(VERSION 2.8.3)
project(catkin_pkg_a)
find_package(catkin REQUIRED)
catkin_package()

set(SCRIPT_SETUP_SAMPLE "${PROJECT_SOURCE_DIR}/setup_sample.sh")
execute_process(
  COMMAND ${SCRIPT_SETUP_SAMPLE}
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  )

setup_sample.sh file:

#!/bin/bash
touch /tmp/file_made_via_cmake

Command executed:

date
Thu Oct 23 18:37:57 PDT 2019
ll /tmp/file_made_via_cmake
ls: cannot access '/tmp/file_made_via_cmake': No such file or directory

catkin config --install
catkin build

ll /tmp/file_made_via_cmake
-rw-r--r-- 1 root root 0 Oct 23 18:38 /tmp/file_made_via_cmake

(Btw, I'm seeing when running catkin build -DCMAKE_BUILD_TYPE=Release, the file doesn't always get created. Not yet sure why.)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-10-30 09:41:32 -0600

Seen: 3,508 times

Last updated: Apr 26 '21