Skip to content

Commit

Permalink
Merge pull request #6 from JPenuchot/dev
Browse files Browse the repository at this point in the history
CMake overhaul
  • Loading branch information
JPenuchot authored Mar 30, 2022
2 parents 47876a3 + 4c4a94a commit c7cadc7
Show file tree
Hide file tree
Showing 16 changed files with 129 additions and 199 deletions.
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

0 comments on commit c7cadc7

Please sign in to comment.