cmake execute_process command
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.
Asked by robo_ninja on 2017-10-30 09:41:32 UTC
Answers
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.)
Asked by 130s on 2019-10-24 18:46:17 UTC
Comments