Check CMake Cache Variable in Toolchain File

前端 未结 1 665
粉色の甜心
粉色の甜心 2020-12-16 02:56

I\'m having trouble setting a configuration variable via the command line. I can\'t determine it from the system, so I expect the user to specify:

cmake -DCM         


        
相关标签:
1条回答
  • 2020-12-16 03:24

    I don't pretend to fully understand what's going on behind the scenes, but here's 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 accessible), set an intermediary environment variable.
    
    if (FOO)
        # Environment variables are always preserved.
        set(ENV{_FOO} "${FOO}")
    else ()
        set(FOO "$ENV{_FOO}")
    endif ()
    
    0 讨论(0)
提交回复
热议问题