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

CMake overhaul #6

Merged
merged 26 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
79852fe
Bump DAC version
JPenuchot Mar 29, 2022
5400a5b
Moved internal API into benchmarking.cmake
JPenuchot Mar 29, 2022
c59ad08
Shiny docs
JPenuchot Mar 29, 2022
8a7e089
Major CMake overhaul in preparation for an installable ctbench first …
JPenuchot Mar 29, 2022
b3a3c17
Command name change
JPenuchot Mar 29, 2022
c626048
Temporarily restored CTBENCH_TIME_TRACE_WRAPPER_EXEC variable export
JPenuchot Mar 29, 2022
44fd30f
Fixed CTBENCH_TIME_TRACE_WRAPPER_EXEC export
JPenuchot Mar 29, 2022
8012016
CMake overhaul: target exports and install targets
JPenuchot Mar 29, 2022
2779569
Updated target dependency
JPenuchot Mar 29, 2022
3a4196b
Renamed time-trace-wrapper as ttw
JPenuchot Mar 29, 2022
3360a02
Renamed time-trace-wrapper as ttw
JPenuchot Mar 29, 2022
a87d038
Format + set include to private for test target
JPenuchot Mar 29, 2022
f0a5b2d
Changed subdir path to ttw, added subdir folder definitions for bench…
JPenuchot Mar 29, 2022
1276aef
cmake-format
JPenuchot Mar 29, 2022
89d34a2
Added ttw and ctbench prefixes to exec paths
JPenuchot Mar 29, 2022
827edeb
Changed TIME_TRACE_WRAPPER_FOLDER to TTW_FOLDER
JPenuchot Mar 29, 2022
45c744d
Propagate folder prefixes to parent scope
JPenuchot Mar 29, 2022
d8b9b92
Added benchmark dependency to ctbench-ttw
JPenuchot Mar 29, 2022
7750a08
Added CTBENCH_PORTABLE variable, defined only when ctbench is importe…
JPenuchot Mar 29, 2022
8fd9421
Moved prefix definitions inside benchmarking.cmake
JPenuchot Mar 29, 2022
085a85c
Fixed prefix names
JPenuchot Mar 29, 2022
9b8d56f
Added debug lines for executable prefixes in portable mode
JPenuchot Mar 29, 2022
8fe9977
Removed CTBENCH_PORTABLE, now relying on ctbench_FOUND to find out wh…
JPenuchot Mar 29, 2022
f0d134b
Fixed prefix setting
JPenuchot Mar 29, 2022
f25572c
Added info regarding folder/target prefixes, and added dependency to …
JPenuchot Mar 30, 2022
4c4a94a
Fixed add_dependencies call in ctbench_add_graph
JPenuchot Mar 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
95 changes: 80 additions & 15 deletions benchmarking.cmake → cmake/benchmarking.cmake
Original file line number Diff line number Diff line change
@@ -1,31 +1,82 @@
#! # 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.
#!
#! - `name`: Name of benchmark
#! - `source`: Source file
#! - `begin, end, step`: Iteration parameters
#! - `samples`: Number of samples per iteration
#!

function(
ctbench_add_benchmark
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -100,24 +154,35 @@ 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.
#!
#! - `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)

#!
#! --
8 changes: 4 additions & 4 deletions cmake/docs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
30 changes: 0 additions & 30 deletions cmake/internal.cmake

This file was deleted.

53 changes: 23 additions & 30 deletions grapher/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
53 changes: 0 additions & 53 deletions grapher/cmake/libraries_fetch.cmake

This file was deleted.

16 changes: 0 additions & 16 deletions grapher/cmake/libraries_local.cmake

This file was deleted.

File renamed without changes.
6 changes: 0 additions & 6 deletions grapher/grapher-plot/CMakeLists.txt

This file was deleted.

File renamed without changes.
6 changes: 0 additions & 6 deletions grapher/grapher-utils/CMakeLists.txt

This file was deleted.

Loading