Dear Chandler Carruth,
I forgot one single line (didn't add it to the git commit) in the
previous patch to include the change I made to the CMakeLists.txt of
libclang which performs the add_subdirectory of the cmake/modules
CMakeLists.txt.
Please find the updated patch attached.
Cheers,
--
Damien Buhl
alias daminetreg
On 02/22/2013 01:27 AM, Damien Buhl wrote:
Dear Chandler Carruth,
I'm sending you a patch today, which adds a CMake package configuration
file for libclang. So that others CMake based project can easily find
libclang and link to it, as we are used to with CMake :
find_package(libclang 3.2 REQUIRED)
link_directories(${LIBCLANG_LIBRARY_DIRS})
include_directories(${LIBCLANG_INCLUDE_DIRS})
add_definitions(${LIBCLANG_DEFINITIONS})
I'm sending you this patch, because I first proposed a FindLibClang to
the CMake project, but as Brad King from Kitware told me that it would
be better for libclang to provide a package configuration file; I
decided to drop my FindLibClang (See the pull request :
https://github.com/Kitware/CMake/pull/34).
The patch simply adds a configuration and install step for
libclang-config.cmake and libclang-config-version.cmake.
The libclang-config.cmake provides the LIBCLANG_INCLUDE_DIRS,
LIBCLANG_LIBRARY_DIRS, LIBCLANG_DEFINITIONS variables.
I decided to hardcode LIBCLANG_DEFINITIONS to "-D__STDC_LIMIT_MACROS"
"-D__STDC_CONSTANT_MACROS", instead of using something like list(APPEND
@LLVM_DEFINITIONS@ ...), because I think it's the more correct decision
since clang is a separate project based on llvm, but isn't fully part of
it (i.e. Neither the same git repository nor a git submodule of llvm).
That's why I made the supposition that it's not set in stone that both
llvm and clang will always share the same #defines in the future.
Perhaps I misinterpreted something here, so don't hesitate to ask me to
change this to the non hardcoded variant.
The other file libclang-config-version.cmake simply checks that the
requested version is totally exact (major and minor) to the one of the
installed library. It's currently checking for exact equality, because I
didn't find anything in the documentation telling that the API stays
backward compatible accross minor versions. Is it the case ?
On our side we are already using this patch to integrate libclang in our
build. We use libclang as a c++ parser for a tool generating interfaces
and bindings between different programming languages. Until now we were
using gcc plugins to extract the information from c++ code, but it was
such a hell of macros and of #pragma poison, that we wanted to change to
something cleaner, and libclang has a so nice API, that we moved.
Thank you alot for the nice work done on llvm and clang, these projects
are drastically changing the day-to-day work of many developers I know. :)
Cheers,
--
Damien Buhl
alias daminetreg
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>From 18746ec00061375ab348f995e68a5ca19369f2d7 Mon Sep 17 00:00:00 2001
From: "Damien Buhl (alias daminetreg)" <[email protected]>
Date: Fri, 22 Feb 2013 01:47:29 +0100
Subject: [PATCH] Adds a CMake package configuration file for libclang, so
that library users from CMake based project can configure
their dependency to libclang easily.
Signed-off-by: Damien Buhl (alias daminetreg) <[email protected]>
---
tools/libclang/CMakeLists.txt | 2 ++
tools/libclang/cmake/modules/CMakeLists.txt | 17 ++++++++++
.../cmake/modules/libclang-config-version.cmake.in | 9 ++++++
.../cmake/modules/libclang-config.cmake.in | 33 ++++++++++++++++++++
4 files changed, 61 insertions(+)
create mode 100644 tools/libclang/cmake/modules/CMakeLists.txt
create mode 100644 tools/libclang/cmake/modules/libclang-config-version.cmake.in
create mode 100644 tools/libclang/cmake/modules/libclang-config.cmake.in
diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt
index dd4eccf..31ab8c4 100644
--- a/tools/libclang/CMakeLists.txt
+++ b/tools/libclang/CMakeLists.txt
@@ -1,3 +1,5 @@
+add_subdirectory(cmake/modules)
+
set(LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
asmparser
diff --git a/tools/libclang/cmake/modules/CMakeLists.txt b/tools/libclang/cmake/modules/CMakeLists.txt
new file mode 100644
index 0000000..c733284
--- /dev/null
+++ b/tools/libclang/cmake/modules/CMakeLists.txt
@@ -0,0 +1,17 @@
+set(libclang_cmake_builddir "${CMAKE_BINARY_DIR}/share/clang/cmake")
+set(LLVM_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
+
+configure_file (
+ libclang-config.cmake.in
+ ${libclang_cmake_builddir}/libclang-config.cmake
+ @ONLY)
+
+configure_file (
+ libclang-config-version.cmake.in
+ ${libclang_cmake_builddir}/libclang-config-version.cmake
+ @ONLY)
+
+install(FILES
+ ${libclang_cmake_builddir}/libclang-config.cmake
+ ${libclang_cmake_builddir}/libclang-config-version.cmake
+ DESTINATION share/clang/cmake)
diff --git a/tools/libclang/cmake/modules/libclang-config-version.cmake.in b/tools/libclang/cmake/modules/libclang-config-version.cmake.in
new file mode 100644
index 0000000..50dffd3
--- /dev/null
+++ b/tools/libclang/cmake/modules/libclang-config-version.cmake.in
@@ -0,0 +1,9 @@
+set(PACKAGE_VERSION @LIBCLANG_LIBRARY_VERSION@)
+if("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL @CLANG_VERSION_MAJOR@)
+ set(PACKAGE_VERSION_COMPATIBLE 1)
+
+ if("${PACKAGE_FIND_VERSION_MINOR}" EQUAL @CLANG_VERSION_MINOR@)
+ set(PACKAGE_VERSION_EXACT 1)
+ endif("${PACKAGE_FIND_VERSION_MINOR}" EQUAL @CLANG_VERSION_MINOR@)
+
+endif("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL @CLANG_VERSION_MAJOR@)
diff --git a/tools/libclang/cmake/modules/libclang-config.cmake.in b/tools/libclang/cmake/modules/libclang-config.cmake.in
new file mode 100644
index 0000000..a704cb3
--- /dev/null
+++ b/tools/libclang/cmake/modules/libclang-config.cmake.in
@@ -0,0 +1,33 @@
+# libclang @LIBCLANG_LIBRARY_VERSION@ - CMake Package Configuration File
+#
+# To use libclang in your software, simply add the following to your
+# CMakeLists.txt :
+#
+# find_package(libclang @LIBCLANG_LIBRARY_VERSION@ REQUIRED)
+# link_directories(${LIBCLANG_LIBRARY_DIRS})
+# include_directories(${LIBCLANG_INCLUDE_DIRS})
+# add_definitions(${LIBCLANG_DEFINITIONS})
+#
+# Once this done you can simply add *clang* to you target_link_libraries, e.g:
+# target_link_libraries(youTarget clang)
+#
+# In case you have installed an LLVM version which was compiled without
+# defining REQUIRES_RTTI=1, then you are probably getting problems with
+# missing typeid symbols (i.e. of the mangled form : _ZTIN5[...]E) when the
+# dynamic linker resolve symbols in your binary.
+#
+# To solve the issue, find a version of llvm and clang compiled with rtti
+# enabled, because this should be the case for released clang versions.
+# (c.f. llvm/docs/Packaging.rst)
+#
+
+set(LIBCLANG_VERSION_MAJOR @CLANG_VERSION_MAJOR@)
+set(LIBCLANG_VERSION_MINOR @CLANG_VERSION_MINOR@)
+set(LIBCLANG_PACKAGE_VERSION @LIBCLANG_LIBRARY_VERSION@)
+
+set(LIBCLANG_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@")
+set(LIBCLANG_INCLUDE_DIRS ${LIBCLANG_INSTALL_PREFIX}/include)
+set(LIBCLANG_LIBRARY_DIRS ${LIBCLANG_INSTALL_PREFIX}/lib)
+set(LIBCLANG_DEFINITIONS "-D__STDC_LIMIT_MACROS" "-D__STDC_CONSTANT_MACROS")
+
+message(STATUS "libclang version: ${LIBCLANG_PACKAGE_VERSION}")
--
1.7.9.5
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits