How to print result of shell script in CMake?

30,996

If you want to know the value of a specific variable, you can use $ENV{varname}:

message(STATUS $ENV{PATH})

If you want to see all variables, you probably need to resort to invoking an external command such as env (on Unix) or set (on Windows):

# Windows
execute_process(COMMAND cmd /c set OUTPUT_VARIABLE output)
message(${output})
Share:
30,996
eonil
Author by

eonil

Favorite words: "Make it work, make it right, make it fast" — by Kent Beck? "...premature optimization is the root of all evil (or at least most of it) in programming." - from The Art of Computer Programming, by Donald Knuth. "Yes, but your program doesn't work. If mine doesn't have to work, I can make it run instantly and take up no memory." — from Code Complete, by Steve Mcconnell. "Flat is better than nested." — from The Zen of Python, by Tim Peters "Making decisions is slow." — from The Ninja build system manual, author unknown. "A little copying is better than a little dependency." - from Go Proverbs, by Rob Pike Preferred tools: macOS, iOS, Ubuntu. Rust, Swift, VIM, Xcode. SQLite, PostgreSQL, Redis. And a few more trivial stuffs. Feel free to fix my grammar. I always appreciate!

Updated on December 25, 2020

Comments

  • eonil
    eonil over 3 years

    If I want to check currently exported environment variables, I do this in shell.

    export
    

    In CMake, I do this to print something.

    MESSAGE ("This is message.")
    

    How can I print former one with CMake?

    I know that CMake is stand for cross-platform building, anyway when debugging something I need to check raw values. So I need this.