diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c2db7a..715fbc2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/ctbench-api.cmake b/cmake/ctbench-api.cmake index 118d7aa..37fb663 100644 --- a/cmake/ctbench-api.cmake +++ b/cmake/ctbench-api.cmake @@ -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 @@ -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() + "$;${output}") # Pass benchmark size target_compile_options(${target_name} PRIVATE ${options}) @@ -117,7 +76,6 @@ function( end step samples) - _ctbench_set_prefixes() # Setting names add_custom_target(${name}) @@ -162,8 +120,6 @@ function( step samples generator) - _ctbench_set_prefixes() - # Setting names add_custom_target(${name}) @@ -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}) diff --git a/cmake/install.cmake b/cmake/install.cmake index 1a5cf70..3b10b05 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -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 diff --git a/readme.md b/readme.md index 55fbdc3..5c60675 100644 --- a/readme.md +++ b/readme.md @@ -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 @@ -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 diff --git a/ttw/CMakeLists.txt b/ttw/CMakeLists.txt index 5588c12..95970e8 100644 --- a/ttw/CMakeLists.txt +++ b/ttw/CMakeLists.txt @@ -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)