if(BUILD_TESTS)
    # Install Test Configs
    # These are read-only test fixtures, not configuration an administrator is
    # expected to edit, so they belong under datadir rather than sysconfdir.
    file(GLOB testConfigs "${CMAKE_CURRENT_SOURCE_DIR}/Configs/*.yaml")
    install(
        FILES ${testConfigs}
        DESTINATION ${CMAKE_INSTALL_DATADIR}/urm/tests/configs/
        PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
    )

    # Install Custom Resource Nodes
    # These stand in for sysfs nodes and are written to while the tests run, so
    # they are variable state and belong under /var/lib.
    install(
        DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Configs/ResourceSysFsNodes/
        DESTINATION ${CMAKE_INSTALL_LOCALSTATEDIR}/lib/urm/tests/nodes
        FILES_MATCHING
        PATTERN "*.txt"
        PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
    )

    add_library(RestuneTestUtils
                ${CMAKE_CURRENT_SOURCE_DIR}/Utils/Baseline.cpp
                ${CMAKE_CURRENT_SOURCE_DIR}/Utils/URMTests.cpp)
    set_target_properties(RestuneTestUtils PROPERTIES VERSION 1.0.0 SOVERSION 1)
    target_link_libraries(RestuneTestUtils UrmAuxUtils)
    target_include_directories(RestuneTestUtils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Utils/Include)
    install(TARGETS RestuneTestUtils DESTINATION ${CMAKE_INSTALL_LIBDIR})

    add_library(UrmTestPlugin ${CMAKE_CURRENT_SOURCE_DIR}/Utils/Setup.cpp)
    set_target_properties(UrmTestPlugin PROPERTIES VERSION 1.0.0 SOVERSION 1)
    target_link_libraries(UrmTestPlugin UrmExtAPIs)
    install(TARGETS UrmTestPlugin DESTINATION ${CMAKE_INSTALL_LIBDIR}/urm)

    add_executable(
        UrmComponentTests
        ${CMAKE_CURRENT_SOURCE_DIR}/Component/MemoryPoolTests.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/Component/ClientDataManagerTests.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/Component/ParserTests.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/Component/ConfigSelectionTests.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/Component/ExtensionIntfTests.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/Component/MiscTests.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/Component/RequestQueueTests.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/Component/ThreadPoolTests.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/Component/SafeOpsTests.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/Component/RateLimiterTests.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/Component/TimerTests.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/Component/DeviceInfoTests.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/Component/CocoTableTests.cpp
        # ${CMAKE_CURRENT_SOURCE_DIR}/Component/RequestMapTests.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/Component/Trigger.cpp)

    target_link_libraries(UrmComponentTests PUBLIC UrmAuxUtils
                                                   UrmExtAPIs
                                                   RestuneCore
                                                   RestuneTestUtils
                                                   ${LIBYAML_LIBRARIES})
    target_include_directories(UrmComponentTests PRIVATE ${LIBYAML_INCLUDE_DIRS}
                                                         ${CMAKE_SOURCE_DIR}/resource-tuner/Include
                                                         ${CMAKE_SOURCE_DIR}/common/Include)

    if(BUILD_CLASSIFIER)
        set(FLORET_FOUND FALSE)
        set(FLORET_LIBRARIES "")
        set(FLORET_INCLUDE_DIRS "")

        if(ENABLE_FLORET)
            # Use pkg-config to find floret
            pkg_check_modules(PC_FLORET QUIET floret)
            if(PC_FLORET_FOUND)
                set(FLORET_FOUND TRUE)
                set(FLORET_LIBRARIES ${PC_FLORET_LIBRARIES})
                set(FLORET_INCLUDE_DIRS ${PC_FLORET_INCLUDE_DIRS})
            endif()
        endif()

        if(FLORET_FOUND)
            add_definitions(-DUSE_FLORET=1)

            target_sources(UrmComponentTests PRIVATE
                ${CMAKE_CURRENT_SOURCE_DIR}/Component/ContextClassificationTest.cpp
            )

            target_link_libraries(UrmComponentTests PUBLIC
                ContextualClassifier
                ml_inference_lib
            )

            target_include_directories(UrmComponentTests PRIVATE
                ${CMAKE_SOURCE_DIR}/contextual-classifier/Include
            )
        endif()
    endif()

    # Install
    install(TARGETS UrmComponentTests DESTINATION ${CMAKE_INSTALL_BINDIR})

    add_executable(UrmIntegrationTests Integration/IntegrationTests.cpp)
    target_link_libraries(UrmIntegrationTests PUBLIC UrmAuxUtils
                                                     UrmClient
                                                     RestuneTestUtils
                                                     ${LIBYAML_LIBRARIES})
    target_include_directories(UrmIntegrationTests PRIVATE ${LIBYAML_INCLUDE_DIRS})

    if(BUILD_CLASSIFIER)
        target_sources(
            UrmIntegrationTests PRIVATE
            ${CMAKE_CURRENT_SOURCE_DIR}/Integration/CCIntegrationTests.cpp
        )
    endif()

    # Install
    install(TARGETS UrmIntegrationTests RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

endif()
