Skip to content

Commit

Permalink
Merge pull request #15 from JPenuchot/dev
Browse files Browse the repository at this point in the history
CMake in order for v1.0.0 release
  • Loading branch information
JPenuchot authored Dec 5, 2022
2 parents 0f7ea0e + 9f7444a commit 7c1b164
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 71 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.21)
project(ctbench VERSION 0.1.0)
cmake_minimum_required(VERSION 3.25)
project(ctbench VERSION 1.0.0)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Expand Down
51 changes: 3 additions & 48 deletions cmake/ctbench-api.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,6 @@
#@
## =============================================================================

## =============================================================================
#@
#@ _ctbench_internal_add_compile_benchmark
#@
#@ Sets ctbench executable/target prefixes for FetchContent support.

function(_ctbench_set_prefixes)
if(ctbench_FOUND)
# ctbench_FOUND being true means ctbench found through find_package.

set(GRAPHER_PREFIX
ctbench::
CACHE STRING "Prefix for grapher executables")

# ttw is a special case as it is used as a compiler launcher.
# Therefore we can't use the imported executable target,
# and have to provide an executable name assuming ttw can be found in PATH.
set(TTW_PREFIX
""
CACHE STRING "Prefix for TTW executable")
else()
# ctbench_FOUND being false means ctbench was imported inside of the tree.

set(GRAPHER_PREFIX
${CMAKE_CURRENT_BINARY_DIR}/grapher/
CACHE STRING "Prefix for grapher executables")

set(TTW_PREFIX
${CMAKE_CURRENT_BINARY_DIR}/ttw/
CACHE STRING "Prefix for TTW executable")
endif()
endfunction()

#@
#@ --

## =============================================================================
#@
#@ _ctbench_internal_add_compile_benchmark
Expand All @@ -56,18 +20,13 @@ endfunction()

function(_ctbench_internal_add_compile_benchmark target_name output source
options)
_ctbench_set_prefixes()
add_library(${target_name} OBJECT EXCLUDE_FROM_ALL ${source})
target_include_directories(${target_name} PUBLIC "../include")

# Setting ctbench-ttw as a compiler launcher
set_target_properties(
${target_name} PROPERTIES CXX_COMPILER_LAUNCHER
"${TTW_PREFIX}ctbench-ttw;${output}")

if(NOT ctbench_FOUND)
add_dependencies(${target_name} ctbench-ttw)
endif()
"$<TARGET_FILE:ctbench::ctbench-ttw>;${output}")

# Pass benchmark size
target_compile_options(${target_name} PRIVATE ${options})
Expand Down Expand Up @@ -117,7 +76,6 @@ function(
end
step
samples)
_ctbench_set_prefixes()
# Setting names
add_custom_target(${name})

Expand Down Expand Up @@ -162,8 +120,6 @@ function(
step
samples
generator)
_ctbench_set_prefixes()

# Setting names
add_custom_target(${name})

Expand Down Expand Up @@ -200,12 +156,11 @@ endfunction(ctbench_add_custom_benchmark)
#! - `benchmarks...`: List of benchmark names

function(ctbench_add_graph category config)
_ctbench_set_prefixes()

set(config_path ${CMAKE_CURRENT_SOURCE_DIR}/${config})
add_custom_target(
${category}
COMMAND ${GRAPHER_PREFIX}ctbench-grapher-plot --output=${category}
# COMMAND ${CTBENCH_GRAPHER_PLOT_EXEC} --output=${category}
COMMAND ctbench::ctbench-grapher-plot --output=${category}
--config=${config_path} ${ARGN}
DEPENDS ${config_path} ${ARGN}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
Expand Down
5 changes: 3 additions & 2 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ export(EXPORT ctbench-targets FILE ctbench-targets.cmake)

install(
EXPORT ctbench-targets
DESTINATION ${ConfigPackageLocation}
NAMESPACE ctbench::)
NAMESPACE ctbench::
DESTINATION ${ConfigPackageLocation})

install(FILES cmake/ctbench-api.cmake DESTINATION ${ConfigPackageLocation})

# CMake package config files
Expand Down
34 changes: 21 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,19 @@ reference project for using ctbench.

## Using ctbench

### Integrating ctbench in your project

You can integrate `ctbench` by adding this into your CMake listfiles:

```cmake
include(FetchContent)
FetchContent_Declare(
ctbench
GIT_REPOSITORY https://github.com/jpenuchot/ctbench.git
GIT_TAG main
GIT_SHALLOW)
FetchContent_MakeAvailable(ctbench)
### Installing `ctbench`

```sh
git clone https://github.com/jpenuchot/ctbench
cd ctbench
cmake --preset release
cmake --build --preset release
sudo cmake --build --preset release --target install
```

or through `find_package(ctbench REQUIRED)` after installing it.
### Integrating `ctbench` in your project

Use `find_package(ctbench REQUIRED)` after installing it.

The [Rule of Cheese](https://github.com/JPenuchot/rule-of-cheese) project can be
used as an example of how to use `ctbench`. It is the project that gave birth to
Expand Down Expand Up @@ -82,6 +80,16 @@ int sum() {
}
```
By default, only compiler execution time is measured.
If you want to generate plots using Clang's builtin profiler, add the following:
```cmake
add_compile_options(-ftime-trace -ftime-trace-granularity=1)
```

Note that plotting profiler data takes more time
and will generate a *lot* of plot files.

Then you can declare a benchmark case target in CMake with the following:

```cmake
Expand Down
6 changes: 0 additions & 6 deletions ttw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
add_executable(ctbench-ttw ttw.cpp)
target_link_libraries(ctbench-ttw PRIVATE ctbench-compile-opts)
target_include_directories(ctbench-ttw PRIVATE include)

if(BUILD_TESTING)
add_executable(ctbench-ttw-test-exec tests/ttw.cpp)
target_include_directories(ctbench-ttw-test-exec PRIVATE include)
add_test(NAME ctbench-ttw-test COMMAND ctbench-ttw-test-exec)
endif(BUILD_TESTING)

0 comments on commit 7c1b164

Please sign in to comment.