-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
69 lines (58 loc) · 2.58 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
64
65
66
67
68
69
cmake_minimum_required(VERSION 3.14)
project(natural_comparison)
add_library(${PROJECT_NAME} INTERFACE)
add_library(challenge::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_sources(${PROJECT_NAME} INTERFACE
src/challenge.hpp)
# Normally I would make this private, but since this is my own and I am lazy I can do this :)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_20)
target_compile_options(${PROJECT_NAME} INTERFACE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall>
$<$<CXX_COMPILER_ID:MSVC>:
/W4>)
######################################################################
option(BUILD_REFERENCE "Will build a reference implementation as a library,
which will also be tested. Cool for comparison." ON)
if(BUILD_REFERENCE)
add_library(${PROJECT_NAME}_Reference INTERFACE)
add_library(challenge::${PROJECT_NAME}_Reference ALIAS ${PROJECT_NAME}_Reference)
target_sources(${PROJECT_NAME}_Reference INTERFACE
src/reference.hpp)
endif()
######################################################################
option(BUILD_TESTS "Will build the tests verifying your result" ON) # If you disable this there will not be much to build...
if( BUILD_TESTS)
find_package(gtest REQUIRED)
add_executable(${PROJECT_NAME}_Tests)
target_sources(${PROJECT_NAME}_Tests PRIVATE
src/tests.cpp)
target_include_directories(${PROJECT_NAME}_Tests PRIVATE
src)
target_link_libraries(${PROJECT_NAME}_Tests PRIVATE
challenge::${PROJECT_NAME}
gtest::gtest
$<$<TARGET_EXISTS:${PROJECT_NAME}_Reference>:${PROJECT_NAME}_Reference>)
enable_testing()
include(GoogleTest)
gtest_discover_tests(${PROJECT_NAME}_Tests)
endif()
######################################################################
option(BUILD_BENCHMARK "This will enable the performance tests using google benchmark" ON)
if( BUILD_BENCHMARK)
find_package(benchmark REQUIRED)
# Requires PThreads on Linux
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
add_executable(${PROJECT_NAME}_Benchmark)
target_sources(${PROJECT_NAME}_Benchmark PRIVATE
src/benchmark.cpp)
target_link_libraries(${PROJECT_NAME}_Benchmark PRIVATE
challenge::${PROJECT_NAME}
benchmark::benchmark
Threads::Threads
$<$<TARGET_EXISTS:${PROJECT_NAME}_Reference>:${PROJECT_NAME}_Reference>)
add_custom_target(NAME ${PROJECT_NAME}_Benchmark
COMMAND ${PROJECT_NAME}_Benchmark
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()