Skip to content

Commit 782714b

Browse files
committed
replace conan with CPM, default disable all non-lib targets
1 parent 3bf191e commit 782714b

File tree

5 files changed

+53
-87
lines changed

5 files changed

+53
-87
lines changed

CMakeLists.txt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,30 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
22

33
project(sorting_network_cpp)
44

5-
option(BUILD_BENCHMARK "Build the benchmark" ON)
6-
option(BUILD_TESTS "Build the tests" OFF)
7-
8-
include(cmake/Conan.cmake)
9-
run_conan()
5+
option(SORTING_NETWORK_CPP_BUILD_BENCHMARK "Build the benchmark" OFF)
6+
option(SORTING_NETWORK_CPP_BUILD_TESTS "Build the tests" OFF)
107

118
set(CMAKE_CXX_STANDARD 17)
129
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1310

11+
include(cmake/CPM.cmake)
12+
1413
add_library(project_options INTERFACE)
1514
target_compile_features(project_options INTERFACE cxx_std_17)
1615

1716
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
18-
target_compile_options(project_options INTERFACE /W3 /O2 /fp:fast)
19-
target_link_options(project_options INTERFACE /OPT:REF /GL)
17+
target_compile_options(project_options INTERFACE $<$<NOT:$<CONFIG:Debug>>: /W3 /O2 /fp:fast> /bigobj)
18+
target_link_options(project_options INTERFACE $<$<NOT:$<CONFIG:Debug>>: /OPT:REF /GL>)
2019
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
21-
target_compile_options(project_options INTERFACE -O3 -ffast-math)
20+
target_compile_options(project_options INTERFACE $<$<NOT:$<CONFIG:Debug>>: -O3 -ffast-math>)
2221
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
23-
target_compile_options(project_options INTERFACE -O3 -ffast-math)
22+
target_compile_options(project_options INTERFACE $<$<NOT:$<CONFIG:Debug>>: -O3 -ffast-math>)
2423
endif()
2524

26-
add_library(sorting_network_cpp_lib INTERFACE)
27-
target_include_directories(sorting_network_cpp_lib INTERFACE "include")
25+
add_library(sorting_network_cpp INTERFACE)
26+
target_include_directories(sorting_network_cpp INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
2827

29-
add_library(metal INTERFACE)
30-
target_include_directories(metal INTERFACE "extern/metal/include")
31-
32-
if (BUILD_BENCHMARK)
28+
if (SORTING_NETWORK_CPP_BUILD_BENCHMARK)
3329
set(SN_BENCHMARK_EXECUTABLE_NAME ${PROJECT_NAME}_benchmark)
3430

3531
add_executable(${SN_BENCHMARK_EXECUTABLE_NAME}
@@ -42,13 +38,17 @@ if (BUILD_BENCHMARK)
4238
"src/benchmark_double.cpp"
4339
"src/benchmark_vec2i.cpp"
4440
)
45-
target_link_libraries(${SN_BENCHMARK_EXECUTABLE_NAME} PRIVATE project_options sorting_network_cpp_lib)
41+
target_link_libraries(${SN_BENCHMARK_EXECUTABLE_NAME} PRIVATE project_options sorting_network_cpp)
4642
endif()
4743

48-
if(BUILD_TESTS)
44+
if(SORTING_NETWORK_CPP_BUILD_TESTS)
45+
set(METAL_BUILD_DOC OFF)
46+
set(METAL_BUILD_EXAMPLES OFF)
47+
set(METAL_BUILD_TESTS OFF)
48+
CPMAddPackage("gh:brunocodutra/metal#v2.1.4")
49+
CPMAddPackage("gh:google/googletest#release-1.12.0")
50+
4951
set(SN_TESTS_EXECUTABLE_NAME ${PROJECT_NAME}_tests)
50-
find_package(GTest REQUIRED)
51-
include(GoogleTest)
5252

5353
add_executable(${SN_TESTS_EXECUTABLE_NAME}
5454
"test/test_base.h"
@@ -59,5 +59,5 @@ if(BUILD_TESTS)
5959
"test/test_insertion_sort.cpp"
6060
"test/test_size_optimized_sort.cpp"
6161
)
62-
target_link_libraries(${SN_TESTS_EXECUTABLE_NAME} GTest::gtest GTest::gtest_main metal project_options sorting_network_cpp_lib)
62+
target_link_libraries(${SN_TESTS_EXECUTABLE_NAME} GTest::gtest GTest::gmock GTest::gtest_main Metal project_options sorting_network_cpp)
6363
endif()

cmake/CPM.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
set(CPM_DOWNLOAD_VERSION 0.38.1)
2+
3+
if(CPM_SOURCE_CACHE)
4+
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
5+
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
6+
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
7+
else()
8+
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
9+
endif()
10+
11+
# Expand relative path. This is important if the provided path contains a tilde (~)
12+
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
13+
14+
function(download_cpm)
15+
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
16+
file(DOWNLOAD
17+
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
18+
${CPM_DOWNLOAD_LOCATION}
19+
)
20+
endfunction()
21+
22+
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
23+
download_cpm()
24+
else()
25+
# resume download if it previously failed
26+
file(READ ${CPM_DOWNLOAD_LOCATION} check)
27+
if("${check}" STREQUAL "")
28+
download_cpm()
29+
endif()
30+
unset(check)
31+
endif()
32+
33+
include(${CPM_DOWNLOAD_LOCATION})

cmake/Conan.cmake

Lines changed: 0 additions & 58 deletions
This file was deleted.

conanfile.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

extern/metal

Submodule metal deleted from 8d68773

0 commit comments

Comments
 (0)