Checking CMake Cache Variable in Toolchain File

I am having problems setting a configuration variable through the command line. I cannot determine it from the system, so I expect the user to specify:

cmake -DCMAKE_TOOLCHAIN_FILE=../android.toolchain -DANDROID_ABI:STRING="arm64" .. 

Inside my android.toolchain , I have the following:

 message(STATUS "Android ABI: ${ANDROID_ABI}") if( "${ANDROID_ABI}" STREQUAL "" ) message(FATAL_ERROR "Please specifiy ABI at cmake call -DANDROID_ABI:STRING=armeabi or -DANDROID_ABI:STRING=arm64") endif() 

No matter what happens on this line EVEN, it prints the correct arm64:

  -- Android ABI: arm64 CMake Error at yaml-cpp/android.toolchain:45 (message): Please specifiy ABI at cmake call -DANDROID_ABI:STRING=armeabi or -DANDROID_ABI:STRING=arm64 

Can someone direct me to what I am doing wrong?


I think this is due to:

  • -D adds a cache variable instead of a regular variable
  • This is in the toolchain file ... it seems to ignore cache variables

Any thoughts or suggestions?

+6
source share
1 answer

I do not pretend to fully understand what is going on behind the scenes, but here is a workaround that works for me:

 # Problem: CMake runs toolchain files multiple times, but can't read cache variables on some runs. # Workaround: On first run (in which cache variables are always accessable), set an intermediary environment variable. if (FOO) # Environment variables are always preserved. set(ENV{_FOO} "${FOO}") else () set(FOO "$ENV{_FOO}") endif () 
+4
source

Source: https://habr.com/ru/post/982753/


All Articles