File: FindPrefixFromConfig.cmake

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-16
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,496,368 kB
  • sloc: cpp: 5,593,980; ansic: 986,873; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,547; xml: 953; cs: 573; fortran: 567
file content (44 lines) | stat: -rw-r--r-- 1,914 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Find the prefix from the `*Config.cmake` file being generated.
#
# When generating an installed `*Config.cmake` file, we often want to be able
# to refer to the ancestor directory which contains all the installed files.
#
# We want to do this without baking in an absolute path when the config file is
# generated, in order to allow for a "relocatable" binary distribution that
# doesn't need to know what path it ends up being installed at when it is
# built.
#
# The solution that we know the relative path that the config file will be at
# within that prefix, like `"${prefix_var}/lib/cmake/${project}"`, so we count
# the number of components in that path to figure out how many parent dirs we
# need to traverse from the location of the config file to get to the prefix
# dir.
#
# out_var:
#   variable to set the "return value" of the function, which is the code to
#   include in the config file under construction.
#
# prefix_var:
#   Name of the variable to define in the returned code (not directory for the
#   faller!) that will contain the prefix path.
#
# path_to_leave:
#   Path from the prefix to the config file, a relative path which we wish to
#   go up and out from to find the prefix directory.
function(find_prefix_from_config out_var prefix_var path_to_leave)
  set(config_code
    "# Compute the installation prefix from this LLVMConfig.cmake file location."
    "get_filename_component(${prefix_var} \"\${CMAKE_CURRENT_LIST_FILE}\" REALPATH)")


  # Construct the proper number of get_filename_component(... PATH)
  # calls to compute the installation prefix.
  string(REGEX REPLACE "/" ";" _count "prefix/${path_to_leave}")

  foreach(p ${_count})
    list(APPEND config_code
      "get_filename_component(${prefix_var} \"\${${prefix_var}}\" PATH)")
  endforeach(p)
  string(REPLACE ";" "\n" config_code "${config_code}")
  set("${out_var}" "${config_code}" PARENT_SCOPE)
endfunction()