| 1 |
# @HEADER |
| 2 |
# ***************************************************************************** |
| 3 |
# TriBITS: Tribal Build, Integrate, and Test System |
| 4 |
# |
| 5 |
# Copyright 2013-2016 NTESS and the TriBITS contributors. |
| 6 |
# SPDX-License-Identifier: BSD-3-Clause |
| 7 |
# ***************************************************************************** |
| 8 |
# @HEADER |
| 9 |
|
| 10 |
include(CMakeParseArguments) |
| 11 |
include(PrintNonemptyVar) |
| 12 |
|
| 13 |
# |
| 14 |
# Finds the absolute path for a program given optionally just the program name |
| 15 |
# |
| 16 |
# Input keyword arguments: |
| 17 |
# |
| 18 |
# NAMES name1 name2 ... |
| 19 |
# List of default names that will be search |
| 20 |
# |
| 21 |
# PATHS path1 path2 ... |
| 22 |
# List of paths |
| 23 |
# |
| 24 |
# DOC docStr |
| 25 |
# Documentation string |
| 26 |
# |
| 27 |
|
| 28 |
function(find_program_plus PROG_VAR) |
| 29 |
|
| 30 |
cmake_parse_arguments( |
| 31 |
#prefix |
| 32 |
PARSE |
| 33 |
#options |
| 34 |
"" |
| 35 |
#one_value_keywords |
| 36 |
"" |
| 37 |
#multi_value_keywords |
| 38 |
"NAMES;PATHS;DOC" |
| 39 |
${ARGN} |
| 40 |
) |
| 41 |
|
| 42 |
tribits_check_for_unparsed_arguments() |
| 43 |
|
| 44 |
print_nonempty_var(${PROG_VAR}) |
| 45 |
|
| 46 |
if (IS_ABSOLUTE ${PROG_VAR}) |
| 47 |
#message(STATUS "Is Absolute") |
| 48 |
set(NAMES_ARGS ${PARSE_NAMES}) |
| 49 |
else() |
| 50 |
#message(STATUS "Is Not Absolute") |
| 51 |
set(NAMES_ARGS ${${PROG_VAR}} ${PARSE_NAMES}) |
| 52 |
set(${PROG_VAR} "${PROG_VAR}-NOTFOUND" CACHE FILEPATH "" FORCE) |
| 53 |
endif() |
| 54 |
#print_var(NAMES_ARGS) |
| 55 |
|
| 56 |
set(DOC "${PARSE_DOC} Can be full path or just exec name.") |
| 57 |
|
| 58 |
# Look for program in given paths first! |
| 59 |
find_program( ${PROG_VAR} |
| 60 |
NAMES ${NAMES_ARGS} |
| 61 |
PATHS ${PARSE_PATHS} |
| 62 |
DOC ${DOC} |
| 63 |
NO_DEFAULT_PATH |
| 64 |
) |
| 65 |
find_program( ${PROG_VAR} |
| 66 |
NAMES ${NAMES_ARGS} |
| 67 |
DOC ${DOC} |
| 68 |
) |
| 69 |
mark_as_advanced(${PROG_VAR}) |
| 70 |
|
| 71 |
print_nonempty_var(${PROG_VAR}) |
| 72 |
|
| 73 |
endfunction() |