Warning, /libraries/perceptualcolor/autotests/CMakeLists.txt is written in an unsupported language. File is not indexed.

0001 # SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
0002 # SPDX-License-Identifier: BSD-2-Clause OR MIT
0003 
0004 
0005 
0006 
0007 
0008 ################# General setup #################
0009 include(CTest)
0010 
0011 
0012 
0013 
0014 
0015 ################# Test bed #################
0016 
0017 if(BUILD_TESTING)
0018 
0019     message(
0020         STATUS
0021         "Unit testing is enabled because BUILD_TESTING was set. \n"
0022         "   CMake’s own “test” target unfortunately runs the unit tests \n"
0023         "   without building them if the source files have changed. \n"
0024         "   Therefore, to run unit tests, you should always execute \n"
0025         "   the target “buildandruntests” instead, which builds and updates \n"
0026         "   the unit tests if necessary.")
0027 
0028     add_custom_target(buildtests)
0029 
0030     add_custom_target(
0031         buildandruntests
0032         COMMAND "${CMAKE_CTEST_COMMAND}")
0033     add_dependencies(
0034         buildandruntests
0035         buildtests)
0036 
0037     enable_testing() # Also defines the target “test”
0038 
0039     # Define add_unit_tests(). For adding the unit tests “testfoo.cpp” and
0040     # “testbar.cpp”, call “add_unit_tests(testfoo testbar)”. If a file
0041     # “foo.qrc” or “bar.qrc” exists, the corresponding resources are compiled
0042     # into the respective unit test using the Qt resource system. Every
0043     # unit test links against the “perceptualcolorinternal” library, which
0044     # exports all symbols as public symbols, which makes white box tests
0045     # possible. Furthermore, every unit test links against Qt::Test to
0046     # provide a test framework, and against LCMS2 to simplify white box tests.
0047     # For the sake of simplicity, all these libraries are always linked to
0048     # regardless of the actual needs of the individual unit test.
0049     function(add_unit_tests)
0050         foreach(test_name IN LISTS ARGV)
0051             set(test_target_name "${test_name}")
0052             add_executable("${test_target_name}")
0053             set(test_sources "${test_name}.cpp")
0054             if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${test_name}.qrc")
0055                 # Add all resources from the .qrt file to our sources
0056                 # so they will get compiled in.
0057                 qt_add_resources(
0058                     test_sources # existing source list
0059                     "${test_name}.qrc" # List of Qt resource to be added
0060                 )
0061             endif()
0062             # target_sources should normally always use PRIVATE. Details:
0063             # crascit.com/enhanced-source-file-handling-with-target_sources
0064             target_sources(
0065                 ${test_target_name}
0066                 PRIVATE ${test_sources})
0067             if(MSVC_DLL)
0068                 target_compile_definitions(
0069                     ${test_target_name}
0070                     PRIVATE MSVC_DLL)
0071             endif()
0072             target_link_libraries(
0073                 ${test_target_name}
0074                 # Transitive dependencies (PUBLIC, INTERFACE) don’t make sense
0075                 # for executables, since you can’t link against an executable.
0076                 # Therefore using PRIVAT:
0077                 PRIVATE
0078                     "perceptualcolorinternal-${MAJOR_VERSION}"
0079                     Qt::Test
0080                     ${LCMS2_LIBRARIES})
0081 
0082             # The CMakeLists.txt in the main directory might add
0083             # -Weverything as compile option when the user requests
0084             # additional warnings. On Clang, this also pulls in
0085             # -Wreserved-identifier, which in turn prints warnings
0086             # when using Qt’s QBENCHMARK macro:
0087             # https://bugreports.qt.io/browse/QTBUG-102431
0088             # As we need this macro, we have to disable
0089             # -Wreserved-identifier. Unfortunately the corresponding
0090             # -Wno-reserved-identifier does not work when using clazy
0091             # instead of clang. Therefore, we cannot disable it. To
0092             # work around this problem, we remove -Weverything from
0093             # the compile options for unit tests:
0094             get_target_property(
0095                 target_options
0096                 ${test_target_name}
0097                 COMPILE_OPTIONS)
0098             if(NOT ("${target_options}" STREQUAL "target_options-NOTFOUND"))
0099                 list(REMOVE_ITEM target_options "-Weverything")
0100                 set_property(
0101                     TARGET ${test_target_name}
0102                     PROPERTY COMPILE_OPTIONS
0103                     ${target_options})
0104             endif()
0105             add_test(
0106                 NAME "${test_target_name}"
0107                 COMMAND "${test_target_name}")
0108             if(MSVC_DLL)
0109                 # NOTE On MSVC, when using a shared/dynamic library,
0110                 # we need to explicitly provide the path to the
0111                 # perceptualcolorinteral DLL. More information can be found at:
0112                 # https://www.scivision.dev/cmake-ctest-set-environment-variable
0113                 # Alternatively, installing the library would make it
0114                 # discoverable, but since we are linking against the
0115                 # internal library instead of the public one, installation
0116                 # is not suitable.
0117                 set_tests_properties(
0118                     "${test_target_name}"
0119                     PROPERTIES
0120                         ENVIRONMENT_MODIFICATION
0121                             "PATH=path_list_append:${CMAKE_BINARY_DIR}/src")
0122             endif()
0123             add_dependencies(
0124                 buildtests
0125                 "${test_target_name}")
0126         endforeach()
0127     endfunction()
0128 
0129     add_unit_tests(
0130         testabsolutecolor
0131         testabstractdiagram
0132         testasyncimageprovider
0133         testasyncimageproviderbase
0134         testasyncimagerendercallback
0135         testasyncimagerenderthread
0136         testchromahuediagram
0137         testchromahueimageparameters
0138         testchromalightnessdiagram
0139         testchromalightnessimageparameters
0140         testcielchd50values
0141         testcolordialog
0142         testcolorpatch
0143         testcolorwheel
0144         testcolorwheelimage
0145         testconstpropagatingrawpointer
0146         testconstpropagatinguniquepointer
0147         testcsscolor
0148         testextendeddoublevalidator
0149         testgenericcolor
0150         testgradientimageparameters
0151         testgradientslider
0152         testhelper
0153         testhelperconstants
0154         testhelperconversion
0155         testhelpermath
0156         testhelperposixmath
0157         testhelperqttypes
0158         testimportexport
0159         testinitializetranslation
0160         testinterlacingpass
0161         testiohandlerfactory
0162         testlanguagechangeeventfilter
0163         testlchadouble
0164         testlchdouble
0165         testmultispinbox
0166         testmultispinboxsection
0167         testoklchvalues
0168         testperceptualsettings
0169         testpolarpointf
0170         testrgbcolor
0171         testrgbcolorspace
0172         testrgbcolorspacefactory
0173         testscreencolorpicker
0174         testsetting
0175         testsettingbase
0176         testsettings
0177         testsettranslation
0178         testswatchbook
0179         testversion
0180         testwheelcolorpicker)
0181 
0182 else()
0183 
0184     message(
0185         STATUS
0186         "Unit testing is disabled because BUILD_TESTING wasn’t set.")
0187 
0188 endif()