On 01/18/2014 10:54 AM, Sylvestre Ledru wrote: > Maybe there is a way to generate this file with the autotools?
Yes, and here are patches to do so. I built these on top of the 3.4 release: llvm/branches/release_34@197944 They also correctly work on top of a recent trunk: llvm/trunk@199058 They should work for r197556. The latter patch contains some hacks to avoid re-running autoconf so it can be simplified if it goes upstream as noted in the TODO comments. -Brad
>From deeda6e64171bff53b96d6d32f54f4741b1a0da9 Mon Sep 17 00:00:00 2001 Message-Id: <deeda6e64171bff53b96d6d32f54f4741b1a0da9.1390405404.git.brad.k...@kitware.com> In-Reply-To: <52daa3d3.8030...@debian.org> References: <52daa3d3.8030...@debian.org> From: Brad King <brad.k...@kitware.com> Date: Tue, 21 Jan 2014 09:50:53 -0500 Subject: [PATCH 1/2] Simplify LLVMConfig.cmake inclusion of LLVM-Config module The LLVMConfig.cmake file we generate already hard-codes include and lib paths under the install prefix and therefore works only from the install tree. Simply include LLVM-Config from the location it is known to be installed. In the future we could configure a separate LLVMConfig.cmake to work in the build tree. --- cmake/modules/LLVMConfig.cmake.in | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/cmake/modules/LLVMConfig.cmake.in b/cmake/modules/LLVMConfig.cmake.in index 68fe296..32d1c7f 100644 --- a/cmake/modules/LLVMConfig.cmake.in +++ b/cmake/modules/LLVMConfig.cmake.in @@ -43,16 +43,4 @@ set(LLVM_INCLUDE_DIRS ${LLVM_INSTALL_PREFIX}/include) set(LLVM_LIBRARY_DIRS ${LLVM_INSTALL_PREFIX}/lib) set(LLVM_DEFINITIONS "-D__STDC_LIMIT_MACROS" "-D__STDC_CONSTANT_MACROS") -# We try to include using the current setting of CMAKE_MODULE_PATH, -# which suppossedly was filled by the user with the directory where -# this file was installed: -include( LLVM-Config OPTIONAL RESULT_VARIABLE LLVMCONFIG_INCLUDED ) - -# If failed, we assume that this is an un-installed build: -if( NOT LLVMCONFIG_INCLUDED ) - set(CMAKE_MODULE_PATH - ${CMAKE_MODULE_PATH} - "@LLVM_SOURCE_DIR@/cmake/modules") - include( LLVM-Config ) -endif() - +include(${LLVM_INSTALL_PREFIX}/share/llvm/cmake/LLVM-Config.cmake) -- 1.8.5.2
>From b9ac38eeed2946b61c3e0d63c0510129cf677a21 Mon Sep 17 00:00:00 2001 Message-Id: <b9ac38eeed2946b61c3e0d63c0510129cf677a21.1390405404.git.brad.k...@kitware.com> In-Reply-To: <52daa3d3.8030...@debian.org> References: <52daa3d3.8030...@debian.org> From: Brad King <brad.k...@kitware.com> Date: Wed, 22 Jan 2014 10:00:50 -0500 Subject: [PATCH 2/2] 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. Several values that we need are not AC_SUBST'd by autoconf/configure.ac so parse them out of include/llvm/Config/config.h for now and leave TODO comments. --- Makefile | 4 +- Makefile.config.in | 1 + Makefile.rules | 15 ++++--- cmake/Makefile | 12 ++++++ cmake/modules/Makefile | 103 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 128 insertions(+), 7 deletions(-) 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..2d8d613 100644 --- a/Makefile.config.in +++ b/Makefile.config.in @@ -207,6 +207,7 @@ POD2MAN := @POD2MAN@ PDFROFF := @PDFROFF@ ZIP := @ZIP@ +HAVE_LIBZ := @HAVE_LIBZ@ HAVE_PTHREAD := @HAVE_PTHREAD@ LIBS := @LIBS@ 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/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..f357567 --- /dev/null +++ b/cmake/modules/Makefile @@ -0,0 +1,103 @@ +##===- 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: Remove this when 'autoconf/configure.ac' is updated as below +LLVM_config_h := $(LLVM_OBJ_ROOT)/include/llvm/Config/config.h + +# TODO: De-duplicate target lists w.r.t. 'autoconf/configure.ac' +LLVM_TARGETS_WITH_JIT := AArch64 ARM Mips PowerPC SystemZ X86 +LLVM_ALL_TARGETS := AArch64 ARM CppBackend Hexagon Mips MSP430 NVPTX PowerPC R600 Sparc SystemZ X86 XCore + +# TODO: Teach 'autoconf/configure.ac' to AC_SUBST these values +HAVE_LIBDL := $(shell grep '\#define HAVE_LIBDL ' "$(LLVM_config_h)" | sed 's/\#define HAVE_LIBDL *//') +HAVE_TERMINFO := $(shell grep '\#define HAVE_TERMINFO ' "$(LLVM_config_h)" | sed 's/\#define HAVE_TERMINFO *//') +LLVM_NATIVE_ARCH := $(shell grep '\#define LLVM_NATIVE_ARCH ' "$(LLVM_config_h)" | sed 's/\#define LLVM_NATIVE_ARCH *//') +LLVM_VERSION_MAJOR := $(shell grep '\#define LLVM_VERSION_MAJOR ' "$(LLVM_config_h)" | sed 's/\#define LLVM_VERSION_MAJOR *//') +LLVM_VERSION_MINOR := $(shell grep '\#define LLVM_VERSION_MINOR ' "$(LLVM_config_h)" | sed 's/\#define LLVM_VERSION_MINOR *//') +TERMINFO_LIBS := tinfo terminfo curses ncurses ncursesw +TERMINFO_LIBS := $(filter $(TERMINFO_LIBS),$(subst -l,,$(LIBS))) +ENABLE_TERMINFO := $(HAVE_TERMINFO) + +$(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@/'"$(LLVM_ALL_TARGETS)"'/' \ + -e 's/@LLVM_TARGETS_TO_BUILD@/'"$(TARGETS_TO_BUILD)"'/' \ + -e 's/@LLVM_TARGETS_WITH_JIT@/'"$(LLVM_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_LIBDL)"'/' \ + -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