build: only use HOSTNAME_PRG if HOSTNAME is undefined (#22288)

Allow specifying the HOSTNAME variable by defining it with -D when
invoking CMake, instead of overriding it with the output of
HOSTNAME_RPG.
This commit is contained in:
Gregory Anders 2023-02-16 12:36:55 -07:00 committed by GitHub
parent 5688a9fb34
commit ced0cd12d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -188,7 +188,7 @@ elseif (NOT DEFINED USERNAME AND EXISTS ${WHOAMI_PRG})
endif()
if (DEFINED ENV{HOSTNAME})
set(HOSTNAME $ENV{HOSTNAME})
elseif (EXISTS ${HOSTNAME_PRG})
elseif (NOT DEFINED HOSTNAME AND EXISTS ${HOSTNAME_PRG})
execute_process(COMMAND ${HOSTNAME_PRG}
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE HOSTNAME)