Skip to content

Commit

Permalink
CMake: Only set the variable if it has not been defined (facebookincu…
Browse files Browse the repository at this point in the history
…bator#11040)

Summary:
This enables variables to be set via `-Dvar_name=foo` on the command-line. Traditionally that would override an environment variable. This is more of a minor adjustment to the behavior and it will not break existing scripts using environment variables but a CMake cache variable would take precedence if both were supplied.

Pull Request resolved: facebookincubator#11040

Reviewed By: xiaoxmeng

Differential Revision: D63138389

Pulled By: Yuhta

fbshipit-source-id: 3deac39616600f808195df8e94ef3b711fb7f9bb
  • Loading branch information
cryos authored and facebook-github-bot committed Sep 20, 2024
1 parent 6d1fbf0 commit c61a353
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions CMake/ResolveDependency.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@ macro(set_source dependency_name)
STATUS "Setting ${dependency_name} source to ${${dependency_name}_SOURCE}")
endmacro()

# Set a variable to the value of $ENV{envvar_name} if defined, set to ${DEFAULT}
# if not defined. If called from within a nested scope the variable will not
# 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.
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}}
Expand Down

0 comments on commit c61a353

Please sign in to comment.