-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCMakeLists.txt
122 lines (103 loc) · 4.35 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
cmake_minimum_required(VERSION 3.23 FATAL_ERROR)
project(signature VERSION 0.9.0 LANGUAGES CXX)
# Options
option(SIGNATURE_BUILD_MAIN "Build main" OFF)
option(SIGNATURE_BUILD_TESTS "Build tests" OFF)
option(SIGNATURE_BUILD_BENCHMARKS "Build benchmarks" OFF)
option(SIGNATURE_INSTALL_HEADERS "Install signature headers" ON)
option(SIGNATURE_INSTALL_CONFIG "Install signature config" ${SIGNATURE_INSTALL_HEADERS})
option(SIGNATURE_INSTALL_LIBDIR "Install signature config prefix" ${CMAKE_INSTALL_LIBDIR})
if(SIGNATURE_INSTALL_CONFIG AND NOT SIGNATURE_INSTALL_HEADERS)
message(FATAL_ERROR "SIGNATURE_INSTALL_CONFIG requires SIGNATURE_INSTALL_HEADERS")
endif()
if(NOT SIGNATURE_INSTALL_LIBDIR)
set(SIGNATURE_INSTALL_LIBDIR .)
endif()
# Build Configuration
if(SIGNATURE_BUILD_BENCHMARKS OR SIGNATURE_BUILD_TESTS OR SIGNATURE_BUILD_MAIN)
# Set conan install directory.
if(WIN32)
set(third_party third_party/msvc)
else()
set(third_party third_party/llvm)
endif()
# Copy binaries installed with conan to build directory.
if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${third_party}/bin)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${third_party}/bin/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endif()
# Add conan install directory to module and config search paths.
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${third_party})
list(PREPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${third_party})
# Find common dependencies.
find_package(TBB REQUIRED COMPONENTS tbb)
# Enable buffer security checks for debug builds.
if(MSVC)
string(APPEND CMAKE_CXX_FLAGS_DEBUG " /GS")
endif()
# Configures target and sources.
function(signature_configure_target target)
# Configure standard library and system headers.
if(WIN32)
target_compile_definitions(${target} PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
else()
target_compile_definitions(${target} PRIVATE -D_LIBCPP_ENABLE_EXPERIMENTAL=1)
target_compile_options(${target} PRIVATE -stdlib=libc++)
target_link_libraries(${target} PRIVATE c++ c++experimental)
endif()
# Enable AVX2 support.
foreach(source IN LISTS ARGN)
if(source MATCHES "avx_" OR source MATCHES "memory.cpp" OR source MATCHES "main.cpp")
if(MSVC)
set_source_files_properties(${source} PROPERTIES COMPILE_OPTIONS "/arch:AVX2")
else()
set_source_files_properties(${source} PROPERTIES COMPILE_OPTIONS "-mavx2")
endif()
endif()
endforeach()
endfunction()
endif()
# Library
file(GLOB headers include/qis/*.hpp)
add_library(signature INTERFACE ${headers})
target_compile_features(signature INTERFACE cxx_std_23)
target_include_directories(signature INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
if(SIGNATURE_INSTALL_HEADERS)
install(DIRECTORY include/ DESTINATION include FILES_MATCHING PATTERN "*.hpp")
endif()
if(SIGNATURE_INSTALL_CONFIG)
install(TARGETS signature EXPORT signature)
install(EXPORT signature FILE signature-config.cmake
NAMESPACE qis:: DESTINATION ${SIGNATURE_INSTALL_LIBDIR}/cmake/signature)
endif()
add_library(qis::signature ALIAS signature)
# Main
if(SIGNATURE_BUILD_MAIN)
file(GLOB sources src/main.cpp)
add_executable(main ${sources})
target_compile_features(main PRIVATE cxx_std_23)
target_include_directories(main PRIVATE include src)
target_link_libraries(main PRIVATE TBB::tbb)
signature_configure_target(main ${sources})
endif()
# Tests
if(SIGNATURE_BUILD_TESTS)
find_package(doctest REQUIRED)
file(GLOB tests_headers src/memory.hpp src/tests.hpp)
file(GLOB tests_sources src/memory.cpp src/tests.cpp src/tests/*.cpp)
add_executable(tests ${tests_headers} ${tests_sources})
target_link_libraries(tests PRIVATE doctest::doctest TBB::tbb signature)
target_include_directories(tests PRIVATE src)
signature_configure_target(tests ${tests_sources})
endif()
# Benchmarks
if(SIGNATURE_BUILD_BENCHMARKS)
find_package(benchmark REQUIRED)
file(GLOB benchmark_headers src/memory.hpp src/benchmarks.hpp)
file(GLOB benchmark_sources src/memory.cpp src/benchmarks.cpp src/benchmarks/*.cpp)
add_executable(benchmarks ${benchmark_headers} ${benchmark_sources})
target_link_libraries(benchmarks PRIVATE benchmark::benchmark TBB::tbb signature)
target_include_directories(benchmarks PRIVATE src)
signature_configure_target(benchmarks ${benchmark_sources})
endif()