Answer the question
In order to leave comments, you need to log in
How to make cmake execute_process understand source command?
Hi all!
It happened to me recently to encounter a funny error when trying to make friends with cmake and a bash script. Briefly about the reason for what you will see next. In the project, you need to set a variable that will be seen by projects that will be built after this project. It seemed to me that the simplest solution was to set the environment variable using bash.
So, I have CMakeLists.txt and all this project does is call a bash script, like this:
execute_process(COMMAND source var_set.sh VALUE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE variable_RESULT)
message(STATUS ${variable_RESULT})
message(STATUS $ENV{MY_VAR})
var_set.sh
looks very simple too:#!/bin/bash
MY_VAR=$1
export MY_VAR
-- No such file or directory
source
, because if I callexecute_process(COMMAND ./var_set.sh VALUE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE variable_RESULT)
Answer the question
In order to leave comments, you need to log in
CMake generally works strangely with command interpreters
Try to specify the full path to source, or the knight's move - the command
bash -c "source var_set.h"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question