xref: /llvm-project/cmake/Modules/GNUInstallPackageDir.cmake (revision e941b031d316f74267350fe2373d30e28b3a2c2e)
1# Mimick `GNUInstallDirs` for one more install directory, the one where
2# project's installed cmake subdirs go.
3
4# These functions are internal functions vendored in from GNUInstallDirs (with
5# new names), so we don't depend on unstable implementation details. They are
6# also simplified to only handle the cases we need.
7#
8# The purpose would appear to be making `CACHE PATH` vars in a way that
9# bypasses the legacy oddity that `-D<PATH>` gets canonicalized, despite
10# non-canonical `CACHE PATH`s being perfectly valid.
11
12macro(_GNUInstallPackageDir_cache_convert_to_path var description)
13  get_property(_GNUInstallPackageDir_cache_type CACHE ${var} PROPERTY TYPE)
14  if(_GNUInstallPackageDir_cache_type STREQUAL "UNINITIALIZED")
15    file(TO_CMAKE_PATH "${${var}}" _GNUInstallPackageDir_cmakepath)
16    set_property(CACHE ${var} PROPERTY TYPE PATH)
17    set_property(CACHE ${var} PROPERTY VALUE "${_GNUInstallPackageDir_cmakepath}")
18    set_property(CACHE ${var} PROPERTY HELPSTRING "${description}")
19    unset(_GNUInstallPackageDir_cmakepath)
20  endif()
21  unset(_GNUInstallPackageDir_cache_type)
22endmacro()
23
24# Create a cache variable with default for a path.
25macro(_GNUInstallPackageDir_cache_path var default description)
26  if(NOT DEFINED ${var})
27    set(${var} "${default}" CACHE PATH "${description}")
28  endif()
29  _GNUInstallPackageDir_cache_convert_to_path("${var}" "${description}")
30endmacro()
31
32_GNUInstallPackageDir_cache_path(CMAKE_INSTALL_PACKAGEDIR "lib${LLVM_LIBDIR_SUFFIX}/cmake"
33  "Directories containing installed CMake modules (lib/cmake)")
34