From c61a3532daf1d1a888f4270e95cc387288ea0405 Mon Sep 17 00:00:00 2001 From: "Marcus D. Hanwell" Date: Fri, 20 Sep 2024 16:18:36 -0700 Subject: [PATCH] CMake: Only set the variable if it has not been defined (#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: https://github.com/facebookincubator/velox/pull/11040 Reviewed By: xiaoxmeng Differential Revision: D63138389 Pulled By: Yuhta fbshipit-source-id: 3deac39616600f808195df8e94ef3b711fb7f9bb --- CMake/ResolveDependency.cmake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CMake/ResolveDependency.cmake b/CMake/ResolveDependency.cmake index eba371fbcd60..ad8a8fd31bca 100644 --- a/CMake/ResolveDependency.cmake +++ b/CMake/ResolveDependency.cmake @@ -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}}