diff --git a/CMakeLists.txt b/CMakeLists.txt index 2152738..9e2f28b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,12 +4,6 @@ project(ctbench) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_CXX_STANDARD 20) -# Project options -option(CTBENCH_ENABLE_TESTING "Enable testing for ctbench components." OFF) - -option(CTBENCH_FETCH_LIBRARIES - "Fetch libraries instead of using the ones installed locally." OFF) - add_compile_options( -Wall -Wextra @@ -19,23 +13,20 @@ add_compile_options( -Wdouble-promotion -Wshadow) -add_compile_options(-fno-rtti -fno-exceptions) - -add_subdirectory(time-trace-wrapper) - # Docs if(${PROJECT_IS_TOP_LEVEL}) add_subdirectory(cmake-doc-extractor) include(cmake/docs.cmake) endif() -# Exporting time-trace-wrapper exec path to parent scope if needed -if(NOT ${PROJECT_IS_TOP_LEVEL}) - set(CTBENCH_TIME_TRACE_WRAPPER_EXEC - ${CTBENCH_TIME_TRACE_WRAPPER_EXEC} - PARENT_SCOPE) -endif() - +add_subdirectory(ttw) add_subdirectory(grapher) -include(benchmarking.cmake) +export( + EXPORT ctbench-targets + NAMESPACE ctbench:: + FILE CtbenchTargets.cmake) + +install(EXPORT ctbench-targets DESTINATION ctbench) + +include(cmake/benchmarking.cmake) diff --git a/benchmarking.cmake b/cmake/benchmarking.cmake similarity index 59% rename from benchmarking.cmake rename to cmake/benchmarking.cmake index c165fe4..05e417e 100644 --- a/benchmarking.cmake +++ b/cmake/benchmarking.cmake @@ -1,23 +1,75 @@ +#! # CMake documentation + ## ============================================================================= -#! # CMake API -#! -#! Functions for automated benchmark declarations. -#! +#@ +#@ ## Internal API +#@ +## ============================================================================= + +# Setting executable/target prefix. +# ctbench_FOUND being false means ctbench was imported inside of the tree. +# ctbench_FOUND being true means ctbench found through find_package. +if(NOT ctbench_FOUND) + set(GRAPHER_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/grapher/ PARENT_SCOPE) + set(TTW_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/ttw/ PARENT_SCOPE) +else() + set(GRAPHER_PREFIX ctbench:: PARENT_SCOPE) + set(TTW_PREFIX ctbench:: PARENT_SCOPE) +endif() + +## ============================================================================= +#@ +#@ _ctbench_internal_add_compile_benchmark +#@ +#@ Creates a library target for a file and extracts the compilation time trace +#@ file. +#@ +#@ - `target_name`: Name of the benchmark target +#@ - `output`: Time trace output path +#@ - `source`: Source file +#@ - `options`: Options passed to the compiler + +function(_ctbench_internal_add_compile_benchmark target_name output source + options) + + 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() + + # Pass benchmark size + target_compile_options(${target_name} PRIVATE ${options}) + +endfunction(_ctbench_internal_add_compile_benchmark) + +## ============================================================================= +#@ +#@ ## Public API +#@ ## ============================================================================= ## ============================================================================= -#! ## ctbench-graph-all target +#! +#! ### ctbench-graph-all target #! #! `ctbench-graph-all` is a ctbench-provided target to generate all graphs #! at once. -#! add_custom_target(ctbench-graph-all) -include(cmake/internal.cmake) +#! +#! -- ## ============================================================================= -#! ## ctbench_add_benchmark +#! +#! ### ctbench_add_benchmark(name source begin end step samples) #! #! Add a benchmark for a given source, with a given size range. #! @@ -25,7 +77,6 @@ include(cmake/internal.cmake) #! - `source`: Source file #! - `begin, end, step`: Iteration parameters #! - `samples`: Number of samples per iteration -#! function( ctbench_add_benchmark @@ -56,8 +107,12 @@ function( endfunction(ctbench_add_benchmark) +#! +#! -- + ## ============================================================================= -#! ## ctbench_add_custom_benchmark +#! +#! ### ctbench_add_custom_benchmark(name source begin end step iterations generator) #! #! Add a benchmark for a given source with a given size range #! using a custom compile options generator. @@ -68,7 +123,6 @@ endfunction(ctbench_add_benchmark) #! - `iterations`: Number of benchmark iterations for a given size #! - `generator`: Compile option generator. Takes a size and an output #! variable name as parameters. -#! function( ctbench_add_custom_benchmark @@ -100,8 +154,12 @@ function( endfunction(ctbench_add_custom_benchmark) +#! +#! -- + ## ============================================================================= -#! ## ctbench_add_graph +#! +#! ### ctbench_add_graph(category config benchmarks...) #! #! Adds a graph target for a set of benchmarks, #! and adds the target to ctbench-graph-all. @@ -109,15 +167,22 @@ endfunction(ctbench_add_custom_benchmark) #! - `category`: Name of the category. This is also the name of the graph #! target, and the folder where the graphs will be saved. #! - `config`: Config file for plotting -#! - `benchmarks`: List of benchmark names -#! +#! - `benchmarks...`: List of benchmark names function(ctbench_add_graph category config) set(config_path ${CMAKE_CURRENT_SOURCE_DIR}/${config}) add_custom_target( ${category} - COMMAND grapher-plot --output=${category} --config=${config_path} ${ARGN} + COMMAND ${GRAPHER_PREFIX}ctbench-grapher-plot --output=${category} + --config=${config_path} ${ARGN} DEPENDS ${config_path} ${ARGN} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) add_dependencies(ctbench-graph-all ${category}) + + if(NOT ctbench_FOUND) + add_dependencies(${category} ctbench-grapher-plot) + endif() endfunction(ctbench_add_graph) + +#! +#! -- diff --git a/cmake/docs.cmake b/cmake/docs.cmake index 6be5340..667b522 100644 --- a/cmake/docs.cmake +++ b/cmake/docs.cmake @@ -17,7 +17,7 @@ include(FetchContent) FetchContent_Declare( dac_content GIT_REPOSITORY https://github.com/jothepro/doxygen-awesome-css.git - GIT_TAG v1.6.1 + GIT_TAG v2.0.3 GIT_SHALLOW) FetchContent_GetProperties(dac_content) @@ -33,8 +33,8 @@ doxygen_add_docs(docs ALL) add_custom_target( extract-api-doc - cmake-doc-extractor --input ${CMAKE_SOURCE_DIR}/benchmarking.cmake --output - ${CMAKE_SOURCE_DIR}/generated-docs/benchmarking.md - DEPENDS ${CMAKE_SOURCE_DIR}/benchmarking.cmake) + cmake-doc-extractor --input ${CMAKE_SOURCE_DIR}/cmake/benchmarking.cmake + --output ${CMAKE_SOURCE_DIR}/generated-docs/benchmarking.md + DEPENDS ${CMAKE_SOURCE_DIR}/cmake/benchmarking.cmake) add_dependencies(docs extract-api-doc) diff --git a/cmake/internal.cmake b/cmake/internal.cmake deleted file mode 100644 index c924bdd..0000000 --- a/cmake/internal.cmake +++ /dev/null @@ -1,30 +0,0 @@ -# Creates a library target for a file and extracts the compilation time trace -# file. -# -# * target_name: Name of the benchmark target -# * output: Time trace output path -# * file: Source file -# * size: Sets BENCHMARK_SIZE define (can be something else than a number) -# * options: Options passed to the compiler - -function(_ctbench_internal_add_compile_benchmark target_name output source - options) - - add_library(${target_name} OBJECT EXCLUDE_FROM_ALL ${source}) - target_include_directories(${target_name} PUBLIC "../include") - - # Setting time-trace-wrapper as a compiler launcher - set_target_properties( - ${target_name} PROPERTIES CXX_COMPILER_LAUNCHER - "${CTBENCH_TIME_TRACE_WRAPPER_EXEC};${output}") - - # Adding dependency because CMake won't - add_dependencies(${target_name} time-trace-wrapper) - - # Pass benchmark size - target_compile_options(${target_name} PRIVATE ${options}) - - # Boost Preprocessor - target_include_directories(${target_name} PUBLIC Boost_INCLUDE_DIRS) - -endfunction(_ctbench_internal_add_compile_benchmark) diff --git a/grapher/CMakeLists.txt b/grapher/CMakeLists.txt index 13434d2..87d17d3 100644 --- a/grapher/CMakeLists.txt +++ b/grapher/CMakeLists.txt @@ -1,38 +1,31 @@ -# Creating the grapher library +# Declaring the grapher library + file(GLOB_RECURSE GRAPHER_SOURCES lib/*.cpp) add_library(grapher STATIC ${GRAPHER_SOURCES}) target_include_directories(grapher PUBLIC include) -if(CTBENCH_FETCH_LIBRARIES) - include(cmake/libraries_fetch.cmake) -else() - include(cmake/libraries_local.cmake) -endif() - -# LLVM +find_package(nlohmann_json 3.9.1 REQUIRED) +find_package(sciplot REQUIRED) find_package(LLVM REQUIRED CONFIG) + llvm_map_components_to_libnames(llvm_libs core support) -#target_compile_options(grapher PUBLIC -fno-rtti) -target_link_libraries(grapher PUBLIC ${llvm_libs}) - -target_compile_options( - grapher - PUBLIC -Wall - -Wextra - -Werror - -Wnull-dereference - -Wold-style-cast - -Wdouble-promotion - -Wshadow) - -# Old libstdc++ compatibility -target_link_libraries(grapher PUBLIC stdc++fs) -target_link_libraries(grapher PUBLIC tbb) - -# Adding executable subdirectories -add_subdirectory(grapher-plot) -add_subdirectory(grapher-utils) - -if(CTBENCH_ENABLE_TESTING) + +target_link_libraries(grapher PUBLIC nlohmann_json::nlohmann_json + sciplot::sciplot stdc++fs tbb ${llvm_libs}) + +target_compile_options(grapher PUBLIC -fno-rtti -fno-exceptions) + +# Adding executables + +add_executable(ctbench-grapher-plot grapher-plot.cpp) +target_link_libraries(ctbench-grapher-plot PRIVATE grapher) + +add_executable(ctbench-grapher-utils grapher-utils.cpp) +target_link_libraries(ctbench-grapher-utils PRIVATE grapher) + +install(TARGETS ctbench-grapher-plot ctbench-grapher-utils + EXPORT ctbench-targets) + +if(BUILD_TESTING) add_subdirectory(tests) endif() diff --git a/grapher/cmake/libraries_fetch.cmake b/grapher/cmake/libraries_fetch.cmake deleted file mode 100644 index 9ef3e27..0000000 --- a/grapher/cmake/libraries_fetch.cmake +++ /dev/null @@ -1,53 +0,0 @@ -# ============================================================================== -# nlohmann::json - -set(JSON_BuildTests OFF) -set(JSON_Install OFF) -set(JSON_MultipleHeaders ON) -set(JSON_ImplicitConversions ON) -set(JSON_Diagnostics ON) -set(JSON_CI OFF) - -FetchContent_Declare( - json_content - GIT_REPOSITORY https://github.com/nlohmann/json.git - GIT_TAG v3.9.1 - GIT_SHALLOW) - -FetchContent_MakeAvailable(json_content) - -target_link_libraries(grapher PUBLIC nlohmann_json::nlohmann_json) - -# ============================================================================== -# Sciplot - -FetchContent_Declare( - sciplot_content - GIT_REPOSITORY https://github.com/sciplot/sciplot.git - GIT_TAG master - GIT_SHALLOW) - -FetchContent_GetProperties(sciplot_content) -if(NOT sciplot_content_POPULATED) - FetchContent_Populate(sciplot_content) -endif() - -target_include_directories(grapher PUBLIC ${sciplot_content_SOURCE_DIR}) - -# ============================================================================== -# TTS - -if(CTBENCH_ENABLE_TESTING) - FetchContent_Declare( - tts_content - GIT_REPOSITORY https://github.com/jfalcou/tts.git - GIT_TAG 1.0 - GIT_SHALLOW) - - FetchContent_GetProperties(tts_content) - if(NOT tts_content_POPULATED) - FetchContent_Populate(tts_content) - endif() - - target_include_directories(grapher PUBLIC ${tts_content_SOURCE_DIR}/include) -endif() diff --git a/grapher/cmake/libraries_local.cmake b/grapher/cmake/libraries_local.cmake deleted file mode 100644 index 9fb1a46..0000000 --- a/grapher/cmake/libraries_local.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# ============================================================================== -# nlohmann::json - -find_package(nlohmann_json 3.9.1 REQUIRED) -target_link_libraries(grapher PUBLIC nlohmann_json::nlohmann_json) - -# ============================================================================== -# Sciplot - -find_package(sciplot REQUIRED) -target_link_libraries(grapher PUBLIC sciplot::sciplot) - -# ============================================================================== -# TTS - -# https://jfalcou.github.io/tts/index.html#buildandsetup diff --git a/grapher/grapher-plot/src/main.cpp b/grapher/grapher-plot.cpp similarity index 100% rename from grapher/grapher-plot/src/main.cpp rename to grapher/grapher-plot.cpp diff --git a/grapher/grapher-plot/CMakeLists.txt b/grapher/grapher-plot/CMakeLists.txt deleted file mode 100644 index 779edf0..0000000 --- a/grapher/grapher-plot/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -file(GLOB_RECURSE GRAPHER_PLOT_SOURCES src/*.cpp) - -add_executable(grapher-plot ${GRAPHER_PLOT_SOURCES}) - -target_link_libraries(grapher-plot PRIVATE grapher) -target_include_directories(grapher-plot PRIVATE include) diff --git a/grapher/grapher-utils/src/main.cpp b/grapher/grapher-utils.cpp similarity index 100% rename from grapher/grapher-utils/src/main.cpp rename to grapher/grapher-utils.cpp diff --git a/grapher/grapher-utils/CMakeLists.txt b/grapher/grapher-utils/CMakeLists.txt deleted file mode 100644 index 024b92f..0000000 --- a/grapher/grapher-utils/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -file(GLOB_RECURSE GRAPHER_UTILS_SOURCES src/*.cpp) - -add_executable(grapher-utils ${GRAPHER_UTILS_SOURCES}) - -target_link_libraries(grapher-utils PRIVATE grapher) -target_include_directories(grapher-utils PRIVATE include) diff --git a/time-trace-wrapper/CMakeLists.txt b/time-trace-wrapper/CMakeLists.txt deleted file mode 100644 index 0e1d8e7..0000000 --- a/time-trace-wrapper/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required(VERSION 3.18) -project(time-trace-wrapper) - -set(CMAKE_CXX_STANDARD 20) - -# time-trace-wrapper -add_executable(time-trace-wrapper time-trace-wrapper.cpp) -target_include_directories(time-trace-wrapper PUBLIC include/) - -set(CTBENCH_TIME_TRACE_WRAPPER_EXEC - "${PROJECT_BINARY_DIR}/time-trace-wrapper" - PARENT_SCOPE) - -if(CTBENCH_ENABLE_TESTING) - add_executable(time-trace-wrapper-test-exec tests/time-trace-wrapper.cpp) - add_test(NAME time-trace-wrapper-test COMMAND time-trace-wrapper-test-exec) - target_include_directories(time-trace-wrapper-test-exec PUBLIC include/) -endif(CTBENCH_ENABLE_TESTING) diff --git a/ttw/CMakeLists.txt b/ttw/CMakeLists.txt new file mode 100644 index 0000000..d7de904 --- /dev/null +++ b/ttw/CMakeLists.txt @@ -0,0 +1,10 @@ +add_executable(ctbench-ttw ttw.cpp) +target_include_directories(ctbench-ttw PRIVATE include) + +install(TARGETS ctbench-ttw EXPORT ctbench-targets) + +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) diff --git a/time-trace-wrapper/include/time-trace-wrapper.hpp b/ttw/include/ttw.hpp similarity index 100% rename from time-trace-wrapper/include/time-trace-wrapper.hpp rename to ttw/include/ttw.hpp diff --git a/time-trace-wrapper/tests/time-trace-wrapper.cpp b/ttw/tests/ttw.cpp similarity index 79% rename from time-trace-wrapper/tests/time-trace-wrapper.cpp rename to ttw/tests/ttw.cpp index a95cd69..f943224 100644 --- a/time-trace-wrapper/tests/time-trace-wrapper.cpp +++ b/ttw/tests/ttw.cpp @@ -1,4 +1,4 @@ -#include +#include // auto parse_args(int argc, char const *argv[]) void test_parse_args() { @@ -16,4 +16,4 @@ void test_all() { test_get_timetrace_file(); } -int main(int argc, char const *argv[]) { test_all(); } +int main(int /*argc*/, char const * /*argv*/[]) { test_all(); } diff --git a/time-trace-wrapper/time-trace-wrapper.cpp b/ttw/ttw.cpp similarity index 97% rename from time-trace-wrapper/time-trace-wrapper.cpp rename to ttw/ttw.cpp index 5a8b8dc..991e669 100644 --- a/time-trace-wrapper/time-trace-wrapper.cpp +++ b/ttw/ttw.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include /// Wrapper for a given clang command.