Expected environment variables not being loaded when generating with CMake GUI on macOS
CMake GUI generation is not reading in environment variables, but generation with the cmake
command does. Problem is on macOS only, it continues to work fine on Linux and Windows.
Reproduced it with CMake 3.18.4 as well as 3.19.0-rc1 on macOS Catalina (10.15.6) and OS X Mavericks 10.9.5. This impactful to me because I'm running conan
or mono
within CMake. Here's a minimal example:
First, install Python3 and Conan.
Put the following in a CMakeLists.txt file:
cmake_minimum_required(VERSION 3.17)
project(hello_cmake)
execute_process(
COMMAND conan --version
RESULT_VARIABLE conan_result
)
if(conan_result)
message(FATAL_ERROR "Conan error")
endif()
Then:
- Open CMake GUI
- Set the source code directory to the above file's location
- Click Generate
- Select the Xcode generator
You'll see the printout of Conan error
and configuration fails
If you try to make the equivalent build at the terminal:
cmake -G Xcode -B build
It prints the Conan version as expected and generation succeeds.
As part of the Python3 installation process, /Library/Frameworks/Python.framework/Versions/3.9/bin
is appended to the PATH
environment variable in ~/.zprofile on Catalina and ~/.bash_profile on Mavericks. That's how Conan was found at the terminal. For some reason CMake GUI is not seeing those settings on macOS.
If I repeat this process using the Visual Studio 16 2019 generator on Windows or Ninja on Ubuntu, it works fine in the GUI and the command line. On Ubuntu, environment variables set in ~/.profile are usable from the CMake GUI. On Windows environment variables set in Control Panel > System and Security > System > Advanced System Settings > Environment variables... are also usable from the CMake GUI.