Skip to content

Commit

Permalink
CMake: Make the env variable precedence by default in set_with_default (
Browse files Browse the repository at this point in the history
#11070)

Summary:
After the modification in #11040, if the `var_name` is already defined, the `set_with_default` method will not override it with the env variable. However, before that, the value from the env will be prioritized for defining `var_name`. The design goal of the `resolve_dependency_url` method is to allow the overriding of values defined in `VELOX_xxx_SOURCE_URL` with env variables, which enables specifying `VELOX_xxx_SOURCE_URL` to a local file to reduce dependency download time and achieve offline dependency compilation.

Pull Request resolved: #11070

Reviewed By: DanielHunte

Differential Revision: D63344157

Pulled By: Yuhta

fbshipit-source-id: 3740d3a77f12f096f7c7c9d5460b005b3a9815e0
  • Loading branch information
liujiayi771 authored and facebook-github-bot committed Sep 25, 2024
1 parent d20ca4b commit a59538c
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions CMake/ResolveDependency.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,16 @@ macro(set_source dependency_name)
STATUS "Setting ${dependency_name} source to ${${dependency_name}_SOURCE}")
endmacro()

# If the var_name is not defined then set var_name to the value of
# $ENV{envvar_name} if it is defined. If neither is defined then set var_name to
# ${DEFAULT}. If called from within a nested scope the variable will not
# propagate into outer scopes automatically! Use PARENT_SCOPE.
# Set var_name to the value of $ENV{envvar_name} if ENV is defined. If neither
# ENV or var_name is defined then set var_name to ${DEFAULT}. If called from
# within a nested scope the variable will not propagate into outer scopes
# automatically! Use PARENT_SCOPE.
function(set_with_default var_name envvar_name default)
if(DEFINED ${var_name})
return()
endif()
if(DEFINED ENV{${envvar_name}})
set(${var_name}
$ENV{${envvar_name}}
PARENT_SCOPE)
else()
elseif(NOT DEFINED ${var_name})
set(${var_name}
${default}
PARENT_SCOPE)
Expand Down Expand Up @@ -142,6 +139,8 @@ macro(resolve_dependency_url dependency_name)
set_with_default(
VELOX_${dependency_name}_SOURCE_URL VELOX_${dependency_name}_URL
${VELOX_${dependency_name}_SOURCE_URL})
message(VERBOSE "Set VELOX_${dependency_name}_SOURCE_URL to "
"${VELOX_${dependency_name}_SOURCE_URL}")
if(DEFINED ENV{VELOX_${dependency_name}_URL})
set_with_default(VELOX_${dependency_name}_BUILD_SHA256_CHECKSUM
VELOX_${dependency_name}_SHA256 "")
Expand Down

0 comments on commit a59538c

Please sign in to comment.