diff --git a/CMakeLists.txt b/CMakeLists.txt index 3abab79..feb6208 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,4 +5,5 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter") +add_subdirectory(op-finder-lib) add_subdirectory(op-finder) diff --git a/op-finder-lib/CMakeLists.txt b/op-finder-lib/CMakeLists.txt new file mode 100644 index 0000000..97b4d00 --- /dev/null +++ b/op-finder-lib/CMakeLists.txt @@ -0,0 +1,47 @@ +cmake_minimum_required(VERSION 3.17) + +find_package(Clang REQUIRED) +find_package(LLVM REQUIRED COMPONENTS Support Option Core) + +# LLVM is typically compiled without RTTI. Weird linker errors ensue if +# you keep RTTI on and try to link. +if (NOT LLVM_ENABLE_RTTI) + if (MSVC) + string(REGEX REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-") + else () + string(REGEX REPLACE "-frtti" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") + endif () +endif () + +llvm_map_components_to_libnames(llvm_libs support option core) + +add_library(op-finder-lib STATIC + src/OperationFinder.cpp + src/OperationStorage.cpp + src/OperationAstMatcher.cpp + src/OperationFinderAstVisitor.cpp + src/OperationFinderAstConsumer.cpp + src/OperationFinderAstAction.cpp + src/OperationLog.cpp) + +target_include_directories(op-finder-lib + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/dependencies + ${LLVM_INCLUDE_DIRS} +) + +target_compile_definitions(op-finder-lib + PUBLIC + ${LLVM_DEFINITIONS} +) + +target_link_libraries(op-finder-lib + PRIVATE + ${llvm_libs} + clangTooling + clangBasic + clangASTMatchers +) diff --git a/op-finder/OperationAstMatcher.hpp b/op-finder-lib/include/OperationAstMatcher.hpp similarity index 100% rename from op-finder/OperationAstMatcher.hpp rename to op-finder-lib/include/OperationAstMatcher.hpp diff --git a/op-finder/OperationFinder.hpp b/op-finder-lib/include/OperationFinder.hpp similarity index 100% rename from op-finder/OperationFinder.hpp rename to op-finder-lib/include/OperationFinder.hpp diff --git a/op-finder/OperationFinderAstAction.hpp b/op-finder-lib/include/OperationFinderAstAction.hpp similarity index 100% rename from op-finder/OperationFinderAstAction.hpp rename to op-finder-lib/include/OperationFinderAstAction.hpp diff --git a/op-finder/OperationFinderAstConsumer.hpp b/op-finder-lib/include/OperationFinderAstConsumer.hpp similarity index 100% rename from op-finder/OperationFinderAstConsumer.hpp rename to op-finder-lib/include/OperationFinderAstConsumer.hpp diff --git a/op-finder/OperationFinderAstVisitor.hpp b/op-finder-lib/include/OperationFinderAstVisitor.hpp similarity index 100% rename from op-finder/OperationFinderAstVisitor.hpp rename to op-finder-lib/include/OperationFinderAstVisitor.hpp diff --git a/op-finder/OperationLog.hpp b/op-finder-lib/include/OperationLog.hpp similarity index 100% rename from op-finder/OperationLog.hpp rename to op-finder-lib/include/OperationLog.hpp diff --git a/op-finder/OperationStorage.hpp b/op-finder-lib/include/OperationStorage.hpp similarity index 100% rename from op-finder/OperationStorage.hpp rename to op-finder-lib/include/OperationStorage.hpp diff --git a/op-finder/ASTHelpers.hpp b/op-finder-lib/src/ASTHelpers.hpp similarity index 99% rename from op-finder/ASTHelpers.hpp rename to op-finder-lib/src/ASTHelpers.hpp index e50e740..40e7b1b 100644 --- a/op-finder/ASTHelpers.hpp +++ b/op-finder-lib/src/ASTHelpers.hpp @@ -1,4 +1,4 @@ -// +//src // Created by erki on 02.03.21. // diff --git a/op-finder/OperationAstMatcher.cpp b/op-finder-lib/src/OperationAstMatcher.cpp similarity index 100% rename from op-finder/OperationAstMatcher.cpp rename to op-finder-lib/src/OperationAstMatcher.cpp diff --git a/op-finder/OperationFinder.cpp b/op-finder-lib/src/OperationFinder.cpp similarity index 100% rename from op-finder/OperationFinder.cpp rename to op-finder-lib/src/OperationFinder.cpp diff --git a/op-finder/OperationFinderAstAction.cpp b/op-finder-lib/src/OperationFinderAstAction.cpp similarity index 100% rename from op-finder/OperationFinderAstAction.cpp rename to op-finder-lib/src/OperationFinderAstAction.cpp diff --git a/op-finder/OperationFinderAstConsumer.cpp b/op-finder-lib/src/OperationFinderAstConsumer.cpp similarity index 100% rename from op-finder/OperationFinderAstConsumer.cpp rename to op-finder-lib/src/OperationFinderAstConsumer.cpp diff --git a/op-finder/OperationFinderAstVisitor.cpp b/op-finder-lib/src/OperationFinderAstVisitor.cpp similarity index 100% rename from op-finder/OperationFinderAstVisitor.cpp rename to op-finder-lib/src/OperationFinderAstVisitor.cpp diff --git a/op-finder/OperationLog.cpp b/op-finder-lib/src/OperationLog.cpp similarity index 100% rename from op-finder/OperationLog.cpp rename to op-finder-lib/src/OperationLog.cpp diff --git a/op-finder/OperationStorage.cpp b/op-finder-lib/src/OperationStorage.cpp similarity index 100% rename from op-finder/OperationStorage.cpp rename to op-finder-lib/src/OperationStorage.cpp diff --git a/op-finder/CMakeLists.txt b/op-finder/CMakeLists.txt index 15668a8..eb8c7e0 100644 --- a/op-finder/CMakeLists.txt +++ b/op-finder/CMakeLists.txt @@ -1,8 +1,5 @@ cmake_minimum_required(VERSION 3.17) -find_package(Clang REQUIRED) -find_package(LLVM REQUIRED COMPONENTS Support Option Core) - # LLVM is typically compiled without RTTI. Weird linker errors ensue if # you keep RTTI on and try to link. if (NOT LLVM_ENABLE_RTTI) @@ -15,33 +12,9 @@ if (NOT LLVM_ENABLE_RTTI) endif () endif () -llvm_map_components_to_libnames(llvm_libs support option core) - add_executable(op-finder - main.cpp - OperationFinder.cpp - OperationStorage.cpp - OperationAstMatcher.cpp - OperationFinderAstVisitor.cpp - OperationFinderAstConsumer.cpp - OperationFinderAstAction.cpp - OperationLog.cpp) - -target_include_directories(op-finder - PRIVATE - ${LLVM_INCLUDE_DIRS} - ${PROJECT_SOURCE_DIR}/dependencies -) - -target_compile_definitions(op-finder - PRIVATE - ${LLVM_DEFINITIONS} -) + main.cpp) target_link_libraries(op-finder - PRIVATE - ${llvm_libs} - clangTooling - clangBasic - clangASTMatchers -) + PUBLIC + op-finder-lib)