1 # SPDX-License-Identifier: GPL-2.0-or-later
2 # -----------------------------------------------------------------------------
4 # custom "check" target with proper dependencies (builds inkscape and tests)
5 file(TO_NATIVE_PATH "/" _separator)
6 ADD_DEFINITIONS(-DINKSCAPE_TESTS_DIR="${CMAKE_SOURCE_DIR}/testfiles")
7 add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
8 DEPENDS tests unit_tests
9 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
10 add_dependencies(check inkscape)
12 # create symlink "inkscape_datadir" to use as INKSCAPE_DATADIR
13 # - ensures tests can be run without installing the project
14 # - also helpful for running Inkscape uninstalled: 'INKSVAPE_DATADIR=inkscape_datadir bin/inkscape'
15 set(INKSCAPE_DATADIR ${CMAKE_BINARY_DIR}/inkscape_datadir)
16 if(NOT EXISTS ${INKSCAPE_DATADIR}/inkscape)
17 set(link_source ${INKSCAPE_DATADIR}/inkscape)
18 set(link_target ${CMAKE_SOURCE_DIR}/share)
19 message(STATUS "Creating link '${link_source}' --> '${link_target}'")
20 execute_process(COMMAND mkdir inkscape_datadir)
21 execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${link_target} ${link_source}
22 RESULT_VARIABLE result)
24 message(WARNING "Creation of link failed: ${result}")
27 # check if creation succeeded
28 if(EXISTS ${INKSCAPE_DATADIR}/inkscape)
29 set(CMAKE_CTEST_ENV INKSCAPE_DATADIR=${INKSCAPE_DATADIR})
31 message(WARNING "Directory 'inkscape_datadir/inkscape' missing. Tests might not run properly.\n"
32 "Possible solutions:\n"
33 " - create a suitable symlink yourself, e.g.\n"
34 " ln -s ${CMAKE_SOURCE_DIR}/share ${INKSCAPE_DATADIR}/inkscape\n"
35 " - run '${CMAKE_MAKE_PROGRAM} install' before running tests (only for not relocatable packages.\n"
36 " - set the environment variable 'INKSCAPE_DATADIR' manually (every time you run tests)")
40 # Set custom profile directory for tests using environment variable.
41 # Copy CTestCustom.cmake into binary dir, where it will be picked up automatically by ctest for cleanup.
42 set(INKSCAPE_TEST_PROFILE_DIR ${CMAKE_CURRENT_BINARY_DIR}/test_profile_dir)
43 set(INKSCAPE_TEST_PROFILE_DIR_ENV INKSCAPE_PROFILE_DIR=${INKSCAPE_TEST_PROFILE_DIR})
44 configure_file(CTestCustom.cmake.in ${CMAKE_BINARY_DIR}/CTestCustom.cmake)
47 include_directories("${CMAKE_SOURCE_DIR}/src/3rdparty/adaptagrams") # TODO: remove this hack
49 if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
52 # (test not stable on 32bit Windows)
57 # Integration tests (linking all of Inkscape)
59 actions-svg-processing
66 colors/document-cms-test
72 colors/spaces-cms-test
73 colors/spaces-cmyk-test
74 colors/spaces-gray-test
75 colors/spaces-hsl-test
76 colors/spaces-hsluv-test
77 colors/spaces-hsv-test
78 colors/spaces-lab-test
79 colors/spaces-lch-test
80 colors/spaces-linear-rgb-test
81 colors/spaces-luv-test
82 colors/spaces-named-test
83 colors/spaces-okhsl-test
84 colors/spaces-oklab-test
85 colors/spaces-oklch-test
86 colors/spaces-rgb-test
87 colors/spaces-xyz-test
105 path-reverse-lpe-test
115 svg-stringstream-test
120 livarot-pathoutline-test
122 sp-glyph-kerning-test
126 2geom-characterization-test
135 add_library(cpp_test_static_library SHARED inkscape-test.cpp doc-per-case-test.cpp compare-paths-test.h lpespaths-test.h store-integrity-test.h test-with-svg-object-pairs.cpp)
136 target_link_libraries(cpp_test_static_library PUBLIC ${GTEST_LIBRARIES} inkscape_base)
138 add_custom_target(tests)
139 foreach(test_source ${TEST_SOURCES})
140 string(REPLACE "-test" "" testname "test_${test_source}")
141 string(REPLACE "/" "_" testname "${testname}")
142 add_executable(${testname} src/${test_source}.cpp)
143 target_include_directories(${testname} SYSTEM PRIVATE ${GTEST_INCLUDE_DIRS})
144 target_link_libraries(${testname} cpp_test_static_library 2Geom::2geom)
145 add_test(NAME ${testname} COMMAND ${testname})
146 set_tests_properties(${testname} PROPERTIES ENVIRONMENT "${INKSCAPE_TEST_PROFILE_DIR_ENV}/${testname};${CMAKE_CTEST_ENV}")
147 add_dependencies(tests ${testname})
149 include(${CMAKE_SOURCE_DIR}/CMakeScripts/UnitTest.cmake)
152 add_unit_test(version-test SOURCES version.cpp)
153 add_dependencies(tests version-test)
155 ### CLI rendering tests and LPE
156 add_subdirectory(cli_tests)
157 add_subdirectory(rendering_tests)
158 add_subdirectory(lpe_tests)
162 # to use the fuzzer, make sure you use the right compiler (clang)
163 # with the right flags -fsanitize=address -fsanitize-coverage=edge,trace-pc-guard,indirect-calls,trace-cmp,trace-div,trace-gep -fno-omit-frame-pointer
164 # (see libfuzzer doc for info in flags)
165 # first line is for integration into oss-fuzz https://github.com/google/oss-fuzz
166 add_executable(fuzz fuzzer.cpp)
167 if(LIB_FUZZING_ENGINE)
168 target_link_libraries(fuzz inkscape_base -lFuzzingEngine)
170 target_link_libraries(fuzz inkscape_base -lFuzzer)