1 get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
2 string_append(CMAKE_CXX_FLAGS ${WARNINGS_XX} ${SANITIZE_XX})
3 string_append(CMAKE_C_FLAGS ${WARNINGS_CC} ${SANITIZE_CC})
4 string_append(CMAKE_EXE_LINKER_FLAGS ${SANITIZE_LD})
6 function(set_executable_options)
7 list(FIND ENABLED_LANGUAGES CXX HAS_CXX)
8 set_target_properties(${ARGN} PROPERTIES
9 INTERPROCEDURAL_OPTIMIZATION ${LIBA_IPO}
10 POSITION_INDEPENDENT_CODE ${LIBA_PIE}
13 if(${HAS_CXX} GREATER -1)
14 set_property(TARGET ${ARGN} APPEND PROPERTY COMPILE_DEFINITIONS HAS_CXX)
17 if(LIBA_IWYU AND IWYU_FOUND)
18 add_include_what_you_use(TARGETS ${ARGN})
21 if(LIBA_CLANG_TIDY AND CLANG_TIDY_FOUND)
22 add_clang_tidy(TARGETS ${ARGN} OPTIONS --fix)
25 if(LIBA_CPPCHECK AND CPPCHECK_FOUND)
26 add_cppcheck(TARGETS ${ARGN} OPTIONS --enable=warning,performance)
30 target_compile_analyzer(${ARGN})
34 target_link_static(${ARGN})
38 set(TARGET_PREFIX test.)
40 function(building target)
41 set(TARGET "${TARGET_PREFIX}${target}")
42 list(FIND ENABLED_LANGUAGES CXX HAS_CXX)
44 if(${HAS_CXX} EQUAL -1)
45 file_filter(ARGN ${ARGN} EXT c h)
48 if(NOT TARGET_SUPPORTS_EXECUTABLES)
49 add_library(${TARGET} STATIC ${ARGN})
51 add_executable(${TARGET} ${ARGN})
54 set_property(TARGET ${TARGET} PROPERTY OUTPUT_NAME ${target})
56 if(TARGET_SUPPORTS_SHARED_LIBS AND LIBA_SANITIZE)
57 target_link_libraries(${TARGET} PRIVATE libasan)
58 elseif(NOT CMAKE_VERSION VERSION_LESS 3.12 AND LIBA_SANITIZE)
59 target_link_libraries(${TARGET} PRIVATE asan)
60 elseif(BUILD_SHARED_LIBS)
61 target_link_libraries(${TARGET} PRIVATE liba)
63 target_link_libraries(${TARGET} PRIVATE liba.o)
66 set_executable_options(${TARGET})
69 function(unittest target)
70 set(TARGET "${TARGET_PREFIX}${target}")
71 cmake_parse_arguments(TEST "" "NAME" "ARGS" ${ARGN})
75 set(TEST_NAME ${target})
79 set(BINARY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
81 set(BINARY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
84 if((BUILD_SHARED_LIBS OR LIBA_SANITIZE) AND IS_MULTI_CONFIG)
85 set(WORKING_DIRECTORY $<TARGET_FILE_DIR:alib>)
87 set(WORKING_DIRECTORY ${BINARY_DIRECTORY})
90 foreach(arg ${TEST_ARGS} ${TEST_UNPARSED_ARGUMENTS})
91 get_filename_component(ext ${arg} EXT)
93 if(NOT ext OR IS_ABSOLUTE ${arg})
94 list(APPEND ARGS ${arg})
95 elseif(NOT EMSCRIPTEN)
96 list(APPEND ARGS ${BINARY_DIRECTORY}/${arg})
100 if(NOT TARGET_SUPPORTS_EXECUTABLES AND NOT CMAKE_CROSSCOMPILING_EMULATOR)
104 add_test(NAME ${TEST_NAME} WORKING_DIRECTORY ${WORKING_DIRECTORY}
105 COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:${TARGET}> ${ARGS}
107 set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 30
108 FAIL_REGULAR_EXPRESSION "ERROR;error;:[0-9]+:"
112 option(LIBA_GNUPLOT "Enable/Disable gnuplot" 0)
115 find_package(Gnuplot)
118 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
119 function(unitplot target script output)
120 set(TARGET "${TARGET_PREFIX}${target}")
121 set(SOURCE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
124 set(BINARY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
126 set(BINARY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
129 if((BUILD_SHARED_LIBS OR LIBA_SANITIZE) AND IS_MULTI_CONFIG)
130 set(WORKING_DIRECTORY $<TARGET_FILE_DIR:alib>)
132 set(WORKING_DIRECTORY ${BINARY_DIRECTORY})
135 if(NOT IS_ABSOLUTE ${script})
136 file(TO_CMAKE_PATH ${SOURCE_DIRECTORY}/${script} script)
139 if(NOT IS_ABSOLUTE ${output})
140 file(TO_CMAKE_PATH ${BINARY_DIRECTORY}/${output} output)
143 if(NOT TARGET_SUPPORTS_EXECUTABLES AND NOT CMAKE_CROSSCOMPILING_EMULATOR)
147 add_custom_command(TARGET ${TARGET} POST_BUILD WORKING_DIRECTORY ${WORKING_DIRECTORY}
148 COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:${TARGET}> ${output} ${ARGN}
149 COMMAND ${GNUPLOT_EXECUTABLE} -c ${script} ${output}
155 unittest(a NAME a_for ARGS for 10)
156 unittest(a NAME a_hash_bkdr ARGS hash_bkdr hash_bkdr)
157 unittest(a NAME a_hash_sdbm ARGS hash_sdbm hash_sdbm)
160 building(avl avl.c avl.cc)
163 building(buf buf.c buf.cc)
166 building(complex complex.c complex.cc)
167 unittest(complex ARGS -4,3 -2,1)
169 building(crc crc.c crc.cc)
170 unittest(crc ARGS crc.c)
172 building(hpf hpf.c hpf.cc)
175 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
176 unitplot(hpf 2.gp hpf.csv)
179 building(list list.c list.cc)
182 building(lpf lpf.c lpf.cc)
185 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
186 unitplot(lpf 3.gp lpf.csv)
189 building(math math.c math.cc)
192 building(mf mf.c mf.cc)
195 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
196 unitplot(mf mf.gp mf_gauss.csv -4 4 1 0)
197 unitplot(mf mf.gp mf_gauss2.csv -4 4 1 -1 1 1)
198 unitplot(mf mf.gp mf_gbell.csv -4 4 2 4 0)
199 unitplot(mf mf.gp mf_sig.csv -4 4 2 0)
200 unitplot(mf mf.gp mf_dsig.csv -4 4 5 -2 5 2)
201 unitplot(mf mf.gp mf_psig.csv -4 4 5 -2 -5 2)
202 unitplot(mf mf.gp mf_trap.csv -3 3 -2 -1 1 2)
203 unitplot(mf mf.gp mf_tri.csv -2 2 -1 0 1)
204 unitplot(mf mf.gp mf_lins.csv -2 2 -1 1)
205 unitplot(mf mf.gp mf_linz.csv -2 2 -1 1)
206 unitplot(mf mf.gp mf_s.csv -2 2 -1 1)
207 unitplot(mf mf.gp mf_z.csv -2 2 -1 1)
208 unitplot(mf mf.gp mf_pi.csv -3 3 -2 -1 1 2)
211 building(notefreqs notefreqs.c notefreqs.cc)
214 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
215 unitplot(notefreqs notefreqs.gp notefreqs.csv)
218 building(operator operator.c operator.cc)
221 building(pid pid.c pid.cc)
224 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
225 unitplot(pid 3.gp pid.csv)
228 building(pid_expert pid_expert.c pid_expert.cc)
231 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
232 unitplot(pid_expert 3.gp pid_expert.csv)
235 building(pid_fuzzy pid_fuzzy.c pid_fuzzy.cc)
238 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
239 unitplot(pid_fuzzy 3.gp pid_fuzzy.csv)
242 building(pid_neuro pid_neuro.c pid_neuro.cc)
245 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
246 unitplot(pid_neuro 3.gp pid_neuro.csv)
249 building(poly poly.c poly.cc)
252 building(que que.c que.cc)
255 building(rbt rbt.c rbt.cc)
258 building(slist slist.c slist.cc)
261 building(str str.c str.cc)
264 building(test test.c test.cc)
267 building(tf tf.c tf.cc)
270 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
271 unitplot(tf 2.gp tf.csv)
274 building(trajbell trajbell.c trajbell.cc)
275 unittest(trajbell ARGS trajbell.csv 3 2 3 0 10)
277 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
278 unitplot(trajbell traj4.gp trajbell.csv 3 2 3 0 10)
281 building(trajpoly3 trajpoly3.c trajpoly3.cc)
282 unittest(trajpoly3 ARGS trajpoly3.csv 0 10 0 10)
284 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
285 unitplot(trajpoly3 traj3.gp trajpoly3.csv 0 10 0 10)
288 building(trajpoly5 trajpoly5.c trajpoly5.cc)
289 unittest(trajpoly5 ARGS trajpoly5.csv 0 10 0 10)
291 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
292 unitplot(trajpoly5 traj3.gp trajpoly5.csv 0 10 0 10)
295 building(trajpoly7 trajpoly7.c trajpoly7.cc)
296 unittest(trajpoly7 ARGS trajpoly7.csv 0 10 0 10)
298 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
299 unitplot(trajpoly7 traj4.gp trajpoly7.csv 0 10 0 10)
302 building(trajtrap trajtrap.c trajtrap.cc)
303 unittest(trajtrap ARGS trajtrap.csv 2 2 -2 0 4)
305 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
306 unitplot(trajtrap traj3.gp trajtrap.csv 2 2 -2 0 4)
309 building(utf utf.c utf.cc)
312 building(vec vec.c vec.cc)
315 building(version version.c version.cc)