Improving support for CMake-based applications

NAKAMURA Takumi geek4civic at gmail.com
Mon Jan 27 08:29:55 PST 2014


Hello Brad,

Thanks for your great work, and I am happy since I know you are one of
CMake core developers.
I am certain your contributes could be merged.

I am sorry I am lazy not to respond you soon.
Excuse me, for now, I am speaking to browse your patches grossly.

I have been playing to tweak to let Clang FindPackage-friendly.
FYI, my tweaks, working in progress
  -- https://github.com/chapuni/llvm-project/commits/cmake/sa/trunk

I have a few questions.

  - Could you introduce me how to write FindPackage-friendly
cmakefiles for developers?
  - Would it be better to add stuff in LLVMConfig.cmake?
    - list(APPEND CMAKE_MODULE_PATH)
    - include_directories(${LLVM_INCLUDE_DIRS})
    - link_directories(${LLVM_LIBRAY_DIRS})

I think LLVMBuild part in 0008 is less invasive. I'd like to ask Daniel Dunbar.

Eric, how do you think 0007 and 0008?

I'd like more time to comment to other patches, thank you.

...Takumi

--- a/llvm/cmake/modules/CMakeLists.txt
+++ b/llvm/cmake/modules/CMakeLists.txt
@@ -10,6 +9,24 @@ foreach(lib ${llvm_libs})
     "${all_llvm_lib_deps}\nset_property(GLOBAL PROPERTY
LLVMBUILD_LIB_DEPS_${lib} ${llvm_lib_deps})")
 endforeach(lib)

+# Generate LLVMConfig.cmake for the build tree.
+set(LLVM_CONFIG_CODE "
+# LLVM_BUILD_* values available only from LLVM build tree.
+set(LLVM_BUILD_BINARY_DIR \"${LLVM_BINARY_DIR}\")
+set(LLVM_BUILD_ENABLE_ASSERTIONS \"${LLVM_ENABLE_ASSERTIONS}\")
+set(LLVM_BUILD_LIBRARY_DIR \"${LLVM_LIBRARY_DIR}\")
+set(LLVM_BUILD_MAIN_INCLUDE_DIR \"${LLVM_MAIN_INCLUDE_DIR}\")
+set(LLVM_BUILD_MAIN_SRC_DIR \"${LLVM_MAIN_SRC_DIR}\")
+set(LLVM_BUILD_TOOLS_BINARY_DIR \"${LLVM_TOOLS_BINARY_DIR}\")
+")
+set(LLVM_CONFIG_INCLUDE_DIRS
+  "${LLVM_MAIN_INCLUDE_DIR}"
+  "${LLVM_INCLUDE_DIR}"
+  )

For historical reasons, we prefer to seek build tree at first in INCLUDE_DIRS.
See also https://github.com/chapuni/llvm-project/commit/8a09aaa4c07fc9fdd1b4a63d7accc8ccf3389032

+set(LLVM_CONFIG_LIBRARY_DIRS
+  "${LLVM_LIBRARY_DIR}"
+  )
+set(LLVM_CONFIG_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
 configure_file(
   LLVMConfig.cmake.in
   ${llvm_cmake_builddir}/LLVMConfig.cmake

2014-01-25 Brad King <brad.king at kitware.com>:
> Hi Folks,
>
> CMake's preferred way for applications to locate their dependencies is
>
>  find_package(LLVM)
>
> This is supported by LLVM as documented here:
>
>  http://llvm.org/docs/CMake.html#embedding-llvm-in-your-project
>
> by providing the "LLVMConfig.cmake" package configuration file
> (which is distinct from the LLVM-Config API module).
>
> However, the LLVMConfig.cmake currently provided by LLVM does not
> cleanly distinguish between coming with the build tree v. the install
> tree.  It is also not provided at all by the Makefile-based build
> system.
>
> Here is a patch series to improve the CMake package infrastructure:
>
> * Create separate LLVMConfig.cmake for the build and install trees
>   each with relevant settings when building with CMake.
>
> * Use the CMake export() and install(EXPORT) commands to "export"
>   library target names and dependencies for import into applications.
>   This allows application CMake code to reference LLVM libraries by
>   logical name and CMake will handle mapping to the real library
>   (e.g. "LLVMSupport" => "/path/to/lib/libLLVMSupport.a").
>
>   It also communicates library dependencies (from llvm-build) to
>   applications in a way that CMake builtin features understand.
>   A follow-up to this series will use this feature to avoid explicit
>   handling of dependencies and system libraries in LLVM-Config.cmake.
>
> * Provide LLVMConfig.cmake for the install tree when building with
>   the Makefile-based build system.  This will allow applications
>   to build with CMake using find_package(LLVM) even when LLVM was
>   not built with CMake.
>
> This patch series is based on trunk as of r200018.  It must be
> followed up by a patch 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
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>



More information about the llvm-commits mailing list