0

Hello to whoever reading this.

This is not actually a question. It's a problem i faced and i was trying to find solution here in stackoverflow. But i couldn't. [Chances are it may be duplicate in the eyes of experts]. Anyway thought i'll share the solution which is working for me.

The Problem

I work on Windows CE panels so in some scenario I need to read batch script variable in CMakeLists.txt to do some filtering based on whether it's Windows x86 or Windows CE. How to do that ?

Could be the same as This but for me export didn't work. So the whole picture.

Later checked export is in bash. In batch set will work

Community
  • 1
  • 1
A J
  • 720
  • 1
  • 8
  • 11
  • 3
    Possible duplicate of [How to retrieve a user environment variable in CMake (Windows)](http://stackoverflow.com/questions/690223/how-to-retrieve-a-user-environment-variable-in-cmake-windows) – Tsyvarev Apr 06 '17 at 08:20
  • In a bigger picture Seems same.. but in my case export was not working :( – A J Apr 06 '17 at 10:30

1 Answers1

1

The Answer which is working for me. [There are chance that other solution also exists but this worked for me]. Ok here it goes.

In batch file

set "PANEL_TYPE=WINCE"

In CMakeLists.txt

if( $ENV{PANEL_TYPE} STREQUAL "WINCE")
    message(STATUS "Print Message = " $ENV{PANEL_TYPE})
    set(THE STUFF)
else()
    message(STATUS "Other Message = " $ENV{PANEL_TYPE}) 
endif()

That's it. It seems simple to me and it worked :)

A J
  • 720
  • 1
  • 8
  • 11
  • Can't you look at the standard environment variable `OS`? – Klitos Kyriacou Apr 06 '17 at 07:01
  • Just a hint: That's probably not going to work with Visual Studio solutions. You have to transfer the environment variable into a cached variable in CMake. The reasoning: if Visual Studio runs in another environment, then each time in your project when CMake re-configures and re-generates the solution `$ENV{PANEL_TYPE}` would probably be empty. – Florian Apr 06 '17 at 07:32
  • Umm .. I am using it in Visual Studio. Not an expert in Cmake so can't actually say anything about it. – A J Apr 06 '17 at 10:29
  • Touch one of your project's `CMakeLists.txt` files and build `ZERO_CHECK` target. What is the message's output of above example? – Florian Apr 06 '17 at 10:45
  • OK .. it's in windows.. So i give 1 space to modify (touch). The message is "Print Message = WINCE" – A J Apr 06 '17 at 10:53
  • @KlitosKyriacou I could but i needed to modify the CMakelist file to segregate the WINCE part and x86. So i needed something of my own which i can play with. – A J Apr 07 '17 at 09:24