aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt57
-rw-r--r--README.md15
2 files changed, 72 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..72507d7
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,57 @@
+
+cmake_minimum_required(VERSION 3.14.5)
+project(cgrep VERSION 1.1)
+# set(CMAKE_CXX_COMPILER clang++-10 CACHE STRING "set the actual name of clang++, i.e. clang++-10" FORCE)
+# set(CMAKE_CXX_COMPILER clang++-10)
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED True)
+set(LLVM_CONF llvm-config-10 CACHE STRING "set the actual name of llvm-config, i.e. llvm-config-10")
+
+function(CleanMessage)
+ execute_process(COMMAND ${CMAKE_COMMAND} -E echo "${ARGN}")
+endfunction()
+
+execute_process(COMMAND ${LLVM_CONF} --includedir OUTPUT_VARIABLE LLVM_INC_DIR)
+string(REGEX REPLACE "\n$" "" LLVM_INC_DIR "${LLVM_INC_DIR}")
+execute_process(COMMAND ${LLVM_CONF} --cxxflags OUTPUT_VARIABLE LLVM_CXX_FLAGS)
+string(REGEX REPLACE "\n$" "" LLVM_CXX_FLAGS "${LLVM_CXX_FLAGS}")
+# execute_process(COMMAND ${LLVM_CONF} --src-root OUTPUT_VARIABLE LLVM_SRC_ROOT)
+# string(REGEX REPLACE "\n$" "" LLVM_SRC_ROOT "${LLVM_SRC_ROOT}")
+# execute_process(COMMAND ${LLVM_CONF} --obj-root OUTPUT_VARIABLE LLVM_OBJ_ROOT)
+# string(REGEX REPLACE "\n$" "" LLVM_OBJ_ROOT "${LLVM_OBJ_ROOT}")
+execute_process(COMMAND ${LLVM_CONF} --libdir OUTPUT_VARIABLE LLVM_LIB_DIR)
+string(REGEX REPLACE "\n" "" LLVM_LIB_DIR "${LLVM_LIB_DIR}")
+execute_process(COMMAND ${LLVM_CONF} --ldflags OUTPUT_VARIABLE LLVM_LD_FLAGS)
+string(REGEX REPLACE "\n" "" LLVM_LD_FLAGS "${LLVM_LD_FLAGS}")
+execute_process(COMMAND ${LLVM_CONF} --libs OUTPUT_VARIABLE LLVM_LIBS)
+string(REGEX REPLACE "\n$" "" LLVM_LIBS "${LLVM_LIBS}")
+string(REGEX REPLACE "^-l" "" LLVM_LIBS "${LLVM_LIBS}")
+execute_process(COMMAND ${LLVM_CONF} --system-libs OUTPUT_VARIABLE LLVM_SYS_LIBS)
+string(REGEX REPLACE "\n$" "" LLVM_SYS_LIBS "${LLVM_SYS_LIBS}")
+string(REGEX REPLACE "^-l" "" LLVM_SYS_LIBS "${LLVM_SYS_LIBS}")
+
+add_compile_options(${LLVM_CXX_FLAGS})
+add_compile_options(-I${LLVM_INC_DIR})
+# add_compile_options(-I"${LLVM_SRC_ROOT}/tools/clang/include")
+# add_compile_options(-I"${LLVM_OBJ_ROOT}/tools/clang/include")
+
+set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin)
+set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
+set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
+
+add_link_options(${LLVM_LD_FLAGS})
+add_link_options(-L${LLVM_LIB_DIR})
+
+add_executable(cgrep cgrep.cpp ${CMAKE_SOURCE_DIR}/cfe-extra/cfe_extra.cpp)
+option(USE_MONOLITH_LIBTOOLING "use libtooling built into a single library" OFF)
+if (USE_MONOLITH_LIBTOOLING)
+ target_link_libraries(cgrep clang-cpp)
+else()
+ target_link_libraries(cgrep -Wl,--start-group clangAST clangAnalysis clangBasic clangDriver clangEdit clangFrontend clangFrontendTool clangLex clangParse clangSema clangEdit clangASTMatchers clangRewrite clangRewriteFrontend clangStaticAnalyzerFrontend clangStaticAnalyzerCheckers clangStaticAnalyzerCore clangSerialization clangToolingCore clangTooling stdc++ LLVMRuntimeDyld m -Wl,--end-group)
+endif()
+target_link_libraries(cgrep ${LLVM_SYS_LIBS})
+target_link_libraries(cgrep ${LLVM_LIBS})
+
+include_directories("${PROJECT_SOURCE_DIR}/cfe-extra")
+target_include_directories(cgrep PUBLIC "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR/cfe-extra}")
+
diff --git a/README.md b/README.md
index 2481f23..c46f10c 100644
--- a/README.md
+++ b/README.md
@@ -54,6 +54,8 @@ You can get cgrep from AUR. Thanks to [schra](https://github.com/schra).
### Cygwin
You will need `libclang-devel, libllvm-devel, clang, libiconv-devel`.
+### Good Ole' Makefiles
+**NOTE:the monolithic libtooling library is not supported with the good ole makefiles. Look down below at Cmake for that.**<br/>
Assuming you have the llvm/clang libraries (the build file will read your llvm options using `llvm-config` so make sure it's in path), just run:
```bash
@@ -75,6 +77,19 @@ make CXX=clang-9 LLVM_CONF=llvm-config-9
For windows builds, cygwin builds are supported. Get llvm and clang along with their sources and build like usual. If you run into problems while building on cygwin, you can take a look at the `appveyor.yml` file under the repository root.
+### Cmake
+To do an out-of-source build simply do:<br/>
+```bash
+git clone https://github.com/bloodstalker/cgrep
+cd cgrep
+git submodule init
+git submodule update
+mkdir build
+cmake ../ -DLLVM_CONF=llvm-config-10 -DCMAKE_CXX_COMPIELR=clang++-10 -DUSE_MONOLITH_LIBTOOLING=ON
+make
+```
+The 3 variables denote the llvm-config executable name, the clang++ name and finally, the last one tells cmake whether to build using the single c++ libtooling library or just use the old way with all the libtooling libraries.<br/>
+
## Usage
A simple usage example: