Skip to content
  • Craig Scott's avatar
    FetchContent: Don't leak temporary variable and restore var robustly · 2b68048b
    Craig Scott authored
    In FetchContent_MakeAvailable(), the __fcprefix__ previously used
    when pushing the value of CMAKE_EXPORT_FIND_PACKAGE_NAME
    to the variable stack is not needed. The stack will never be empty
    at that point, so pushing an empty value will be handled correctly.
    By removing the __fcprefix__, we no longer need any temporary
    variable when restoring CMAKE_EXPORT_FIND_PACKAGE_NAME.
    
    But we need to ensure CMAKE_EXPORT_FIND_PACKAGE_NAME is
    left undefined if it wasn't defined before, and pushing an empty
    value doesn't let us distinguish between unset and set-but-empty.
    Therefore, when CMAKE_EXPORT_FIND_PACKAGE_NAME is undefined,
    push a specific value that can't be used by the project instead and
    check for that when popping it again. This ensures we can robustly
    distinguish the two cases and will always restore the right state.
    
    Fixes: #25758
    2b68048b