N
N
niosus2015-03-15 15:32:32
bash
niosus, 2015-03-15 15:32:32

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})

The script itself var_set.shlooks very simple too:
#!/bin/bash
MY_VAR=$1
export MY_VAR

The problem is simple: the way this code is written, cmake gives me an error -- No such file or directory
. It seems to me that the problem here is with the command source, because if I call
execute_process(COMMAND  ./var_set.sh VALUE
                WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
                RESULT_VARIABLE variable_RESULT)

then the script is executed, but of course the export becomes useless.
Does anyone have any ideas why this is happening?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Vasilyevich, 2015-03-17
@mariczzz

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 question

Ask a Question

731 491 924 answers to any question