GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf-cpp/docs/build.md at dev · Liteom/perf-cpp

Expand file tree

/

build.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
136 lines (105 loc) · 4.1 KB
/

build.md

Copy path

File metadata and controls

136 lines (105 loc) · 4.1 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

How to build and include perf-cpp in your project

perf-cpp can be build manually or included into CMake projects.

Table of Contents

  • Building Manually
    • Build the Library
    • Install the Library
    • Build the Examples
    • Building as a Dynamically Linked Library
  • Use CMake
    • ExternalProject
    • FetchContent
    • find_package

Building Manually

Note

Throughout the documentation, we use ./build as the build directory. However, the build directory can be any directory of your choice (including .).

Build the Library

Download the source code

git clone https://github.com/jmuehlig/perf-cpp.git
cd perf-cpp

# Optional: switch to this development version
git checkout v0.12.3

Generate the Makefile and Build

cmake . -B build 
cmake --build build

Install the Library

To install the library, specify the CMAKE_INSTALL_PREFIX:

# Generate Makefile
cmake . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install/dir

# Build
cmake --build build

# Install
cmake --install build

The library will then be available for discovery via CMake and find_package (see below).

Generate Processor-specific Events

With -DGEN_PROCESSOR_EVENTS=1, the build process will try to read the processor-specific events from the event library (events/) and generate a source file (src/processor_specific_event_provider.cpp) that adds these events to every (the default and manually instantiated) perf::CounterDefinition (see also the documentation on hardware events).

With this option, processor-specific events can be used like built-in ones.

# Generate Makefile and source file for processor-specific events
cmake . -B build -DGEN_PROCESSOR_EVENTS=1

# Build Library
cmake --build build

Important

Depending on the underlying processor, the source file can grow very large and increase compilation time significantly.

Build Examples

Enable example compilation with -DBUILD_EXAMPLES=1 and build the examples target:

# Generate Makefile
cmake . -B build -DBUILD_EXAMPLES=1

# Build Library and Examples
cmake --build build --target examples

The example binaries will be located in build/examples/bin.

Building as a Dynamically Linked Library

By default, perf-cpp is build as a static library. You can request to build a shared library with -DBUILD_LIB_SHARED=1:

cmake . -B build -DBUILD_LIB_SHARED=1
cmake --build build

Including into CMakeLists.txt

perf-cpp uses CMake as its build system, facilitating integration into additional CMake projects. Choose from the following methods:

Via ExternalProject

Include ExternalProject in your CMakeLists.txt and define the project:

include(ExternalProject)
ExternalProject_Add(
  perf-cpp-external
  GIT_REPOSITORY "https://github.com/jmuehlig/perf-cpp"
  GIT_TAG "v0.12.3"
  PREFIX "lib/perf-cpp"
  INSTALL_COMMAND cmake -E echo ""
)
  • Add lib/perf-cpp/src/perf-cpp-external/include to your include_directories().
  • Add lib/perf-cpp/src/perf-cpp-external-build to your link_directories().

Note: The directory lib/ can be any folder of your choice.

Via FetchContent

Include FetchContent in your CMakeLists.txt and define the project:

include(FetchContent)
FetchContent_Declare(
  perf-cpp-external
  GIT_REPOSITORY "https://github.com/jmuehlig/perf-cpp"
  GIT_TAG "v0.12.3"
)
FetchContent_MakeAvailable(perf-cpp-external)
  • Add perf-cpp to your linked libraries.
  • Add ${perf-cpp-external_SOURCE_DIR}/include/ to your include directories.

Via find_package

If perf-cpp is already installed on your system (see install instructions above), you can simply use find_package to link it with your project:

find_package(perf-cpp REQUIRED)
target_link_libraries(perf-cpp::perf-cpp)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.