Browse Source

Merge pull request #3 from cppit/master

pull from cppit
merge-requests/37/head
Ole Christian Eidheim 11 years ago
parent
commit
1853a9f6a4
  1. 8
      CMakeLists.txt
  2. 94
      README.md
  3. 13
      docs/install.md
  4. 6
      src/CMakeLists.txt
  5. 13
      src/docs/windows-install.md

8
CMakeLists.txt

@ -1,13 +1,15 @@
cmake_minimum_required (VERSION 2.8.4)
set(project_name clangmm)
project(${project_name})
set(library_installation_path "/usr/local/lib/libclangmm/")
set(library_path "/usr/local/lib/")
set(include_path "/usr/local/include/")
if(APPLE)
set(Boost_USE_STATIC_LIBS "YES")
set(CMAKE_MACOSX_RPATH 1)
endif()
enable_testing()
add_subdirectory(src)
add_subdirectory(tests)
# enable_testing()
# add_subdirectory(tests)

94
README.md

@ -1,96 +1,30 @@
# libclangmm - An easy to use C++-wrapper for libclang #
## About ##
This project is written by *cppit* as part of an bachelor thesis
This is a highlevel wrapper for [libclang](http://www.llvm.org). It
provides highlevel C++11 access to complicated C code.
# Install #
This section describes how to install this library on your system. The section below is tested in on unix based systems and in windows. If there are any problems please create an issue and we will look into it.
## Dependencies ##
Please install these dependencies on your system.
* libclang
* cmake
* make
* clang or gcc (compiler)
## Download the source ##
There are two ways of downloading the source
### Download the zip ###
You can download the zip [here](https://github.com/cppit/libclangmm/archive/master.zip).
### Cloning the repository ###
```sh
$ git clone https://github.com/cppit/libclangmm.git
```
## Installation ##
See [installation guide](https://github.com/cppit/libclangmm/blob/master/docs/install.md)
### Quickstart ###
```sh
$ cmake .
$ make install
$ git clone https://github.com/cppit/libclangmm.git clangmm
$ cd clangmm
$ make
$ sudo make install
```
**Notice:** *make install* needs root privileges
# Usage #
One quick start:
```cpp
// lets say it is empty
std::string path("your file here");
clang::Index index(0, 0);
clang::TranslationUnit tu(&index, path);
// ReparseTranslationUnit takes a map with filepath as key
// and buffer as value
std::map<std::string, std::string> buffers;
// create buffer (this would normally be a gtk/qt-buffer or something)
std::string file;
file.append("#include <iostream>");
file.append("int main(int argc, char *argv[]) {\n");
file.append("std::cout << \"Hello World!\" << std::endl;\n");
file.append("return 0\n");
file.append("}");
buffers[path] = file;
// after you can use various methods to get locations
// for tokens for syntax highlighting of refactoring
// the buffer map should contain all open files. I.e in an text editor
// you could have more than one file open at the same time. Putting the
// files in this std::map will make the translationunit be reparsed
// from memory instead of from file.
tu.ReparseTranslationUnit(path, buffers);
// zero is the start of the buffer
clang::SourceLocation start(&tu, path, 0);
// the 129 value is arbitrary, you must set it to the size of your
// buffer (the number of chars in the buffer)
clang::SourceLocation end(&tu, path, 129);
clang::SourceRange range(&start, &end);
clang::Tokens tokens(&tu, &range);
# Tests #
The compilation of the tests are disabled due to ease of installation. Simply enter CMakeList.txt and uncomment the last two lines in the file to enable testing.
// now tokens are stored in "tokens" we can extract ranges that are
// comments for instance
std::vector<clang::SourceRange> ranges;
for (auto &t : tokens.tokens()) {
if (t.kind() == clang::Token_Comment) {
ranges.emplace_back(&tu, &t);
}
}
```sh
# enable_testing()
# add_subdirectory(tests)
```
For more examples see tests/
# Tests #
To run tests simply do the following:
Then simply:
```sh
$ cmake .
$ make

13
docs/install.md

@ -0,0 +1,13 @@
# Installation guide #
## Debian/Ubuntu
```sh
$ sudo apt-get install libclang-dev make cmake gcc
```
```sh
$ git clone https://github.com/cppit/libclangmm.git clangmm
$ cd clangmm
$ make
$ sudo make install
```

6
src/CMakeLists.txt

@ -50,7 +50,5 @@ add_library(${project_name} SHARED ${header_files} ${cc_files})
include_directories(${LIBCLANG_INCLUDE_DIRS})
target_link_libraries(${project_name} ${LIBCLANG_LIBRARIES})
install(TARGETS ${project_name}
LIBRARY DESTINATION ${library_installation_path})
install(FILES ${header_files}
DESTINATION ${library_installation_path}/include)
install(TARGETS ${project_name} LIBRARY DESTINATION ${library_path})
install(FILES ${header_files} DESTINATION ${include_path}/libclangmm)

13
src/docs/windows-install.md

@ -1,13 +0,0 @@
# Windows Install Guide #
## Requirements ##
```bash
* chocolatey [website](http://chocolatey.org)
```
##Preperation ##
First you install some dependencies
```bash
PS: choco install cmake make nmake
```
Loading…
Cancel
Save