PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 19, 2022

[FIXED] How to set environment variables in CMake so that they can be visible at build time?

 August 19, 2022     c++, cmake, cmake-language, environment-variables, unix     No comments   

Issue

On macOS 12, I tried to set some environment variables in CMakeLists.txt file like this.

# Add environment variables
set(ENV{VK_ICD_FILENAMES} /Users/username/VulkanSDK/macOS/share/vulkan/icd.d/MoltenVK_icd.json)
set(ENV{VK_LAYER_PATH} /Users/username/VulkanSDK/macOS/share/vulkan/explicit_layer.d)

But I quickly realize those environment variables only affects the current CMake instance. Basically, if I use message() in the same CMakeLists.txt file, CMake can print out the exact same value as I set. However, during build time, those variables do not exist and can't guide build phase.

My current solution is to generate Xcode project file and add those environment variables manually in Edit Scheme. But I want to learn CMake and do all the configurations in CMake. My question is if there is any way I can set environment variables in CMakeLists.txt file so that they at least persist during build phase?


Solution

Maybe what you want is CMAKE_XCODE_ATTRIBUTE_<an-attribute>

https://cmake.org/cmake/help/latest/variable/CMAKE_XCODE_ATTRIBUTE_an-attribute.html



Answered By - Gregorio Litenstein
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing