Issue
I'd like to share some variables between my scripts and CMake. It would be nice to re-use bash syntax:
var1=value1
var2=value2
...
I was trying to use the solution from here as the problem is pretty much the same: https://stackoverflow.com/a/17167673/15035275 But the solution didn't work for me.
I created a file config.in
containing:
FOO=foobar
And I added this config file to my CMakeLists file:
cmake_minimum_required(VERSION 3.16)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/config.in
${CMAKE_CURRENT_BINARY_DIR}/config
@ONLY
)
set(CMAKE_VERBOSE_ON)
set(CMAKE_VERBOSE_MAKEFILE ON)
message(STATUS "foo is equal to: ${FOO}")
...
But the variable ${FOO}
isn't visible by CMake:
/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja -S /home/p -B /home/p/cmake-build-debug
-- foo is equal to:
-- The CXX compiler identification is Clang 10.0.0
...
How can I use the variables from config.in
?
Solution
The answer you linked is not applicable to your problem - I've left a comment on that answer as well.
I don't know of a generic way apart from the regex-based solutions offered by other people in the question you linked.
I can only give you a somewhat more verbose alternative, based on this answer:
execute_process(COMMAND ". config.in && echo -n $FOO" OUTPUT_VARIABLE FOO)
message(STATUS "FOO=${FOO}")
Answered By - Wutz Answer Checked By - Candace Johnson (WPSolving Volunteer)