Dear clang & CMake maintainers,

I updated the patch as discussed in the previous mails :
- Changed LIBCLANG_LIBRARY_VERSION to also include CINDEX_VERSION_MAJOR and CINDEX_VERSION_MAJOR as they define the libclang API/ABI.

- As adviced by Brad King (CMake maintainer) it's better to use lib/ as folder for package configuration, instead of share/ because it enables arch-specific information to be stored with, as lib/ can be arch specific on linux.

Otherwise it seems that I have to adapt autoreconf files too. I didn't change anything to these until now, but as I plan to do so, do someone know where it would be better to add the generation of libclang package config files in the configure.ac script ?

You can find the updated patch attached, I combined all as a single commit for the convenience of the discussion, but if the history is needed it can be found on github (https://github.com/daminetreg/clang).

@Brad King : What do you think about LIBCLANG_LIBRARY_VERSION as a concatenation of : CINDEX_VERSION_MAJOR.CINDEX_VERSION_MINOR.CLANG_VERSION_MAJOR.CLANG_VERSION_MINOR ? Isn't it a problem that patch and tweak version of the lib are the major, minor of clang ? Is this acceptable, woudln't it be better to go on something like libtool do ?

Don't hesitate to tell me what still need to be done, so that we can eventually get the patch accepted and merged.

Cheers and thanks for your help, :)
--
Damien Buhl
alias daminetreg
>From 13a9210f2cfa1e5d7723f4871fe656f418022cbb Mon Sep 17 00:00:00 2001
From: "Damien Buhl (alias daminetreg)" <[email protected]>
Date: Wed, 13 Mar 2013 22:17:14 +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.

The choice for lib/ instead of share/ for cmake modules is motivated by
Brad King (CMake maintainer) advice to foresee arch-specific
information to be stored with package version file.

To be able to check correctly the libclang version we embed the API/ABI
interface version in LIBCLANG_LIBRARY_VERSION.
---
 CMakeLists.txt                                     |   21 +++++++++++--
 tools/libclang/CMakeLists.txt                      |    2 ++
 tools/libclang/cmake/modules/CMakeLists.txt        |   16 ++++++++++
 .../cmake/modules/libclang-config-version.cmake.in |   16 ++++++++++
 .../cmake/modules/libclang-config.cmake.in         |   31 ++++++++++++++++++++
 5 files changed, 84 insertions(+), 2 deletions(-)
 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/CMakeLists.txt b/CMakeLists.txt
index 6efcd4a..17b6ac0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -266,9 +266,26 @@ add_definitions(-DCLANG_ENABLE_ARCMT -DCLANG_ENABLE_REWRITER -DCLANG_ENABLE_STAT
 set(CLANG_EXECUTABLE_VERSION
      "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
     "Version number that will be placed into the clang executable, in the form XX.YY")
+
+# libclang version information
+FILE (STRINGS include/clang-c/Index.h CINDEX_VERSION_MAJOR_TMP REGEX
+	"^#define CINDEX_VERSION_MAJOR[ \t]+[0-9\\.]+")
+
+string(REGEX REPLACE "#define CINDEX_VERSION_MAJOR[ \t]+"
+	"" CINDEX_VERSION_MAJOR 
+	 ${CINDEX_VERSION_MAJOR_TMP})
+
+FILE (STRINGS include/clang-c/Index.h CINDEX_VERSION_MINOR_TMP REGEX
+	"^#define CINDEX_VERSION_MINOR[ \t]+[0-9\\.]+")
+
+string(REGEX REPLACE "#define CINDEX_VERSION_MINOR[ \t]+"
+	"" CINDEX_VERSION_MINOR 
+	 ${CINDEX_VERSION_MINOR_TMP})
+
 set(LIBCLANG_LIBRARY_VERSION
-     "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
-    "Version number that will be placed into the libclang library , in the form XX.YY")
+	"${CINDEX_VERSION_MAJOR}.${CINDEX_VERSION_MINOR}.${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
+	 "Version number that will be placed into the libclang library , in the form VV.WW.XX.YY, the first two defines ABI/API and the others the clang version the lib comes from")
+ MESSAGE(STATUS "libclang version : ${LIBCLANG_LIBRARY_VERSION}")
 mark_as_advanced(CLANG_EXECUTABLE_VERSION LIBCLANG_LIBRARY_VERSION)
 
 add_subdirectory(utils/TableGen)
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..17fd7e7
--- /dev/null
+++ b/tools/libclang/cmake/modules/CMakeLists.txt
@@ -0,0 +1,16 @@
+set(libclang_cmake_builddir "${CMAKE_BINARY_DIR}/lib/cmake/libclang-${LIBCLANG_LIBRARY_VERSION}")
+
+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 lib/cmake/libclang-${LIBCLANG_LIBRARY_VERSION})
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..e771bb3
--- /dev/null
+++ b/tools/libclang/cmake/modules/libclang-config-version.cmake.in
@@ -0,0 +1,16 @@
+set(PACKAGE_VERSION @LIBCLANG_LIBRARY_VERSION@)
+
+if("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL @CINDEX_VERSION_MAJOR@ AND
+	NOT "${PACKAGE_FIND_VERSION_MINOR}" GREATER @CINDEX_VERSION_MINOR@)
+  set(PACKAGE_VERSION_COMPATIBLE 1)
+
+  # Here CLANG_VERSION_MAJOR and CLANG_VERSION_MINOR corresponds to the
+  # FIND_VERSION_PATCH and FIND_VERSION_TWEAK as we chosed to name the
+  # libclang with the four version components.
+  if("${PACKAGE_FIND_VERSION_MINOR}" EQUAL @CINDEX_VERSION_MINOR@ AND
+	  "${PACKAGE_FIND_VERSION_PATCH}" EQUAL @CLANG_VERSION_MAJOR@ AND
+	  "${PACKAGE_FIND_VERSION_TWEAK}" EQUAL @CLANG_VERSION_MINOR@)
+	  set(PACKAGE_VERSION_EXACT 1)
+  endif()
+
+endif()
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..d4c39a4
--- /dev/null
+++ b/tools/libclang/cmake/modules/libclang-config.cmake.in
@@ -0,0 +1,31 @@
+# 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 your target_link_libraries, e.g:
+#       target_link_libraries(yourTarget 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 @CINDEX_VERSION_MAJOR@)
+set(LIBCLANG_VERSION_MINOR @CINDEX_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")
-- 
1.7.9.5

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to