|
1 | 1 | cmake_minimum_required(VERSION 3.20 FATAL_ERROR) |
2 | 2 |
|
3 | | -project(SortingNetworkCpp) |
| 3 | +project(sorting_network_cpp) |
4 | 4 |
|
5 | 5 | option(BUILD_BENCHMARK "Build the benchmark" ON) |
6 | 6 | option(BUILD_TESTS "Build the tests" OFF) |
7 | 7 |
|
8 | 8 | include(cmake/Conan.cmake) |
9 | 9 | run_conan() |
10 | 10 |
|
11 | | -set(SN_BENCHMARK_EXECUTABLE_NAME "sorting_network_cpp_benchmark") |
12 | | -set(SN_TESTS_EXECUTABLE_NAME "sorting_network_cpp_tests") |
13 | | - |
14 | 11 | set(CMAKE_CXX_STANDARD 17) |
15 | 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
16 | 13 |
|
17 | 14 | add_library(project_options INTERFACE) |
18 | 15 | target_compile_features(project_options INTERFACE cxx_std_17) |
19 | 16 |
|
20 | 17 | if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) |
21 | | - set(CMAKE_CXX_FLAGS_RELEASE "/W3 /O2 /fp:fast") |
22 | | - add_compile_options("-bigobj") |
| 18 | + target_compile_options(project_options INTERFACE /W3 /O2 /fp:fast) |
| 19 | + target_link_options(project_options INTERFACE /OPT:REF /GL) |
23 | 20 | elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU) |
24 | | - set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ffast-math") |
| 21 | + target_compile_options(project_options INTERFACE -O3 -ffast-math) |
25 | 22 | elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang) |
26 | | - set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ffast-math") |
| 23 | + target_compile_options(project_options INTERFACE -O3 -ffast-math) |
27 | 24 | endif() |
28 | 25 |
|
29 | | -include_directories("include") |
| 26 | +add_library(sorting_network_cpp_lib INTERFACE) |
| 27 | +target_include_directories(sorting_network_cpp_lib INTERFACE "include") |
30 | 28 |
|
31 | 29 | add_library(metal INTERFACE) |
32 | 30 | target_include_directories(metal INTERFACE "extern/metal/include") |
33 | 31 |
|
34 | 32 | if (BUILD_BENCHMARK) |
35 | | - add_executable(${SN_BENCHMARK_EXECUTABLE_NAME} "src/benchmark.cpp") |
36 | | - target_link_libraries(${SN_BENCHMARK_EXECUTABLE_NAME} PRIVATE project_options) |
| 33 | + set(SN_BENCHMARK_EXECUTABLE_NAME ${PROJECT_NAME}_benchmark) |
| 34 | + |
| 35 | + add_executable(${SN_BENCHMARK_EXECUTABLE_NAME} |
| 36 | + "src/benchmark_main.cpp" |
| 37 | + "src/benchmark_int16.cpp" |
| 38 | + "src/benchmark_int32.cpp" |
| 39 | + "src/benchmark_uint32.cpp" |
| 40 | + "src/benchmark_int64.cpp" |
| 41 | + "src/benchmark_float.cpp" |
| 42 | + "src/benchmark_double.cpp" |
| 43 | + "src/benchmark_vec2i.cpp" |
| 44 | + ) |
| 45 | + target_link_libraries(${SN_BENCHMARK_EXECUTABLE_NAME} PRIVATE project_options sorting_network_cpp_lib) |
37 | 46 | endif() |
38 | 47 |
|
39 | 48 | if(BUILD_TESTS) |
40 | | - find_package(GTest REQUIRED) |
41 | | - include(GoogleTest) |
42 | | - |
43 | | - add_executable(${SN_TESTS_EXECUTABLE_NAME} |
44 | | - "test/test_base.h" |
45 | | - "test/test_batcher_odd_even_merge_sort.cpp" |
46 | | - "test/test_bitonic_merge_sort.cpp" |
47 | | - "test/test_bose_nelson_sort.cpp" |
48 | | - "test/test_bubble_sort.cpp" |
49 | | - "test/test_insertion_sort.cpp" |
50 | | - "test/test_size_optimized_sort.cpp" |
51 | | - ) |
52 | | - target_link_libraries(${SN_TESTS_EXECUTABLE_NAME} GTest::gtest GTest::gtest_main metal project_options) |
| 49 | + set(SN_TESTS_EXECUTABLE_NAME ${PROJECT_NAME}_tests) |
| 50 | + find_package(GTest REQUIRED) |
| 51 | + include(GoogleTest) |
| 52 | + |
| 53 | + add_executable(${SN_TESTS_EXECUTABLE_NAME} |
| 54 | + "test/test_base.h" |
| 55 | + "test/test_batcher_odd_even_merge_sort.cpp" |
| 56 | + "test/test_bitonic_merge_sort.cpp" |
| 57 | + "test/test_bose_nelson_sort.cpp" |
| 58 | + "test/test_bubble_sort.cpp" |
| 59 | + "test/test_insertion_sort.cpp" |
| 60 | + "test/test_size_optimized_sort.cpp" |
| 61 | + ) |
| 62 | + target_link_libraries(${SN_TESTS_EXECUTABLE_NAME} GTest::gtest GTest::gtest_main metal project_options sorting_network_cpp_lib) |
53 | 63 | endif() |
0 commit comments