llvm.org GIT mirror llvm / 171129e
[CMake] Make the CMake files (LLVMConfig.cmake and LLVMExports.cmake) generated by the Autoconf/Makefile build system relocatable. Previously the generated CMake files contained hardcoded paths which prevented a binary installation from being relocated to a different place in the file system. This problem was most noticeable in LLVM's official binary releases which were completely unusable by a downstream project trying to import the CMake targets. Package maintainers who choose to modify the install location of the CMake directory without using the ``PROJ_cmake`` Makefile variable override will need to patch the generated``LLVMConfig.cmake`` so that ``LLVM_INSTALL_PREFIX`` and ``_LLVM_CMAKE_DIR`` variables are set correctly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241080 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Liew 4 years ago
1 changed file(s) with 27 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
5959
6060 OBJMODS := LLVMConfig.cmake LLVMConfigVersion.cmake LLVMExports.cmake
6161
62 LLVM_CONFIG_CODE := \
63 \# Compute the CMake directory from the LLVMConfig.cmake file location.\n\
64 get_filename_component(_LLVM_CMAKE_DIR "$${CMAKE_CURRENT_LIST_FILE}" PATH)\n\
65 \# Compute the installation prefix from the LLVMConfig.cmake file location.\n\
66 get_filename_component(LLVM_INSTALL_PREFIX "$${CMAKE_CURRENT_LIST_FILE}" PATH)\n
67
68 # Compute number of levels (typically 3 - ``share/llvm/cmake/``) to PROJ_prefix
69 # from PROJ_cmake, then emit the appropriate number of calls to
70 # get_filename_components(). Note this assumes there are no spaces in the
71 # cmake_path_suffix variable.
72 cmake_path_suffix := $(subst $(PROJ_prefix),,$(subst $(DESTDIR),,$(PROJ_cmake)))
73 cmake_path_dirs := $(subst /, ,$(cmake_path_suffix))
74 LLVM_CONFIG_CODE += $(foreach __not_used,$(cmake_path_dirs),get_filename_component(LLVM_INSTALL_PREFIX "$${LLVM_INSTALL_PREFIX}" PATH)\n)
75
76 LLVM_CONFIG_CODE += set(_LLVM_LIBRARY_DIR "$${LLVM_INSTALL_PREFIX}\/lib")
77
6278 $(PROJ_OBJ_DIR)/LLVMConfig.cmake: LLVMConfig.cmake.in Makefile $(LLVMBuildCMakeFrag)
6379 $(Echo) 'Generating LLVM CMake package config file'
6480 $(Verb) ( \
6581 cat $< | sed \
66 -e 's/@LLVM_CONFIG_CODE@/set(LLVM_INSTALL_PREFIX "'"$(subst /,\/,$(PROJ_prefix))"'")/' \
82 -e 's/@LLVM_CONFIG_CODE@/$(LLVM_CONFIG_CODE)/' \
6783 -e 's/@LLVM_VERSION_MAJOR@/'"$(LLVM_VERSION_MAJOR)"'/' \
6884 -e 's/@LLVM_VERSION_MINOR@/'"$(LLVM_VERSION_MINOR)"'/' \
6985 -e 's/@LLVM_VERSION_PATCH@/'"$(LLVM_VERSION_PATCH)"'/' \
86102 -e 's/@LLVM_ON_UNIX@/'"$(LLVM_ON_UNIX)"'/' \
87103 -e 's/@LLVM_ON_WIN32@/'"$(LLVM_ON_WIN32)"'/' \
88104 -e 's/@LLVM_LIBDIR_SUFFIX@//' \
89 -e 's/@LLVM_CONFIG_INCLUDE_DIRS@/'"$(subst /,\/,$(PROJ_includedir))"'/' \
90 -e 's/@LLVM_CONFIG_LIBRARY_DIRS@/'"$(subst /,\/,$(PROJ_libdir))"'/' \
91 -e 's/@LLVM_CONFIG_CMAKE_DIR@/'"$(subst /,\/,$(PROJ_cmake))"'/' \
92 -e 's/@LLVM_CONFIG_TOOLS_BINARY_DIR@/'"$(subst /,\/,$(PROJ_bindir))"'/' \
105 -e 's#@LLVM_CONFIG_INCLUDE_DIRS@#$${LLVM_INSTALL_PREFIX}/include#' \
106 -e 's#@LLVM_CONFIG_LIBRARY_DIRS@#$${_LLVM_LIBRARY_DIR}#' \
107 -e 's#@LLVM_CONFIG_CMAKE_DIR@#$${_LLVM_CMAKE_DIR}#' \
108 -e 's#@LLVM_CONFIG_TOOLS_BINARY_DIR@#$${LLVM_INSTALL_PREFIX}/bin#' \
93109 -e 's/@LLVM_CONFIG_EXPORTS_FILE@/$${LLVM_CMAKE_DIR}\/LLVMExports.cmake/' \
94110 -e 's/@all_llvm_lib_deps@//' \
95111 && \
96112 ( grep '^set_property.*LLVMBUILD_LIB_DEPS_' "$(LLVMBuildCMakeFrag)" | \
97 grep -v LLVMBUILD_LIB_DEPS_gtest ) \
113 grep -v LLVMBUILD_LIB_DEPS_gtest ) && \
114 echo 'unset(_LLVM_CMAKE_DIR)' && \
115 echo 'unset(_LLVM_LIBRARY_DIR)' \
98116 ) > $@
99117
100 $(PROJ_OBJ_DIR)/LLVMConfigVersion.cmake: LLVMConfigVersion.cmake.in
118 $(PROJ_OBJ_DIR)/LLVMConfigVersion.cmake: LLVMConfigVersion.cmake.in Makefile
101119 $(Echo) 'Generating LLVM CMake package version file'
102120 $(Verb) cat $< | sed \
103121 -e 's/@PACKAGE_VERSION@/'"$(LLVMVersion)"'/' \
106124 -e 's/@LLVM_VERSION_PATCH@/'"$(LLVM_VERSION_PATCH)"'/' \
107125 > $@
108126
109 $(PROJ_OBJ_DIR)/LLVMExports.cmake: $(LLVMBuildCMakeExportsFrag)
127 $(PROJ_OBJ_DIR)/LLVMExports.cmake: $(LLVMBuildCMakeExportsFrag) Makefile
110128 $(Echo) 'Generating LLVM CMake target exports file'
111129 $(Verb) ( \
112130 echo '# LLVM CMake target exports. Do not include directly.' && \
113131 for lib in $(LLVM_LIBS_TO_EXPORT); do \
114132 echo 'add_library('"$$lib"' STATIC IMPORTED)' && \
115 echo 'set_property(TARGET '"$$lib"' PROPERTY IMPORTED_LOCATION "'"$(PROJ_libdir)/lib$$lib.a"'")' ; \
133 echo 'set_property(TARGET '"$$lib"' PROPERTY IMPORTED_LOCATION "$${_LLVM_LIBRARY_DIR}/'lib$$lib.a'")' ; \
116134 done && \
117135 cat "$(LLVMBuildCMakeExportsFrag)" && \
118136 echo 'set_property(TARGET LLVMSupport APPEND PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES '"$(subst -l,,$(LIBS))"')' \