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)
110 option(LIBA_GNUPLOT "Enable/Disable gnuplot" 0)
113 find_package(Gnuplot)
116 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
117 function(unitplot target script output)
118 set(TARGET "${TARGET_PREFIX}${target}")
119 set(SOURCE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
122 set(BINARY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
124 set(BINARY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
127 if((BUILD_SHARED_LIBS OR LIBA_SANITIZE) AND IS_MULTI_CONFIG)
128 set(WORKING_DIRECTORY $<TARGET_FILE_DIR:alib>)
130 set(WORKING_DIRECTORY ${BINARY_DIRECTORY})
133 if(NOT IS_ABSOLUTE ${script})
134 file(TO_CMAKE_PATH ${SOURCE_DIRECTORY}/${script} script)
137 if(NOT IS_ABSOLUTE ${output})
138 file(TO_CMAKE_PATH ${BINARY_DIRECTORY}/${output} output)
141 if(NOT TARGET_SUPPORTS_EXECUTABLES AND NOT CMAKE_CROSSCOMPILING_EMULATOR)
145 add_custom_command(TARGET ${TARGET} POST_BUILD WORKING_DIRECTORY ${WORKING_DIRECTORY}
146 COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:${TARGET}> ${output} ${ARGN}
147 COMMAND ${GNUPLOT_EXECUTABLE} -c ${script} ${output}
153 unittest(a NAME a_for ARGS for 10)
154 unittest(a NAME a_hash_bkdr ARGS hash_bkdr hash_bkdr)
155 unittest(a NAME a_hash_sdbm ARGS hash_sdbm hash_sdbm)
158 building(avl avl.c avl.cc)
161 building(buf buf.c buf.cc)
164 building(complex complex.c complex.cc)
165 unittest(complex ARGS -4,3 -2,1)
167 building(crc crc.c crc.cc)
168 unittest(crc ARGS crc.c)
170 building(hpf hpf.c hpf.cc)
173 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
174 unitplot(hpf 2.gp hpf.csv)
177 building(list list.c list.cc)
180 building(lpf lpf.c lpf.cc)
183 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
184 unitplot(lpf 3.gp lpf.csv)
187 building(math math.c math.cc)
190 building(mf mf.c mf.cc)
193 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
194 unitplot(mf mf.gp mf_gauss.csv -4 4 1 0)
195 unitplot(mf mf.gp mf_gauss2.csv -4 4 1 -1 1 1)
196 unitplot(mf mf.gp mf_gbell.csv -4 4 2 4 0)
197 unitplot(mf mf.gp mf_sig.csv -4 4 2 0)
198 unitplot(mf mf.gp mf_dsig.csv -4 4 5 -2 5 2)
199 unitplot(mf mf.gp mf_psig.csv -4 4 5 -2 -5 2)
200 unitplot(mf mf.gp mf_trap.csv -3 3 -2 -1 1 2)
201 unitplot(mf mf.gp mf_tri.csv -2 2 -1 0 1)
202 unitplot(mf mf.gp mf_lins.csv -2 2 -1 1)
203 unitplot(mf mf.gp mf_linz.csv -2 2 -1 1)
204 unitplot(mf mf.gp mf_s.csv -2 2 -1 1)
205 unitplot(mf mf.gp mf_z.csv -2 2 -1 1)
206 unitplot(mf mf.gp mf_pi.csv -3 3 -2 -1 1 2)
209 building(notefreqs notefreqs.c notefreqs.cc)
212 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
213 unitplot(notefreqs notefreqs.gp notefreqs.csv)
216 building(operator operator.c operator.cc)
219 building(pid pid.c pid.cc)
222 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
223 unitplot(pid 3.gp pid.csv)
226 building(pid_expert pid_expert.c pid_expert.cc)
229 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
230 unitplot(pid_expert 3.gp pid_expert.csv)
233 building(pid_fuzzy pid_fuzzy.c pid_fuzzy.cc)
236 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
237 unitplot(pid_fuzzy 3.gp pid_fuzzy.csv)
240 building(pid_neuro pid_neuro.c pid_neuro.cc)
243 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
244 unitplot(pid_neuro 3.gp pid_neuro.csv)
247 building(poly poly.c poly.cc)
250 building(que que.c que.cc)
253 building(rbt rbt.c rbt.cc)
256 building(slist slist.c slist.cc)
259 building(str str.c str.cc)
262 building(test test.c test.cc)
265 building(tf tf.c tf.cc)
268 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
269 unitplot(tf 2.gp tf.csv)
272 building(trajbell trajbell.c trajbell.cc)
273 unittest(trajbell ARGS trajbell.csv 3 2 3 0 10)
275 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
276 unitplot(trajbell traj4.gp trajbell.csv 3 2 3 0 10)
279 building(trajpoly3 trajpoly3.c trajpoly3.cc)
280 unittest(trajpoly3 ARGS trajpoly3.csv 0 10 0 10)
282 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
283 unitplot(trajpoly3 traj3.gp trajpoly3.csv 0 10 0 10)
286 building(trajpoly5 trajpoly5.c trajpoly5.cc)
287 unittest(trajpoly5 ARGS trajpoly5.csv 0 10 0 10)
289 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
290 unitplot(trajpoly5 traj3.gp trajpoly5.csv 0 10 0 10)
293 building(trajpoly7 trajpoly7.c trajpoly7.cc)
294 unittest(trajpoly7 ARGS trajpoly7.csv 0 10 0 10)
296 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
297 unitplot(trajpoly7 traj4.gp trajpoly7.csv 0 10 0 10)
300 building(trajtrap trajtrap.c trajtrap.cc)
301 unittest(trajtrap ARGS trajtrap.csv 2 2 -2 0 4)
303 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
304 unitplot(trajtrap traj3.gp trajtrap.csv 2 2 -2 0 4)
307 building(utf utf.c utf.cc)
310 building(vec vec.c vec.cc)
313 building(version version.c version.cc)