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}
109 option(LIBA_GNUPLOT "Enable/Disable gnuplot" 0)
112 find_package(Gnuplot)
115 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
116 function(unitplot target script output)
117 set(TARGET "${TARGET_PREFIX}${target}")
118 set(SOURCE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
121 set(BINARY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
123 set(BINARY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
126 if((BUILD_SHARED_LIBS OR LIBA_SANITIZE) AND IS_MULTI_CONFIG)
127 set(WORKING_DIRECTORY $<TARGET_FILE_DIR:alib>)
129 set(WORKING_DIRECTORY ${BINARY_DIRECTORY})
132 if(NOT IS_ABSOLUTE ${script})
133 file(TO_CMAKE_PATH ${SOURCE_DIRECTORY}/${script} script)
136 if(NOT IS_ABSOLUTE ${output})
137 file(TO_CMAKE_PATH ${BINARY_DIRECTORY}/${output} output)
140 if(NOT TARGET_SUPPORTS_EXECUTABLES AND NOT CMAKE_CROSSCOMPILING_EMULATOR)
144 add_custom_command(TARGET ${TARGET} POST_BUILD WORKING_DIRECTORY ${WORKING_DIRECTORY}
145 COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:${TARGET}> ${output} ${ARGN}
146 COMMAND ${GNUPLOT_EXECUTABLE} -c ${script} ${output}
152 unittest(a NAME a_for ARGS for 10)
153 unittest(a NAME a_hash_bkdr ARGS hash_bkdr hash_bkdr)
154 unittest(a NAME a_hash_sdbm ARGS hash_sdbm hash_sdbm)
157 building(avl avl.c avl.cc)
160 building(buf buf.c buf.cc)
163 building(complex complex.c complex.cc)
164 unittest(complex ARGS -4,3 -2,1)
166 building(crc crc.c crc.cc)
167 unittest(crc ARGS crc.c)
169 building(hpf hpf.c hpf.cc)
172 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
173 unitplot(hpf 2.gp hpf.csv)
176 building(list list.c list.cc)
179 building(lpf lpf.c lpf.cc)
182 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
183 unitplot(lpf 3.gp lpf.csv)
186 building(math math.c math.cc)
189 building(mf mf.c mf.cc)
192 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
193 unitplot(mf mf.gp mf_gauss.csv -4 4 1 0)
194 unitplot(mf mf.gp mf_gauss2.csv -4 4 1 -1 1 1)
195 unitplot(mf mf.gp mf_gbell.csv -4 4 2 4 0)
196 unitplot(mf mf.gp mf_sig.csv -4 4 2 0)
197 unitplot(mf mf.gp mf_dsig.csv -4 4 5 -2 5 2)
198 unitplot(mf mf.gp mf_psig.csv -4 4 5 -2 -5 2)
199 unitplot(mf mf.gp mf_trap.csv -3 3 -2 -1 1 2)
200 unitplot(mf mf.gp mf_tri.csv -2 2 -1 0 1)
201 unitplot(mf mf.gp mf_lins.csv -2 2 -1 1)
202 unitplot(mf mf.gp mf_linz.csv -2 2 -1 1)
203 unitplot(mf mf.gp mf_s.csv -2 2 -1 1)
204 unitplot(mf mf.gp mf_z.csv -2 2 -1 1)
205 unitplot(mf mf.gp mf_pi.csv -3 3 -2 -1 1 2)
208 building(notefreqs notefreqs.c notefreqs.cc)
211 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
212 unitplot(notefreqs notefreqs.gp notefreqs.csv)
215 building(operator operator.c operator.cc)
218 building(pid pid.c pid.cc)
221 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
222 unitplot(pid 3.gp pid.csv)
225 building(pid_expert pid_expert.c pid_expert.cc)
228 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
229 unitplot(pid_expert 3.gp pid_expert.csv)
232 building(pid_fuzzy pid_fuzzy.c pid_fuzzy.cc)
235 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
236 unitplot(pid_fuzzy 3.gp pid_fuzzy.csv)
239 building(pid_neuro pid_neuro.c pid_neuro.cc)
242 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
243 unitplot(pid_neuro 3.gp pid_neuro.csv)
246 building(poly poly.c poly.cc)
249 building(que que.c que.cc)
252 building(rbt rbt.c rbt.cc)
255 building(slist slist.c slist.cc)
258 building(str str.c str.cc)
261 building(test test.c test.cc)
264 building(tf tf.c tf.cc)
267 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
268 unitplot(tf 2.gp tf.csv)
271 building(trajbell trajbell.c trajbell.cc)
272 unittest(trajbell ARGS trajbell.csv 3 2 3 0 10)
274 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
275 unitplot(trajbell traj4.gp trajbell.csv 3 2 3 0 10)
278 building(trajpoly3 trajpoly3.c trajpoly3.cc)
279 unittest(trajpoly3 ARGS trajpoly3.csv 0 10 0 10)
281 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
282 unitplot(trajpoly3 traj3.gp trajpoly3.csv 0 10 0 10)
285 building(trajpoly5 trajpoly5.c trajpoly5.cc)
286 unittest(trajpoly5 ARGS trajpoly5.csv 0 10 0 10)
288 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
289 unitplot(trajpoly5 traj3.gp trajpoly5.csv 0 10 0 10)
292 building(trajpoly7 trajpoly7.c trajpoly7.cc)
293 unittest(trajpoly7 ARGS trajpoly7.csv 0 10 0 10)
295 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
296 unitplot(trajpoly7 traj4.gp trajpoly7.csv 0 10 0 10)
299 building(trajtrap trajtrap.c trajtrap.cc)
300 unittest(trajtrap ARGS trajtrap.csv 2 2 -2 0 4)
302 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
303 unitplot(trajtrap traj3.gp trajtrap.csv 2 2 -2 0 4)
306 building(utf utf.c utf.cc)
309 building(vec vec.c vec.cc)
312 building(version version.c version.cc)