1 include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
3 set(TCC_CFLAGS -I${CMAKE_SOURCE_DIR} -I${CMAKE_SOURCE_DIR}/include -B${CMAKE_BINARY_DIR})
5 set(TCC_CFLAGS ${TCC_CFLAGS} -I${CMAKE_SOURCE_DIR}/win32/include)
7 set(TCC_MATH_LDFLAGS -lm)
8 set(LIBTCC_EXTRA_LIBS dl)
9 set(LIBTCC_LDFLAGS -ldl -lm -Wl,-rpath=${CMAKE_BINARY_DIR})
12 add_executable(abitest-cc abitest.c)
13 target_link_libraries(abitest-cc libtcc ${LIBTCC_EXTRA_LIBS})
14 add_test(NAME abitest-cc WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND abitest-cc lib_path=${CMAKE_BINARY_DIR} include=${CMAKE_SOURCE_DIR}/include)
16 set(ABITEST_TCC abitest-tcc${CMAKE_EXECUTABLE_SUFFIX})
17 get_property(LIBTCC_LIB TARGET libtcc PROPERTY LOCATION)
18 add_custom_command(OUTPUT ${ABITEST_TCC} COMMAND tcc ${TCC_CFLAGS} -g ${CMAKE_CURRENT_SOURCE_DIR}/abitest.c ${LIBTCC_LDFLAGS} ${LIBTCC_LIB} -o ${ABITEST_TCC} DEPENDS tcc ${CMAKE_CURRENT_SOURCE_DIR}/abitest.c)
19 add_custom_target(abitest-tcc-exe ALL DEPENDS ${ABITEST_TCC})
21 add_test(NAME abitest-tcc WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${ABITEST_TCC} lib_path=${CMAKE_BINARY_DIR} include=${CMAKE_SOURCE_DIR}/include)
23 set(VLA_TEST vla_test${CMAKE_EXECUTABLE_SUFFIX})
24 add_custom_command(OUTPUT ${VLA_TEST} COMMAND tcc ${TCC_CFLAGS} -g ${CMAKE_CURRENT_SOURCE_DIR}/vla_test.c -o ${VLA_TEST} DEPENDS tcc ${CMAKE_CURRENT_SOURCE_DIR}/vla_test.c)
25 add_custom_target(vla_test-exe ALL DEPENDS ${VLA_TEST})
26 add_test(vla_test vla_test)
28 add_executable(tcctest-cc tcctest.c)
29 target_link_libraries(tcctest-cc libtcc)
30 set_target_properties(tcctest-cc PROPERTIES COMPILE_FLAGS -std=gnu99)
32 find_package(PythonInterp)
33 if(PYTHONINTERP_FOUND)
34 set(TCC_TEST_CFLAGS ${TCC_CFLAGS} -B${CMAKE_BINARY_DIR} -I${CMAKE_BINARY_DIR})
36 set(TCC_TEST_CFLAGS ${TCC_TEST_CFLAGS} -I${CMAKE_SOURCE_DIR}/win32/include/winapi)
38 set(TCC_TEST_SOURCE ${TCC_TEST_CFLAGS} ${TCC_MATH_LDFLAGS} -run ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c)
39 set(TCC_TEST_RUN ${TCC_TEST_CFLAGS} ${TCC_NATIVE_FLAGS} -DONE_SOURCE -run ${CMAKE_SOURCE_DIR}/tcc.c)
40 get_property(TCC TARGET tcc PROPERTY LOCATION)
41 get_property(TCCTESTCC TARGET tcctest-cc PROPERTY LOCATION)
42 set(TCCTEST_PY ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.py ${TCCTESTCC})
43 add_test(test1 ${TCCTEST_PY} ${TCC} ${TCC_TEST_SOURCE})
44 add_test(test2 ${TCCTEST_PY} ${TCC} ${TCC_TEST_RUN} ${TCC_TEST_SOURCE})
45 add_test(test3 ${TCCTEST_PY} ${TCC} ${TCC_TEST_RUN} ${TCC_TEST_RUN} ${TCC_TEST_SOURCE})
47 # Object + link output
48 set(TEST4 test4${CMAKE_EXECUTABLE_SUFFIX})
49 add_custom_command(OUTPUT test4.o COMMAND tcc ${TCC_TEST_CFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c -c -o test4.o DEPENDS tcc ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c)
50 add_custom_command(OUTPUT ${TEST4} COMMAND tcc ${TCC_TEST_CFLAGS} test4.o -o ${TEST4} DEPENDS tcc test4.o)
51 add_custom_target(test4-exe ALL DEPENDS ${TEST4})
52 add_test(test4 ${TCCTEST_PY} ${CMAKE_CURRENT_BINARY_DIR}/${TEST4})
55 set(TEST5 test5${CMAKE_EXECUTABLE_SUFFIX})
56 add_custom_command(OUTPUT ${TEST5} COMMAND tcc ${TCC_TEST_CFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c -o ${TEST5} DEPENDS tcc ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c)
57 add_custom_target(test5-exe ALL DEPENDS ${TEST5})
58 add_test(test5 ${TCCTEST_PY} ${CMAKE_CURRENT_BINARY_DIR}/${TEST5})
61 # Dynamic output + bound check
62 set(TEST6 test6${CMAKE_EXECUTABLE_SUFFIX})
63 add_custom_command(OUTPUT ${TEST6} COMMAND tcc ${TCC_TEST_CFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c -b -o ${TEST6} DEPENDS tcc ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c)
64 add_custom_target(test6-exe ALL DEPENDS ${TEST6})
65 add_test(test6 ${TCCTEST_PY} ${CMAKE_CURRENT_BINARY_DIR}/${TEST6})
70 set(TEST7 test7${CMAKE_EXECUTABLE_SUFFIX})
71 add_custom_command(OUTPUT ${TEST7} COMMAND tcc ${TCC_TEST_CFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c -static -o ${TEST7} DEPENDS tcc ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c)
72 add_custom_target(test7-exe ALL DEPENDS ${TEST7})
73 add_test(test7 ${TCCTEST_PY} ${CMAKE_CURRENT_BINARY_DIR}/${TEST7})
104 26_character_constants
112 36_array_initialisers
114 38_multiple_array_index
120 44_scoped_declarations
124 49_bracket_evaluation
125 50_logical_second_arg
132 list(REMOVE_ITEM MORETESTS 24_math_library)
133 list(REMOVE_ITEM MORETESTS 28_strings)
135 foreach(testfile ${MORETESTS})
136 add_test(NAME ${testfile} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests2
137 COMMAND tcc ${TCC_CFLAGS} ${TCC_MATH_LDFLAGS} -run ${testfile}.c - arg1 arg2 arg3 arg4 | ${DIFF} - ${testfile}.expect)