🌐 AI搜索 & 代理 主页
Skip to content

Commit 032a8e9

Browse files
committed
Benchmark CMake Added And An Interface Target Created For sort.hpp
branch: [feature/restructuring] - The Google Benchmark configuration cmake added. - Will be fetch using FetchContent - Include paths fixed using CMake add_library ALIAS - A dummy target created for the better IDE support Signed-off-by: Ghasem Ramezani (Personal GCCORE GPG) <g1999ramezani@gmail.com>
1 parent 6b235b7 commit 032a8e9

File tree

5 files changed

+42
-5
lines changed

5 files changed

+42
-5
lines changed

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
cmake_minimum_required(VERSION 3.11)
22
project(SortingAlgorithms LANGUAGES CXX)
33

4+
set(CMAKE_CXX_STANDARD 11)
5+
set(CMAKE_CXX_EXTENSIONS off)
6+
set(CMAKE_CXX_STANDARD_REQUIRED on)
7+
48
include(cmake/ConfigureProjectTests.cmake)
59
Core_ConfigureProjectTests()
10+
11+
include(cmake/ConfigureProjectBenchmark.cmake)
12+
Core_ConfigureProjectBenchmark()
13+
14+
add_library(${PROJECT_NAME} INTERFACE include/sorting_algorithms/sort.hpp)
15+
add_library(SortAlgorithmsLibrary ALIAS ${PROJECT_NAME})
16+
target_include_directories(${PROJECT_NAME} INTERFACE
17+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
18+
$<INSTALL_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
19+
)

benchmark/sort_benchmark.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <benchmark/benchmark.h>
99

10-
#include "sort.hpp"
10+
#include <sorting_algorithms/sort.hpp>
1111

1212
struct SortFunc { enum type {
1313
bubble_sort,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function(Core_ConfigureProjectBenchmark)
2+
include(FetchContent)
3+
set(BENCHMARK_ENABLE_TESTING off)
4+
FetchContent_Declare(
5+
GoogleBenchmark
6+
GIT_REPOSITORY https://github.com/google/benchmark.git
7+
GIT_TAG v1.6.1
8+
)
9+
FetchContent_MakeAvailable(GoogleBenchmark)
10+
11+
set(BenchmarkTargetName ${PROJECT_NAME}Benchmark)
12+
13+
add_executable(${BenchmarkTargetName} benchmark/sort_benchmark.cpp)
14+
target_link_libraries(${BenchmarkTargetName} PRIVATE
15+
benchmark::benchmark
16+
SortAlgorithmsLibrary
17+
)
18+
endfunction()

cmake/ConfigureProjectTests.cmake

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ function(Core_ConfigureProjectTests)
77
)
88
FetchContent_MakeAvailable(Catch2)
99

10-
add_executable(${PROJECT_NAME}Tests test/sort_test.cpp)
11-
target_link_libraries(${PROJECT_NAME}Tests PRIVATE Catch2::Catch2)
10+
set(TargetName ${PROJECT_NAME}Tests)
11+
12+
add_executable(${TargetName} test/sort_test.cpp)
13+
target_link_libraries(${TargetName} PRIVATE
14+
Catch2::Catch2
15+
SortAlgorithmsLibrary
16+
)
1217

1318
include(CTest)
1419
include(${Catch2_SOURCE_DIR}/contrib/Catch.cmake)
15-
catch_discover_tests(${PROJECT_NAME}Tests)
20+
catch_discover_tests(${TargetName})
1621
endfunction()

test/sort_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#define CATCH_CONFIG_MAIN
88
#include "catch.hpp"
99

10-
#include "sort.hpp"
10+
#include <sorting_algorithms/sort.hpp>
1111

1212
static std::mt19937 gen(std::chrono::high_resolution_clock::now().time_since_epoch().count());
1313

0 commit comments

Comments
 (0)