Debian Codegraph @

debian/rust-vendor/blake3/c/cmake/BLAKE3/ContinuousIntegration.cmake

raw
1 cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
2
3 if(BUILD_SHARED_LIBS)
4 message(FATAL_ERROR "BUILD_SHARED_LIBS is incompatible with BLAKE3_TESTING_CI")
5 endif()
6
7 include(CTest)
8
9 # Declare a testing specific variant of the `blake3` library target.
10 #
11 # We use a separate library target in order to be able to perform compilation with various
12 # combinations of features which are too noisy to specify in the main CMake config as options for
13 # the normal `blake3` target.
14 #
15 # Initially this target has no properties but eventually we will populate them by copying all of the
16 # relevant properties from the normal `blake3` target.
17 add_library(blake3-testing
18 blake3.c
19 blake3_dispatch.c
20 blake3_portable.c
21 )
22
23 if(BLAKE3_USE_TBB AND TBB_FOUND)
24 target_sources(blake3-testing
25 PRIVATE
26 blake3_tbb.cpp)
27 endif()
28
29 if(BLAKE3_SIMD_TYPE STREQUAL "amd64-asm")
30 # Conditionally add amd64 asm files to `blake3-testing` sources
31 if(MSVC)
32 if(NOT BLAKE3_NO_AVX2)
33 list(APPEND BLAKE3_TESTING_AMD64_ASM_SOURCES blake3_avx2_x86-64_windows_msvc.asm)
34 endif()
35 if(NOT BLAKE3_NO_AVX512)
36 list(APPEND BLAKE3_TESTING_AMD64_ASM_SOURCES blake3_avx512_x86-64_windows_msvc.asm)
37 endif()
38 if(NOT BLAKE3_NO_SSE2)
39 list(APPEND BLAKE3_TESTING_AMD64_ASM_SOURCES blake3_sse2_x86-64_windows_msvc.asm)
40 endif()
41 if(NOT BLAKE3_NO_SSE41)
42 list(APPEND BLAKE3_TESTING_AMD64_ASM_SOURCES blake3_sse41_x86-64_windows_msvc.asm)
43 endif()
44 elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU"
45 OR CMAKE_C_COMPILER_ID STREQUAL "Clang"
46 OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
47 if (WIN32)
48 if(NOT BLAKE3_NO_AVX2)
49 list(APPEND BLAKE3_TESTING_AMD64_ASM_SOURCES blake3_avx2_x86-64_windows_gnu.S)
50 endif()
51 if(NOT BLAKE3_NO_AVX512)
52 list(APPEND BLAKE3_TESTING_AMD64_ASM_SOURCES blake3_avx512_x86-64_windows_gnu.S)
53 endif()
54 if(NOT BLAKE3_NO_SSE2)
55 list(APPEND BLAKE3_TESTING_AMD64_ASM_SOURCES blake3_sse2_x86-64_windows_gnu.S)
56 endif()
57 if(NOT BLAKE3_NO_SSE41)
58 list(APPEND BLAKE3_TESTING_AMD64_ASM_SOURCES blake3_sse41_x86-64_windows_gnu.S)
59 endif()
60 elseif(UNIX)
61 if(NOT BLAKE3_NO_AVX2)
62 list(APPEND BLAKE3_TESTING_AMD64_ASM_SOURCES blake3_avx2_x86-64_unix.S)
63 endif()
64 if(NOT BLAKE3_NO_AVX512)
65 list(APPEND BLAKE3_TESTING_AMD64_ASM_SOURCES blake3_avx512_x86-64_unix.S)
66 endif()
67 if(NOT BLAKE3_NO_SSE2)
68 list(APPEND BLAKE3_TESTING_AMD64_ASM_SOURCES blake3_sse2_x86-64_unix.S)
69 endif()
70 if(NOT BLAKE3_NO_SSE41)
71 list(APPEND BLAKE3_TESTING_AMD64_ASM_SOURCES blake3_sse41_x86-64_unix.S)
72 endif()
73 endif()
74 endif()
75 target_sources(blake3-testing PRIVATE ${BLAKE3_AMD64_ASM_SOURCES})
76 elseif(BLAKE3_SIMD_TYPE STREQUAL "x86-intrinsics")
77 # Conditionally add amd64 C files to `blake3-testing` sources
78 if (NOT DEFINED BLAKE3_CFLAGS_SSE2
79 OR NOT DEFINED BLAKE3_CFLAGS_SSE4.1
80 OR NOT DEFINED BLAKE3_CFLAGS_AVX2
81 OR NOT DEFINED BLAKE3_CFLAGS_AVX512)
82 message(WARNING "BLAKE3_SIMD_TYPE is set to 'x86-intrinsics' but no compiler flags are available for the target architecture.")
83 else()
84 set(BLAKE3_SIMD_X86_INTRINSICS ON)
85 endif()
86
87 if(NOT BLAKE3_NO_AVX2)
88 target_sources(blake3-testing PRIVATE blake3_avx2.c)
89 set_source_files_properties(blake3_avx2.c PROPERTIES COMPILE_FLAGS "${BLAKE3_CFLAGS_AVX2}")
90 endif()
91 if(NOT BLAKE3_NO_AVX512)
92 target_sources(blake3-testing PRIVATE blake3_avx512.c)
93 set_source_files_properties(blake3_avx512.c PROPERTIES COMPILE_FLAGS "${BLAKE3_CFLAGS_AVX512}")
94 endif()
95 if(NOT BLAKE3_NO_SSE2)
96 target_sources(blake3-testing PRIVATE blake3_sse2.c)
97 set_source_files_properties(blake3_sse2.c PROPERTIES COMPILE_FLAGS "${BLAKE3_CFLAGS_SSE2}")
98 endif()
99 if(NOT BLAKE3_NO_SSE41)
100 target_sources(blake3-testing PRIVATE blake3_sse41.c)
101 set_source_files_properties(blake3_sse41.c PROPERTIES COMPILE_FLAGS "${BLAKE3_CFLAGS_SSE4.1}")
102 endif()
103
104 elseif(BLAKE3_SIMD_TYPE STREQUAL "neon-intrinsics")
105 # Conditionally add neon C files to `blake3-testing` sources
106
107 target_sources(blake3-testing PRIVATE
108 blake3_neon.c
109 )
110 target_compile_definitions(blake3-testing PRIVATE
111 BLAKE3_USE_NEON=1
112 )
113
114 if (DEFINED BLAKE3_CFLAGS_NEON)
115 set_source_files_properties(blake3_neon.c PROPERTIES COMPILE_FLAGS "${BLAKE3_CFLAGS_NEON}")
116 endif()
117
118 elseif(BLAKE3_SIMD_TYPE STREQUAL "none")
119 # Disable neon if simd type is "none". We check for individual amd64 features further below.
120
121 target_compile_definitions(blake3-testing PRIVATE
122 BLAKE3_USE_NEON=0
123 )
124
125 endif()
126
127 if(BLAKE3_NO_AVX2)
128 target_compile_definitions(blake3-testing PRIVATE BLAKE3_NO_AVX2)
129 endif()
130 if(BLAKE3_NO_AVX512)
131 target_compile_definitions(blake3-testing PRIVATE BLAKE3_NO_AVX512)
132 endif()
133 if(BLAKE3_NO_SSE2)
134 target_compile_definitions(blake3-testing PRIVATE BLAKE3_NO_SSE2)
135 endif()
136 if(BLAKE3_NO_SSE41)
137 target_compile_definitions(blake3-testing PRIVATE BLAKE3_NO_SSE41)
138 endif()
139
140 target_compile_definitions(blake3-testing PUBLIC BLAKE3_TESTING)
141
142 get_target_property(BLAKE3_COMPILE_DEFINITIONS blake3 COMPILE_DEFINITIONS)
143 if(BLAKE3_COMPILE_DEFINITIONS)
144 target_compile_definitions(blake3-testing PUBLIC
145 ${BLAKE3_COMPILE_DEFINITIONS})
146 endif()
147
148 get_target_property(BLAKE3_COMPILE_OPTIONS blake3 COMPILE_OPTIONS)
149 if(BLAKE3_COMPILE_OPTIONS)
150 target_compile_options(blake3-testing PRIVATE
151 ${BLAKE3_COMPILE_OPTIONS}
152 -O3
153 -Wall
154 -Wextra
155 -pedantic
156 -fstack-protector-strong
157 -D_FORTIFY_SOURCE=2
158 -fPIE
159 -fvisibility=hidden
160 -fsanitize=address,undefined
161 )
162 endif()
163
164 get_target_property(BLAKE3_INCLUDE_DIRECTORIES blake3 INCLUDE_DIRECTORIES)
165 if(BLAKE3_INCLUDE_DIRECTORIES)
166 target_include_directories(blake3-testing PUBLIC
167 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
168 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
169 )
170 endif()
171
172 get_target_property(BLAKE3_LINK_LIBRARIES blake3 LINK_LIBRARIES)
173 if(BLAKE3_LINK_LIBRARIES)
174 target_link_libraries(blake3-testing PRIVATE ${BLAKE3_LINK_LIBRARIES})
175 endif()
176
177 get_target_property(BLAKE3_LINK_OPTIONS blake3 LINK_OPTIONS)
178 if(BLAKE3_LINK_OPTIONS)
179 target_link_options(blake3-testing PRIVATE
180 ${BLAKE3_LINK_OPTIONS}
181 -fsanitize=address,undefined
182 -pie
183 -Wl,-z,relro,-z,now
184 )
185 endif()
186
187 # test asm target
188 add_executable(blake3-asm-test
189 main.c
190 )
191 set_target_properties(blake3-asm-test PROPERTIES
192 OUTPUT_NAME blake3
193 RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
194 target_link_libraries(blake3-asm-test PRIVATE blake3-testing)
195 target_compile_definitions(blake3-asm-test PRIVATE BLAKE3_TESTING)
196 target_compile_options(blake3-asm-test PRIVATE
197 -O3
198 -Wall
199 -Wextra
200 -pedantic
201 -fstack-protector-strong
202 -D_FORTIFY_SOURCE=2
203 -fPIE
204 -fvisibility=hidden
205 -fsanitize=address,undefined
206 )
207 target_link_options(blake3-asm-test PRIVATE
208 -fsanitize=address,undefined
209 -pie
210 -Wl,-z,relro,-z,now
211 )
212
213 add_test(NAME blake3-testing
214 COMMAND "${CMAKE_CTEST_COMMAND}"
215 --verbose
216 --extra-verbose
217 --build-and-test "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}"
218 --build-generator "${CMAKE_GENERATOR}"
219 --build-makeprogram "${CMAKE_MAKE_PROGRAM}"
220 --build-project libblake3
221 --build-target blake3-asm-test
222 --build-options
223 --fresh
224 "-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}"
225 "-DBLAKE3_TESTING=${BLAKE3_TESTING}"
226 "-DBLAKE3_TESTING_CI=${BLAKE3_TESTING_CI}"
227 "-DBLAKE3_USE_TBB=${BLAKE3_USE_TBB}"
228 "-DBLAKE3_SIMD_TYPE=${BLAKE3_SIMD_TYPE}"
229 "-DBLAKE3_NO_SSE2=${BLAKE3_NO_SSE2}"
230 "-DBLAKE3_NO_SSE41=${BLAKE3_NO_SSE41}"
231 "-DBLAKE3_NO_AVX2=${BLAKE3_NO_AVX2}"
232 "-DBLAKE3_NO_AVX512=${BLAKE3_NO_AVX512}"
233 --test-command
234 "${CMAKE_SOURCE_DIR}/test.py"
235 )