-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
64 lines (49 loc) · 2.31 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
set(CPP_DECIMAL decimal)
project(${CPP_DECIMAL} LANGUAGES CXX)
enable_testing()
if(NOT "${CMAKE_CXX_STANDARD}")
set(CMAKE_CXX_STANDARD 17)
endif()
message(STATUS "CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}")
add_library(${CPP_DECIMAL} INTERFACE)
target_sources(${CPP_DECIMAL} INTERFACE include/decimal.hpp)
target_include_directories(${CPP_DECIMAL} INTERFACE include/)
option(ENABLE_TESTING "Enable test target generation" OFF)
option(BENCHMARK_ENABLE_TESTING "run benchmarks" OFF)
if (ENABLE_TESTING)
include(cmake/CPM.cmake)
CPMUsePackageLock(package-lock.cmake)
CPMAddPackage( NAME googletest GITHUB_REPOSITORY google/googletest VERSION 1.14.0 )
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
include_directories(googletest_SOURCE_DIR)
enable_testing()
FILE(GLOB tests CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/test/*)
FOREACH (test ${tests})
get_filename_component(test_name ${test} NAME)
message("Adding test: " ${test_name})
add_executable(${test_name} ${PROJECT_SOURCE_DIR}/test/${test_name})
target_link_libraries(${test_name} PRIVATE ${CPP_DECIMAL} gtest gtest_main)
add_test(${test_name} ${test_name})
set_property(TEST ${test_name} PROPERTY LABELS "test")
ENDFOREACH ()
if (BENCHMARK_ENABLE_TESTING)
CPMAddPackage( NAME benchmark GITHUB_REPOSITORY google/benchmark VERSION 1.5.2 OPTIONS "BENCHMARK_ENABLE_TESTING Off")
if(TARGET benchmark::benchmark)
# enable c++11 to avoid compilation errors
set_target_properties(benchmark PROPERTIES CXX_STANDARD 17)
endif()
FILE(GLOB tests ${PROJECT_SOURCE_DIR}/bench/*)
FOREACH (test ${tests})
get_filename_component(test_name ${test} NAME)
message("Adding bench: " ${test_name})
add_executable(${test_name} ${PROJECT_SOURCE_DIR}/bench/${test_name})
target_link_libraries(${test_name} PRIVATE benchmark::benchmark ${CPP_DECIMAL})
add_test(${test_name} ${test_name})
set_property(TEST ${test_name} PROPERTY LABELS "bench")
list(APPEND ignore_tests ${test_name})
ENDFOREACH ()
set (CMAKE_CTEST_ARGUMENTS "-L;test")
add_custom_target(fastchan_bench COMMAND ctest -L bench -V)
endif()
endif()