Skip to content

Commit

Permalink
Merge pull request #40 from lifting-bits/cmake_refactor
Browse files Browse the repository at this point in the history
Depend directly on remill
  • Loading branch information
artemdinaburg authored Sep 17, 2020
2 parents 2023163 + 2c6ff0c commit bd26397
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 177 deletions.
112 changes: 22 additions & 90 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,76 +27,16 @@ macro(target_public_headers TARGET)
set_target_properties(${TARGET} PROPERTIES PUBLIC_HEADER "${ARGN}")
endmacro()

# warnings and compiler settings
if(NOT DEFINED WIN32)
set(PROJECT_CXXFLAGS
${GLOBAL_CXXFLAGS} -Wconversion -pedantic
-Wno-unreachable-code-return
)
endif()

#
# libraries
#

# remill
if(NOT TARGET remill)
if("${PLATFORM_NAME}" STREQUAL "windows")
set(REMILL_FINDPACKAGE_HINTS HINTS "${CMAKE_INSTALL_PREFIX}/remill/lib")
endif()

find_package(remill REQUIRED ${REMILL_FINDPACKAGE_HINTS})
endif()

# llvm
find_package(LLVM REQUIRED CONFIG HINTS ${FINDPACKAGE_LLVM_HINTS})

string(REPLACE "." ";" LLVM_VERSION_LIST ${LLVM_PACKAGE_VERSION})
list(GET LLVM_VERSION_LIST 0 LLVM_MAJOR_VERSION)
list(GET LLVM_VERSION_LIST 1 LLVM_MINOR_VERSION)
set(REMILL_LLVM_VERSION "${LLVM_MAJOR_VERSION}.${LLVM_MINOR_VERSION}")

set(LLVM_LIBRARIES
LLVMCore LLVMAnalysis LLVMSupport LLVMipo LLVMIRReader
LLVMBitReader LLVMBitWriter LLVMTransformUtils LLVMScalarOpts
LLVMLTO
)
list(APPEND PROJECT_LIBRARIES ${LLVM_LIBRARIES})
list(APPEND PROJECT_DEFINITIONS ${LLVM_DEFINITIONS})
list(APPEND PROJECT_INCLUDEDIRECTORIES ${LLVM_INCLUDE_DIRS})

# google log module
find_package(glog REQUIRED)
list(APPEND PROJECT_LIBRARIES glog::glog)

# gflags
find_package(gflags REQUIRED)
list(APPEND PROJECT_LIBRARIES gflags)

# xed
find_package(XED REQUIRED)
list(APPEND PROJECT_LIBRARIES ${XED_LIBRARIES})
list(APPEND PROJECT_INCLUDEDIRECTORIES ${XED_INCLUDE_DIRS})

# z3
if (LLVM_Z3_INSTALL_DIR)
find_package(Z3 4.7.1)
set(need_z3 TRUE)
elseif(DEFINED ENV{TRAILOFBITS_LIBRARIES})
set(LLVM_Z3_INSTALL_DIR "$ENV{TRAILOFBITS_LIBRARIES}/z3")
set(need_z3 TRUE)
else()
set(need_z3 FALSE)
endif()

if(need_z3)
find_package(Z3 4.7.1)
if (NOT Z3_FOUND)
message(WARNING "Z3 >= 4.7.1 has not been found in LLVM_Z3_INSTALL_DIR: ${LLVM_Z3_INSTALL_DIR}.")
endif()
list(APPEND PROJECT_LIBRARIES Z3)
if("${PLATFORM_NAME}" STREQUAL "windows")
set(REMILL_FINDPACKAGE_HINTS HINTS "${CMAKE_INSTALL_PREFIX}/remill/lib")
endif()

find_package(remill REQUIRED ${REMILL_FINDPACKAGE_HINTS})

#
# target settings
Expand Down Expand Up @@ -142,17 +82,11 @@ add_library(${ANVILL} STATIC
include/anvill/Analyze.h
lib/Analyze.cpp)

target_compile_definitions(${ANVILL} PUBLIC
${PROJECT_DEFINITIONS})

target_compile_options(${ANVILL} PUBLIC
${PROJECT_CXXFLAGS})

target_include_directories(${ANVILL} PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/include"
${PROJECT_INCLUDEDIRECTORIES})
"${CMAKE_CURRENT_SOURCE_DIR}/include"
${PROJECT_INCLUDEDIRECTORIES})

target_link_libraries(${ANVILL} PUBLIC remill AnvillVersion ${PROJECT_LIBRARIES})
target_link_libraries(${ANVILL} PUBLIC remill AnvillVersion)

target_public_headers(${ANVILL}
include/anvill/Analyze.h
Expand All @@ -163,8 +97,7 @@ target_public_headers(${ANVILL}
include/anvill/Type.h
include/anvill/TypeParser.h
include/anvill/TypePrinter.h
include/anvill/Version.h
)
include/anvill/Version.h)

#
# tool target settings
Expand All @@ -181,23 +114,22 @@ set(SPECIFY_BITCODE anvill-specify-bitcode-${REMILL_LLVM_VERSION})
add_executable(${SPECIFY_BITCODE} Bitcode.cpp)
target_link_libraries(${SPECIFY_BITCODE} PRIVATE ${ANVILL})


add_custom_target(install_anvill_python
DEPENDS
setup.py
python/anvill/__init__.py
python/anvill/arch.py
python/anvill/binja.py
python/anvill/dwarf.py
python/anvill/exc.py
python/anvill/function.py
python/anvill/ida.py
python/anvill/loc.py
python/anvill/mem.py
python/anvill/os.py
python/anvill/program.py
python/anvill/type.py
python/anvill/var.py)
DEPENDS
setup.py
python/anvill/__init__.py
python/anvill/arch.py
python/anvill/binja.py
python/anvill/dwarf.py
python/anvill/exc.py
python/anvill/function.py
python/anvill/ida.py
python/anvill/loc.py
python/anvill/mem.py
python/anvill/os.py
python/anvill/program.py
python/anvill/type.py
python/anvill/var.py)

add_custom_command(
TARGET install_anvill_python POST_BUILD
Expand Down
9 changes: 4 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ ARG LIBRARIES
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
if [ "$(uname -m)" = "x86_64" ]; then apt-get install -qqy gcc-multilib g++-multilib; fi && \
apt-get install -qqy ninja-build python2.7 python3 python3-pip liblzma-dev zlib1g-dev libtinfo-dev curl git wget build-essential ninja-build ccache && \
apt-get install -qqy ninja-build python2.7 python3 python3-pip liblzma-dev zlib1g-dev libtinfo-dev curl git wget build-essential ninja-build ccache clang && \
rm -rf /var/lib/apt/lists/*

# needed for 20.04 support until we migrate to py3
Expand All @@ -36,7 +35,7 @@ RUN curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py && python2.7 g
RUN update-alternatives --install /usr/bin/python2 python2 /usr/bin/python2.7 1


COPY --from=remill /opt/trailofbits/remill /opt/trailofbits/remill
COPY --from=remill /opt/trailofbits /opt/trailofbits


# Source code build
Expand All @@ -47,8 +46,8 @@ WORKDIR /anvill
COPY . ./

ENV PATH="${LIBRARIES}/llvm/bin:${LIBRARIES}/cmake/bin:${LIBRARIES}/protobuf/bin:${PATH}"
ENV CC="${LIBRARIES}/llvm/bin/clang"
ENV CXX="${LIBRARIES}/llvm/bin/clang++"
ENV CC="/usr/bin/clang"
ENV CXX="/usr/bin/clang++"
ENV TRAILOFBITS_LIBRARIES="${LIBRARIES}"

RUN mkdir -p build && cd build && \
Expand Down
4 changes: 4 additions & 0 deletions JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ static void SetVersion(void) {

# include <gflags/gflags.h>
# include <glog/logging.h>
// clang-format off
# include <remill/BC/Compat/CTypes.h>
# include <llvm/IR/LLVMContext.h>
# include <llvm/IR/Module.h>
# include <llvm/Support/JSON.h>
# include <llvm/Support/MemoryBuffer.h>
// clang-format on

# include <remill/Arch/Arch.h>
# include <remill/Arch/Name.h>
# include <remill/BC/Compat/Error.h>
Expand Down
82 changes: 0 additions & 82 deletions cmake/settings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,6 @@ macro(main)
# generate a compile commands JSON file.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

#
# cxx-common
#

if(DEFINED ENV{TRAILOFBITS_LIBRARIES})
set(LIBRARY_REPOSITORY_ROOT $ENV{TRAILOFBITS_LIBRARIES}
CACHE PATH "Location of cxx-common libraries."
)
endif()

if(DEFINED LIBRARY_REPOSITORY_ROOT)
set(TOB_CMAKE_INCLUDE "${LIBRARY_REPOSITORY_ROOT}/cmake_modules/repository.cmake")
if(NOT EXISTS "${TOB_CMAKE_INCLUDE}")
message(FATAL_ERROR "The library repository could not be found!")
endif()

include("${TOB_CMAKE_INCLUDE}")

else()
message(STATUS "Using system libraries")
endif()

#
# compiler and linker flags
#
Expand All @@ -54,66 +32,6 @@ macro(main)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)

if(WIN32)
# warnings and compiler settings
set(GLOBAL_CXXFLAGS
/MD /nologo /W3 /EHsc /wd4141 /wd4146 /wd4180 /wd4244
/wd4258 /wd4267 /wd4291 /wd4345 /wd4351 /wd4355 /wd4456
/wd4457 /wd4458 /wd4459 /wd4503 /wd4624 /wd4722 /wd4800
/wd4100 /wd4127 /wd4512 /wd4505 /wd4610 /wd4510 /wd4702
/wd4245 /wd4706 /wd4310 /wd4701 /wd4703 /wd4389 /wd4611
/wd4805 /wd4204 /wd4577 /wd4091 /wd4592 /wd4324
)

set(GLOBAL_DEFINITIONS
_CRT_SECURE_NO_DEPRECATE
_CRT_SECURE_NO_WARNINGS
_CRT_NONSTDC_NO_DEPRECATE
_CRT_NONSTDC_NO_WARNINGS
_SCL_SECURE_NO_DEPRECATE
_SCL_SECURE_NO_WARNINGS
GOOGLE_PROTOBUF_NO_RTTI
)

else()
# warnings and compiler settings
set(GLOBAL_CXXFLAGS
-Wall -Wextra -Wno-unused-parameter -Wno-c++98-compat
-Wno-unreachable-code-return -Wno-nested-anon-types
-Wno-extended-offsetof
-Wno-variadic-macros -Wno-return-type-c-linkage
-Wno-c99-extensions -Wno-ignored-attributes -Wno-unused-local-typedef
-Wno-unknown-pragmas -Wno-unknown-warning-option -fPIC
-fno-omit-frame-pointer -fvisibility-inlines-hidden -fno-exceptions
-fno-asynchronous-unwind-tables
)

if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
set(GLOBAL_CXXFLAGS
${GLOBAL_CXXFLAGS}
-Wgnu-alignof-expression -Wno-gnu-anonymous-struct -Wno-gnu-designator
-Wno-gnu-zero-variadic-macro-arguments -Wno-gnu-statement-expression
-fno-aligned-allocation
)
endif()

# debug symbols
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
list(APPEND GLOBAL_CXXFLAGS
-gdwarf-2 -g3
)
endif()

# optimization flags and definitions
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
list(APPEND GLOBAL_CXXFLAGS -O0)
list(APPEND PROJECT_DEFINITIONS "DEBUG")
else()
list(APPEND GLOBAL_CXXFLAGS -O3)
list(APPEND PROJECT_DEFINITIONS "NDEBUG")
endif()
endif()

if(UNIX)
if(APPLE)
set(PLATFORM_NAME "macos")
Expand Down
5 changes: 5 additions & 0 deletions lib/Analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include "anvill/Analyze.h"

#include <glog/logging.h>

// clang-format off
#include <remill/BC/Compat/CTypes.h>
#include <llvm/IR/BasicBlock.h>
#include <llvm/IR/Constants.h>
#include <llvm/IR/DataLayout.h>
Expand All @@ -30,6 +33,8 @@
#include <llvm/IR/Operator.h>
#include <llvm/IR/Type.h>
#include <llvm/Transforms/Utils/Local.h>
// clang-format on

#include <remill/BC/Compat/ScalarTransforms.h>
#include <remill/BC/Optimizer.h>
#include <remill/BC/Util.h>
Expand Down
5 changes: 5 additions & 0 deletions lib/Lift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@

#include <anvill/Lift.h>
#include <glog/logging.h>

// clang-format off
#include <remill/BC/Compat/CTypes.h>
#include <llvm/IR/BasicBlock.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Instruction.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/Module.h>
#include <llvm/Transforms/Utils/Cloning.h>
// clang-format on

#include <remill/Arch/Arch.h>
#include <remill/BC/ABI.h>
#include <remill/BC/IntrinsicTable.h>
Expand Down
5 changes: 5 additions & 0 deletions lib/Optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include "anvill/Optimize.h"

#include <glog/logging.h>

// clang-format off
#include <remill/BC/Compat/CTypes.h>
#include <llvm/IR/BasicBlock.h>
#include <llvm/IR/Constants.h>
#include <llvm/IR/DataLayout.h>
Expand All @@ -32,6 +35,8 @@
#include <llvm/IR/Type.h>
#include <llvm/Transforms/IPO.h>
#include <llvm/Transforms/Utils/Local.h>
// clang-format on

#include <remill/BC/ABI.h>
#include <remill/BC/Compat/ScalarTransforms.h>
#include <remill/BC/Optimizer.h>
Expand Down
5 changes: 5 additions & 0 deletions lib/TypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@

#include <anvill/TypePrinter.h>
#include <glog/logging.h>

// clang-format off
#include <remill/BC/Compat/CTypes.h>
#include <llvm/IR/DataLayout.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/Type.h>
// clang-format on

#include <remill/BC/Util.h>

#include <sstream>
Expand Down

0 comments on commit bd26397

Please sign in to comment.