Filter libraries that are not installed out of CMake exports (currently
[oota-llvm.git] / cmake / modules / Makefile
1 ##===- cmake/modules/Makefile ------------------------------*- Makefile -*-===##
2 #
3 #                     The LLVM Compiler Infrastructure
4 #
5 # This file is distributed under the University of Illinois Open Source
6 # License. See LICENSE.TXT for details.
7 #
8 ##===----------------------------------------------------------------------===##
9
10 LEVEL = ../..
11
12 include $(LEVEL)/Makefile.common
13
14 PROJ_cmake := $(DESTDIR)$(PROJ_prefix)/share/llvm/cmake
15
16 ifeq ($(DISABLE_ASSERTIONS),1)
17         LLVM_ENABLE_ASSERTIONS := 0
18 else
19         LLVM_ENABLE_ASSERTIONS := 1
20 endif
21
22 ifeq ($(ENABLE_ABI_BREAKING_CHECKS),1)
23         LLVM_ABI_BREAKING_CHECKS := FORCE_ON
24 else
25         LLVM_ABI_BREAKING_CHECKS := FORCE_OFF
26 endif
27
28 ifeq ($(REQUIRES_EH),1)
29         LLVM_ENABLE_EH := 1
30 else
31         LLVM_ENABLE_EH := 0
32 endif
33
34 ifeq ($(REQUIRES_RTTI),1)
35         LLVM_ENABLE_RTTI := 1
36 else
37         LLVM_ENABLE_RTTI := 0
38 endif
39
40 ifndef LLVM_LIBS_TO_EXPORT
41 $(error LLVM_LIBS_TO_EXPORT cannot be empty)
42 endif
43
44 OBJMODS := LLVMConfig.cmake LLVMConfigVersion.cmake LLVMExports.cmake
45
46 LLVM_CONFIG_CODE := \
47 \# Compute the CMake directory from the LLVMConfig.cmake file location.\n\
48 get_filename_component(_LLVM_CMAKE_DIR "$${CMAKE_CURRENT_LIST_FILE}" PATH)\n\
49 \# Compute the installation prefix from the LLVMConfig.cmake file location.\n\
50 get_filename_component(LLVM_INSTALL_PREFIX "$${CMAKE_CURRENT_LIST_FILE}" PATH)\n
51
52 # Compute number of levels (typically 3 - ``share/llvm/cmake/``) to PROJ_prefix
53 # from PROJ_cmake, then emit the appropriate number of calls to
54 # get_filename_components(). Note this assumes there are no spaces in the
55 # cmake_path_suffix variable.
56 cmake_path_suffix := $(subst $(PROJ_prefix),,$(subst $(DESTDIR),,$(PROJ_cmake)))
57 cmake_path_dirs := $(subst /, ,$(cmake_path_suffix))
58 LLVM_CONFIG_CODE += $(foreach __not_used,$(cmake_path_dirs),get_filename_component(LLVM_INSTALL_PREFIX "$${LLVM_INSTALL_PREFIX}" PATH)\n)
59
60 LLVM_CONFIG_CODE += set(_LLVM_LIBRARY_DIR "$${LLVM_INSTALL_PREFIX}\/lib")
61
62 $(PROJ_OBJ_DIR)/LLVMConfig.cmake: LLVMConfig.cmake.in Makefile $(LLVMBuildCMakeFrag)
63         $(Echo) 'Generating LLVM CMake package config file'
64         $(Verb) ( \
65          cat $< | sed \
66           -e 's/@LLVM_CONFIG_CODE@/$(LLVM_CONFIG_CODE)/' \
67           -e 's/@LLVM_VERSION_MAJOR@/'"$(LLVM_VERSION_MAJOR)"'/' \
68           -e 's/@LLVM_VERSION_MINOR@/'"$(LLVM_VERSION_MINOR)"'/' \
69           -e 's/@LLVM_VERSION_PATCH@/'"$(LLVM_VERSION_PATCH)"'/' \
70           -e 's/@PACKAGE_VERSION@/'"$(LLVMVersion)"'/' \
71           -e 's/@LLVM_COMMON_DEPENDS@//' \
72           -e 's/@LLVM_AVAILABLE_LIBS@/'"$(LLVM_LIBS_TO_EXPORT)"'/' \
73           -e 's/@LLVM_ALL_TARGETS@/'"$(ALL_TARGETS)"'/' \
74           -e 's/@LLVM_TARGETS_TO_BUILD@/'"$(TARGETS_TO_BUILD)"'/' \
75           -e 's/@LLVM_TARGETS_WITH_JIT@/'"$(TARGETS_WITH_JIT)"'/' \
76           -e 's/@TARGET_TRIPLE@/'"$(TARGET_TRIPLE)"'/' \
77           -e 's/@LLVM_ABI_BREAKING_CHECKS@/'"$(LLVM_ABI_BREAKING_CHECKS)"'/' \
78           -e 's/@LLVM_ENABLE_ASSERTIONS@/'"$(LLVM_ENABLE_ASSERTIONS)"'/' \
79           -e 's/@LLVM_ENABLE_EH@/'"$(LLVM_ENABLE_EH)"'/' \
80           -e 's/@LLVM_ENABLE_RTTI@/'"$(LLVM_ENABLE_RTTI)"'/' \
81           -e 's/@LLVM_ENABLE_TERMINFO@/'"$(ENABLE_TERMINFO)"'/' \
82           -e 's/@LLVM_ENABLE_THREADS@/'"$(ENABLE_THREADS)"'/' \
83           -e 's/@LLVM_ENABLE_ZLIB@/'"$(ENABLE_ZLIB)"'/' \
84           -e 's/@LLVM_NATIVE_ARCH@/'"$(LLVM_NATIVE_ARCH)"'/' \
85           -e 's/@LLVM_ENABLE_PIC@/'"$(ENABLE_PIC)"'/' \
86           -e 's/@LLVM_ON_UNIX@/'"$(LLVM_ON_UNIX)"'/' \
87           -e 's/@LLVM_ON_WIN32@/'"$(LLVM_ON_WIN32)"'/' \
88           -e 's/@LLVM_LIBDIR_SUFFIX@//' \
89           -e 's#@LLVM_CONFIG_INCLUDE_DIRS@#$${LLVM_INSTALL_PREFIX}/include#' \
90           -e 's#@LLVM_CONFIG_LIBRARY_DIRS@#$${_LLVM_LIBRARY_DIR}#' \
91           -e 's#@LLVM_CONFIG_CMAKE_DIR@#$${_LLVM_CMAKE_DIR}#' \
92           -e 's#@LLVM_CONFIG_TOOLS_BINARY_DIR@#$${LLVM_INSTALL_PREFIX}/bin#' \
93           -e 's/@LLVM_CONFIG_EXPORTS_FILE@/$${LLVM_CMAKE_DIR}\/LLVMExports.cmake/' \
94           -e 's/@all_llvm_lib_deps@//' \
95          && \
96          ( grep '^set_property.*LLVMBUILD_LIB_DEPS_' "$(LLVMBuildCMakeFrag)" | \
97            grep -v LLVMBUILD_LIB_DEPS_gtest ) && \
98          echo 'unset(_LLVM_CMAKE_DIR)' && \
99          echo 'unset(_LLVM_LIBRARY_DIR)' \
100         ) > $@
101
102 $(PROJ_OBJ_DIR)/LLVMConfigVersion.cmake: LLVMConfigVersion.cmake.in Makefile
103         $(Echo) 'Generating LLVM CMake package version file'
104         $(Verb) cat $< | sed \
105           -e 's/@PACKAGE_VERSION@/'"$(LLVMVersion)"'/' \
106           -e 's/@LLVM_VERSION_MAJOR@/'"$(LLVM_VERSION_MAJOR)"'/' \
107           -e 's/@LLVM_VERSION_MINOR@/'"$(LLVM_VERSION_MINOR)"'/' \
108           -e 's/@LLVM_VERSION_PATCH@/'"$(LLVM_VERSION_PATCH)"'/' \
109           > $@
110
111 $(PROJ_OBJ_DIR)/LLVMExports.cmake: $(LLVMBuildCMakeExportsFrag) Makefile
112         $(Echo) 'Generating LLVM CMake target exports file'
113         $(Verb) ( \
114           echo '# LLVM CMake target exports.  Do not include directly.' && \
115           for lib in $(LLVM_LIBS_TO_EXPORT); do \
116             echo 'add_library('"$$lib"' STATIC IMPORTED)' && \
117             echo 'set_property(TARGET '"$$lib"' PROPERTY IMPORTED_LOCATION "$${_LLVM_LIBRARY_DIR}/'lib$$lib.a'")' ; \
118           done && \
119           cat "$(LLVMBuildCMakeExportsFrag)" && \
120           echo 'set_property(TARGET LLVMSupport APPEND PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES '"$(subst -l,,$(LIBS))"')' \
121         ) > $@
122
123 all-local:: $(addprefix $(PROJ_OBJ_DIR)/, $(OBJMODS))
124
125 SKIPSRCMODS := \
126   CheckAtomic.cmake \
127   GetHostTriple.cmake \
128   LLVMBuildExports.cmake \
129   LLVMConfig.cmake \
130   LLVMConfigVersion.cmake \
131   LLVMExports.cmake \
132   VersionFromVCS.cmake
133
134 SRCMODS := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cmake))
135 SRCMODS := $(filter-out $(SKIPSRCMODS),$(SRCMODS))
136 INSTSRCMODS := $(addprefix $(PROJ_cmake)/, $(SRCMODS))
137 INSTOBJMODS := $(addprefix $(PROJ_cmake)/, $(OBJMODS))
138
139 $(PROJ_cmake):
140         $(Echo) Making install directory: $@
141         $(Verb) $(MKDIR) $@
142
143 $(INSTSRCMODS): $(PROJ_cmake)/%.cmake: $(PROJ_SRC_DIR)/%.cmake | $(PROJ_cmake)
144         $(Echo) Installing cmake modules: $(notdir $<)
145         $(Verb) $(DataInstall) $< $(PROJ_cmake)
146
147 $(INSTOBJMODS): $(PROJ_cmake)/%.cmake: $(PROJ_OBJ_DIR)/%.cmake | $(PROJ_cmake)
148         $(Echo) Installing cmake modules: $(notdir $<)
149         $(Verb) $(DataInstall) $< $(PROJ_cmake)
150
151 install-local:: $(INSTSRCMODS) $(INSTOBJMODS)