Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build improvement (part 2) #59

Merged
merged 4 commits into from
Apr 24, 2020
Merged

Build improvement (part 2) #59

merged 4 commits into from
Apr 24, 2020

Conversation

Mixaill
Copy link
Contributor

@Mixaill Mixaill commented Apr 24, 2020

  • force capstone and zydis compilation for tests
  • move code with calls to libcapstone to .cpp
  • move code with calls to libzydis to .cpp
  • add ability to control library type of dependencies separately from polyhook.

It gives possibility to create the following configuration which generates only one dynamic library:

  • polyhook : dynamic
  • capstone: static
  • zydis: static

which simplifies linking a lot.

In this case, Polyhook consumer should perform linking only to polyhook, without the direct dependency from capstone/zydis.

@stevemk14ebr
Copy link
Owner

stevemk14ebr commented Apr 24, 2020

This looks great other than additional unique_ptr for the zydis code. Please use an initializer list instead, or if that is not possible then convert to std::optional

Note that in the disassembler tests the catch library has some templated tests that rely on both capstone and zydis to be there. Therefore when tests are being built the system expects both the captone and zydis libraries to be included

@Mixaill
Copy link
Contributor Author

Mixaill commented Apr 24, 2020

@stevemk14ebr fixed

@stevemk14ebr stevemk14ebr merged commit 264165f into stevemk14ebr:master Apr 24, 2020
@stevemk14ebr
Copy link
Owner

Would you be able to provide an example command line of the suggested build settings?

@Mixaill
Copy link
Contributor Author

Mixaill commented Apr 24, 2020

So I use something like that (very simplified, real life example here: https://gitlab.com/xvm/xfw/xfw.native/-/commit/295030e307562355315195f682300a5adbfdec8a )


0. directory layout:

* <my_repo_root>
    * _build <-- temporary, cmake build files
    * _install  <-- temporary, cmake installation dir
    * depends
        * polyhook
    * src

1. Build PolyHook

  1. generate polyhook project
cmake "./depends/polyhook" -B"./_build/polyhook" -DCMAKE_INSTALL_PREFIX="./_install/" -DPOLYHOOK_BUILD_SHARED_LIB=ON -DPOLYHOOK_FEATURE_INLINENTD=OFF
  1. build polyhook project
cmake --build "./_build/polyhook" --config Release --target INSTALL

2. Build dependent project

  1. create src/CMakeLists.txt
#project header
cmake_minimum_required (VERSION 3.15)
project(myproject LANGUAGES C CXX)

#find dependencies
find_package(PolyHook_2 REQUIRED)

#set library with it sources
add_library(mylibrary SHARED "library.cpp")

#link with dependencies
#include directories will be resolved automatically
target_link_libraries(mylibrary PRIVATE PolyHook_2::PolyHook_2)

#install library
install(TARGETS mylibrary
    RUNTIME DESTINATION "bin"
    LIBRARY DESTINATION "lib"
    ARCHIVE DESTINATION "lib"
)
  1. generate dependent project
cmake "./src/" -B"./_build/myproject" -DCMAKE_INSTALL_PREFIX="./_install/" -DCMAKE_PREFIX_PATH="./_install"

# CMake performs packages search in the CMAKE_PREFIX_PATH
# https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure
  1. build dependent project
cmake --build "./_build/myproject" --config Release --target INSTALL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants