I have a zephyr project where I’m setting up the Makefile so that it can be built via elixir_make
. It all works well when I build it from the local project with mix compile
, but when I introduced it as a dependency to a nerves project, the zephyr build would fail.
The build failed with:
CMake Error at /home/jringle/zephyrproject/3.7.0/modules/lib/picolibc/CMakeLists.txt:46 (if):
if given arguments:
"STREQUAL" "arm64"
Unknown arguments specified
The failing code reference by the error has this:
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
set(CMAKE_SYSTEM_PROCESSOR "aarch64")
endif()
(there were also warnings that Zephyr would be ignoring CFLAGS
, CXXFLAGS
, CPPFLAGS
and LDFLAGS
)
After a bit of digging around, I found that nerves_system_br
seems to be setting this in the environment:
CMAKE_TOOLCHAIN_FILE=/home/jringle/git/gridpoint-com/ec2k_firmware/deps/nerves_system_br/nerves-env.cmake
nerves-env.cmake is the culprit for changing CMAKE_SYSTEM_PROCESSOR
that leads to the zephyr build error.
I was finally able to successfully build the zephyr project from my nerves project by adding this to the zephyr project’s Makefile:
unexport CMAKE_TOOLCHAIN_FILE CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
I’m wondering if anyone had thoughts on whether this was an appropriate way to handle this situation, or if there is a different way that might work better?
This is an interesting setup where the Nerves-injected environment variables are unhelpful.
There might be other environment variables that you’ll need to unexport. The Nerves provided environment variables page has the full list.
What I think could be a little better is if you can clear out the environment variables in your elixir_make
configuration via :make_env
rather than unexporting variables in the Zephyr project Makefile. Set the value of each variable to nil
to keep it unset.
I’m curious if setting all of the Nerves-provided environment variables to nil
works rather than just the subset that you found. I hope it does, since this seems like an all-or-none situation.
If using :make_env
works for you, I’d like to make this easier in Nerves and provide a function for getting the list of all environment variables so that everyone who has a similar setup doesn’t need to manually list out all of the important variables. WDYT?
I removed the unexport
line in the Makefile and then set :make_env
to:
%{
"BOARD" => "edge",
"CMAKE_TOOLCHAIN_FILE" => nil,
"CFLAGS" => nil,
"CXXFLAGS" => nil,
"CPPFLAGS" => nil,
"LDFLAGS" => nil
}
And that worked as well
I also tried setting all of the Nerves-provided environment variables to nil
as well, and that worked just fine.
Nice. I’m going to move work on this to Add helper functions to access Nerves-set environment variables · Issue #1003 · nerves-project/nerves · GitHub so we can get you and others who run into this an easier-to-maintain solution.
1 Like