On 01/22/2014 09:46 PM, Sylvestre Ledru wrote:
> Beside:
> +# TODO: De-duplicate target lists w.r.t. 'autoconf/configure.ac'
[snip]
> It sounds good.  Could you see to fix that?

Since that requires re-running autoconf I went ahead and took care
of the other AC_SUBST updates too.  Updated patch 2 attached.

Note now that the version components go through AC_SUBST this
patch will conflict in autoconf/configure.ac when moved between
versions of LLVM.  I built it on top of 3.4.

This must be followed up by a patch to 'configure' made by running
"autoconf/AutoRegen.sh".  However, I do not have the versions of
the autotools required by that script so the 'configure' generated
on my machine for local testing is not suitable for distribution.

Thanks,
-Brad

>From 83cb7d3898947b7b38eaf6960a3b0022bf0c7266 Mon Sep 17 00:00:00 2001
Message-Id: <83cb7d3898947b7b38eaf6960a3b0022bf0c7266.1390495723.git.brad.k...@kitware.com>
In-Reply-To: <52e08268.2090...@debian.org>
References: <52e08268.2090...@debian.org>
From: Brad King <brad.k...@kitware.com>
Date: Wed, 22 Jan 2014 10:00:50 -0500
Subject: [PATCH] Makefile: Build and install CMake package modules

Teach the Makefile build system to generate and install modules
LLVMConfig.cmake and LLVMConfigVersion.cmake so that applications that
build with CMake can use 'find_package(LLVM)' even when LLVM is not
built with CMake.  These modules tell such applications about available
LLVM libraries and their dependencies.

Run llvm-config to generate the list of libraries and use the results
of LLVMBuild to generate the library dependencies.  Use sed to perform
substitutions in the LLVMConfig.cmake.in and LLVMConfigVersion.cmake.in
sources that our CMake build system uses.

Teach autoconf/configure.ac to AC_SUBST several new values that we need.
---
 Makefile                    |  4 +-
 Makefile.config.in          | 15 ++++++++
 Makefile.rules              | 15 +++++---
 autoconf/configure.ac       | 24 +++++++++---
 autoconf/m4/define_subst.m4 |  5 +++
 cmake/Makefile              | 12 ++++++
 cmake/modules/Makefile      | 90 +++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 152 insertions(+), 13 deletions(-)
 create mode 100644 autoconf/m4/define_subst.m4
 create mode 100644 cmake/Makefile
 create mode 100644 cmake/modules/Makefile

diff --git a/Makefile b/Makefile
index e3672b7..e38cc6d 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@ LEVEL := .
 #   3. Build IR, which builds the Intrinsics.inc file used by libs.
 #   4. Build libs, which are needed by llvm-config.
 #   5. Build llvm-config, which determines inter-lib dependencies for tools.
-#   6. Build tools and docs.
+#   6. Build tools, docs, and cmake modules.
 #
 # When cross-compiling, there are some things (tablegen) that need to
 # be build for the build system first.
@@ -31,7 +31,7 @@ ifeq ($(BUILD_DIRS_ONLY),1)
   OPTIONAL_DIRS := tools/clang/utils/TableGen
 else
   DIRS := lib/Support lib/TableGen utils lib/IR lib tools/llvm-shlib \
-          tools/llvm-config tools docs unittests
+          tools/llvm-config tools docs cmake unittests
   OPTIONAL_DIRS := projects bindings
 endif
 
diff --git a/Makefile.config.in b/Makefile.config.in
index dcca45f..7633be2 100644
--- a/Makefile.config.in
+++ b/Makefile.config.in
@@ -15,6 +15,8 @@
 # Define LLVM specific info and directories based on the autoconf variables
 LLVMPackageName   := @PACKAGE_TARNAME@
 LLVMVersion       := @PACKAGE_VERSION@
+LLVM_VERSION_MAJOR := @LLVM_VERSION_MAJOR@
+LLVM_VERSION_MINOR := @LLVM_VERSION_MINOR@
 LLVM_CONFIGTIME   := @LLVM_CONFIGTIME@
 
 ###########################################################################
@@ -118,6 +120,7 @@ HOST_ARCH=@HOST_ARCH@
 # Target hardware architecture
 ARCH=@ARCH@
 TARGET_NATIVE_ARCH := $(ARCH)
+LLVM_NATIVE_ARCH := @LLVM_NATIVE_ARCH@
 
 # Indicates, whether we're cross-compiling LLVM or not
 LLVM_CROSS_COMPILING=@LLVM_CROSS_COMPILING@
@@ -207,13 +210,22 @@ POD2MAN    := @POD2MAN@
 PDFROFF    := @PDFROFF@
 ZIP        := @ZIP@
 
+HAVE_LIBZ  := @HAVE_LIBZ@
+HAVE_DLOPEN := @HAVE_DLOPEN@
 HAVE_PTHREAD := @HAVE_PTHREAD@
+HAVE_TERMINFO := @HAVE_TERMINFO@
 
 LIBS       := @LIBS@
 
+# Targets that are possible to build
+ALL_TARGETS := @ALL_TARGETS@
+
 # Targets that we should build
 TARGETS_TO_BUILD=@TARGETS_TO_BUILD@
 
+# Targets supporting JIT
+TARGETS_WITH_JIT := @TARGETS_WITH_JIT@
+
 # Path to directory where object files should be stored during a build.
 # Set OBJ_ROOT to "." if you do not want to use a separate place for
 # object files.
@@ -250,6 +262,9 @@ ENABLE_CLANG_STATIC_ANALYZER = @ENABLE_CLANG_STATIC_ANALYZER@
 # When ENABLE_WERROR is enabled, we'll pass -Werror on the command line
 ENABLE_WERROR = @ENABLE_WERROR@
 
+# When ENABLE_TERMINFO is enabled, we use terminfo.
+ENABLE_TERMINFO = @ENABLE_TERMINFO@
+
 # When ENABLE_OPTIMIZED is enabled, LLVM code is optimized and output is put
 # into the "Release" directories. Otherwise, LLVM code is not optimized and
 # output is put in the "Debug" directories.
diff --git a/Makefile.rules b/Makefile.rules
index 68f6cf8..0355ca7 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -78,6 +78,10 @@ LLVMBuildTool	:= $(PROJ_SRC_ROOT)/utils/llvm-build/llvm-build
 
 # The files we are going to generate using llvm-build.
 LLVMBuildMakeFrag := $(PROJ_OBJ_ROOT)/Makefile.llvmbuild
+LLVMBuildCMakeFrag := $(PROJ_OBJ_ROOT)/LLVMBuild.cmake
+LLVMBuildMakeFrags := \
+	$(LLVMBuildMakeFrag) \
+	$(LLVMBuildCMakeFrag)
 LLVMConfigLibraryDependenciesInc := \
 	$(PROJ_OBJ_ROOT)/tools/llvm-config/LibraryDependencies.inc
 
@@ -94,18 +98,19 @@ endif
 #
 # We include a dependency on this Makefile to ensure that changes to the
 # generation command get picked up.
-$(LLVMBuildMakeFrag): $(PROJ_SRC_ROOT)/Makefile.rules \
-		      $(PROJ_OBJ_ROOT)/Makefile.config
+$(LLVMBuildMakeFrags): $(PROJ_SRC_ROOT)/Makefile.rules \
+		       $(PROJ_OBJ_ROOT)/Makefile.config
 	$(Echo) Constructing LLVMBuild project information.
 	$(Verb)$(PYTHON) $(LLVMBuildTool) \
 	  --native-target "$(TARGET_NATIVE_ARCH)" \
 	  --enable-targets "$(TARGETS_TO_BUILD)" \
 	  --enable-optional-components "$(OPTIONAL_COMPONENTS)" \
 	  --write-library-table $(LLVMConfigLibraryDependenciesInc) \
-	  --write-make-fragment $(LLVMBuildMakeFrag)
+	  --write-make-fragment $(LLVMBuildMakeFrag) \
+	  --write-cmake-fragment $(LLVMBuildCMakeFrag)
 
 # For completeness, let Make know how the extra files are generated.
-$(LLVMConfigLibraryDependenciesInc): $(LLVMBuildMakeFrag)
+$(LLVMConfigLibraryDependenciesInc): $(LLVMBuildMakeFrags)
 
 # Include the generated Makefile fragment.
 #
@@ -120,7 +125,7 @@ LLVMBUILD_INCLUDE_DEPENDENCIES := 1
 
 # Clean the generated makefile fragment at the top-level.
 clean-local::
-	-$(Verb) $(RM) -f $(LLVMBuildMakeFrag)
+	-$(Verb) $(RM) -f $(LLVMBuildMakeFrags)
 endif
 -include $(LLVMBuildMakeFrag)
 
diff --git a/autoconf/configure.ac b/autoconf/configure.ac
index a9d4915..47826ce 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -32,8 +32,8 @@ dnl===-----------------------------------------------------------------------===
 dnl Initialize autoconf and define the package name, version number and
 dnl address for reporting bugs.
 AC_INIT([LLVM],[3.4],[http://llvm.org/bugs/])
-AC_DEFINE([LLVM_VERSION_MAJOR], [3], [Major version of the LLVM API])
-AC_DEFINE([LLVM_VERSION_MINOR], [4], [Minor version of the LLVM API])
+LLVM_DEFINE_SUBST([LLVM_VERSION_MAJOR], [3], [Major version of the LLVM API])
+LLVM_DEFINE_SUBST([LLVM_VERSION_MINOR], [4], [Minor version of the LLVM API])
 
 dnl Provide a copyright substitution and ensure the copyright notice is included
 dnl in the output of --version option of the generated configure script.
@@ -425,6 +425,7 @@ esac
 
 dnl Define a substitution, ARCH, for the target architecture
 AC_SUBST(ARCH,$llvm_cv_target_arch)
+AC_SUBST(LLVM_NATIVE_ARCH,$LLVM_NATIVE_ARCH)
 
 dnl Determine what our host architecture.
 dnl This will allow MCJIT regress tests runs only for supported
@@ -683,6 +684,9 @@ else
   esac
 fi
 
+TARGETS_WITH_JIT="AArch64 ARM Mips PowerPC SystemZ X86"
+AC_SUBST(TARGETS_WITH_JIT,$TARGETS_WITH_JIT)
+
 dnl Allow enablement of building and installing docs
 AC_ARG_ENABLE(docs,
               AS_HELP_STRING([--enable-docs],
@@ -832,6 +836,10 @@ if test "$llvm_cv_enable_crash_overrides" = "yes" ; then
             [Define to enable crash handling overrides])
 fi
 
+dnl List all possible targets
+ALL_TARGETS="X86 Sparc PowerPC AArch64 ARM Mips XCore MSP430 CppBackend NVPTX Hexagon SystemZ R600"
+AC_SUBST(ALL_TARGETS,$ALL_TARGETS)
+
 dnl Allow specific targets to be specified for building (or not)
 TARGETS_TO_BUILD=""
 AC_ARG_ENABLE([targets],AS_HELP_STRING([--enable-targets],
@@ -843,7 +851,7 @@ if test "$enableval" = host-only ; then
   enableval=host
 fi
 case "$enableval" in
-  all) TARGETS_TO_BUILD="X86 Sparc PowerPC AArch64 ARM Mips XCore MSP430 CppBackend NVPTX Hexagon SystemZ R600" ;;
+  all) TARGETS_TO_BUILD="$ALL_TARGETS" ;;
   *)for a_target in `echo $enableval|sed -e 's/,/ /g' ` ; do
       case "$a_target" in
         x86)      TARGETS_TO_BUILD="X86 $TARGETS_TO_BUILD" ;;
@@ -1104,6 +1112,10 @@ AC_ARG_ENABLE(terminfo,AS_HELP_STRING(
     *) AC_MSG_ERROR([Invalid setting for --enable-terminfo. Use "yes" or "no"]) ;;
   esac],
   llvm_cv_enable_terminfo="yes")
+case "$llvm_cv_enable_terminfo" in
+  yes) AC_SUBST(ENABLE_TERMINFO,[1]) ;;
+  no)  AC_SUBST(ENABLE_TERMINFO,[0]) ;;
+esac
 
 dnl --enable-libffi : check whether the user wants to turn off libffi:
 AC_ARG_ENABLE(libffi,AS_HELP_STRING(
@@ -1404,7 +1416,7 @@ if test "$llvm_cv_os_type" = "MingW" ; then
 fi
 
 dnl dlopen() is required for plugin support.
-AC_SEARCH_LIBS(dlopen,dl,AC_DEFINE([HAVE_DLOPEN],[1],
+AC_SEARCH_LIBS(dlopen,dl,LLVM_DEFINE_SUBST([HAVE_DLOPEN],[1],
                [Define if dlopen() is available on this platform.]),
                AC_MSG_WARN([dlopen() not found - disabling plugin support]))
 
@@ -1417,8 +1429,8 @@ dnl The curses library is optional; used for querying terminal info
 if test "$llvm_cv_enable_terminfo" = "yes" ; then
   dnl We need the has_color functionality in curses for it to be useful.
   AC_SEARCH_LIBS(setupterm,tinfo terminfo curses ncurses ncursesw,
-                 AC_DEFINE([HAVE_TERMINFO],[1],
-                           [Define if the setupterm() function is supported this platform.]))
+                 LLVM_DEFINE_SUBST([HAVE_TERMINFO],[1],
+                                   [Define if the setupterm() function is supported this platform.]))
 fi
 
 dnl libffi is optional; used to call external functions from the interpreter
diff --git a/autoconf/m4/define_subst.m4 b/autoconf/m4/define_subst.m4
new file mode 100644
index 0000000..c66333f
--- /dev/null
+++ b/autoconf/m4/define_subst.m4
@@ -0,0 +1,5 @@
+# Combine AC_DEFINE and AC_SUBST
+AC_DEFUN([LLVM_DEFINE_SUBST], [
+AC_DEFINE([$1], [$2], [$3])
+AC_SUBST([$1], ['$2'])
+])
diff --git a/cmake/Makefile b/cmake/Makefile
new file mode 100644
index 0000000..523cd45
--- /dev/null
+++ b/cmake/Makefile
@@ -0,0 +1,12 @@
+##===- cmake/Makefile --------------------------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+LEVEL = ..
+DIRS := modules
+
+include $(LEVEL)/Makefile.common
diff --git a/cmake/modules/Makefile b/cmake/modules/Makefile
new file mode 100644
index 0000000..78934e9
--- /dev/null
+++ b/cmake/modules/Makefile
@@ -0,0 +1,90 @@
+##===- cmake/modules/Makefile ------------------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../..
+
+LINK_COMPONENTS := all
+
+include $(LEVEL)/Makefile.common
+
+PROJ_cmake := $(DESTDIR)$(PROJ_prefix)/share/llvm/cmake
+
+OBJMODS := LLVMConfig.cmake LLVMConfigVersion.cmake
+
+# TODO: Teach LLVM-Config.cmake to work without explicit terminfo libs.
+TERMINFO_LIBS := tinfo terminfo curses ncurses ncursesw
+TERMINFO_LIBS := $(filter $(TERMINFO_LIBS),$(subst -l,,$(LIBS)))
+
+$(PROJ_OBJ_DIR)/LLVMConfig.cmake: LLVMConfig.cmake.in $(LLVMBuildCMakeFrag)
+	$(Echo) 'Generating LLVM CMake package config file'
+	$(Verb) ( \
+	 cat $< | sed \
+	  -e 's/@LLVM_VERSION_MAJOR@/'"$(LLVM_VERSION_MAJOR)"'/' \
+	  -e 's/@LLVM_VERSION_MINOR@/'"$(LLVM_VERSION_MINOR)"'/' \
+	  -e 's/@PACKAGE_VERSION@/'"$(LLVMVersion)"'/' \
+	  -e 's/@LLVM_COMMON_DEPENDS@//' \
+	  -e 's/"@llvm_libs@"/'"$(subst -l,,$(LLVMConfigLibs))"'/' \
+	  -e 's/@LLVM_ALL_TARGETS@/'"$(ALL_TARGETS)"'/' \
+	  -e 's/@LLVM_TARGETS_TO_BUILD@/'"$(TARGETS_TO_BUILD)"'/' \
+	  -e 's/@LLVM_TARGETS_WITH_JIT@/'"$(TARGETS_WITH_JIT)"'/' \
+	  -e 's/@TARGET_TRIPLE@/'"$(TARGET_TRIPLE)"'/' \
+	  -e 's/@LLVM_TOOLS_BINARY_DIR@/'"$(subst /,\/,$(PROJ_bindir))"'/' \
+	  -e 's/@LLVM_ENABLE_TERMINFO@/'"$(ENABLE_TERMINFO)"'/' \
+	  -e 's/@LLVM_ENABLE_THREADS@/'"$(ENABLE_THREADS)"'/' \
+	  -e 's/@LLVM_ENABLE_ZLIB@/'"$(ENABLE_ZLIB)"'/' \
+	  -e 's/@LLVM_NATIVE_ARCH@/'"$(LLVM_NATIVE_ARCH)"'/' \
+	  -e 's/@LLVM_ENABLE_PIC@/'"$(ENABLE_PIC)"'/' \
+	  -e 's/@HAVE_TERMINFO@/'"$(HAVE_TERMINFO)"'/' \
+	  -e 's/@TERMINFO_LIBS@/'"$(TERMINFO_LIBS)"'/' \
+	  -e 's/@HAVE_LIBDL@/'"$(HAVE_DLOPEN)"'/' \
+	  -e 's/@HAVE_LIBPTHREAD@/'"$(HAVE_PTHREAD)"'/' \
+	  -e 's/@HAVE_LIBZ@/'"$(HAVE_LIBZ)"'/' \
+	  -e 's/@LLVM_ON_UNIX@/'"$(LLVM_ON_UNIX)"'/' \
+	  -e 's/@LLVM_ON_WIN32@/'"$(LLVM_ON_WIN32)"'/' \
+	  -e 's/@LLVM_INSTALL_PREFIX@/'"$(subst /,\/,$(PROJ_prefix))"'/' \
+	  -e 's/@all_llvm_lib_deps@//' \
+	 && \
+	 # TODO: Teach LLVM-Config.cmake to use builtin CMake features     \
+	 # for library dependencies.  For now add the generated fragments. \
+	 grep '^set_property.*LLVMBUILD_LIB_DEPS_' "$(LLVMBuildCMakeFrag)" \
+	) > $@
+
+$(PROJ_OBJ_DIR)/LLVMConfigVersion.cmake: LLVMConfigVersion.cmake.in
+	$(Echo) 'Generating LLVM CMake package version file'
+	$(Verb) cat $< | sed \
+	  -e 's/@PACKAGE_VERSION@/'"$(LLVMVersion)"'/' \
+	  > $@
+
+all-local:: $(addprefix $(PROJ_OBJ_DIR)/, $(OBJMODS))
+
+SKIPSRCMODS := \
+  CheckAtomic.cmake \
+  GetHostTriple.cmake \
+  LLVMConfig.cmake \
+  LLVMConfigVersion.cmake \
+  VersionFromVCS.cmake
+
+SRCMODS := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cmake))
+SRCMODS := $(filter-out $(SKIPSRCMODS),$(SRCMODS))
+INSTSRCMODS := $(addprefix $(PROJ_cmake)/, $(SRCMODS))
+INSTOBJMODS := $(addprefix $(PROJ_cmake)/, $(OBJMODS))
+
+$(PROJ_cmake):
+	$(Echo) Making install directory: $@
+	$(Verb) $(MKDIR) $@
+
+$(INSTSRCMODS): $(PROJ_cmake)/%.cmake: $(PROJ_SRC_DIR)/%.cmake | $(PROJ_cmake)
+	$(Echo) Installing cmake modules: $(notdir $<)
+	$(Verb) $(DataInstall) $< $(PROJ_cmake)
+
+$(INSTOBJMODS): $(PROJ_cmake)/%.cmake: $(PROJ_OBJ_DIR)/%.cmake | $(PROJ_cmake)
+	$(Echo) Installing cmake modules: $(notdir $<)
+	$(Verb) $(DataInstall) $< $(PROJ_cmake)
+
+install-local:: $(INSTSRCMODS) $(INSTOBJMODS)
-- 
1.8.5.2

Reply via email to