Пишу поисковик на Qt. Добрался до тестов и даже подключил библиотеку Qt Test.
Проект собирается, но ровно до тех пор, пока в cpp файле тестового модуля я не пытаюсь прописать
#include "serchserver.h"
- того заголовочного файла, который собираюсь тестировать.
Перебрал уже множество вариантов обоих файлов CMAKE, но результата пока нет.
Тестовый проект - это подпроект основного.
код основного CMAKEcmake_minimum_required(VERSION 3.5)
project("search_engine" VERSION 0.1 LANGUAGES CXX)
enable_testing()
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_subdirectory(nlohmann_json)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
set(PROJECT_SOURCES
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
invertedindex.cpp
invertedindex.h
searchserver.h
searchserver.cpp
converterjson.h
converterjson.cpp
project_threads.h
project_threads.cpp
caller.ui
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(search_engine
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET search_engine APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(search_engine SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(search_engine
${PROJECT_SOURCES}
)
endif()
endif()
add_subdirectory(test)
set(MY_INCLUDE_DIR &{CMAKE_SOURCE_DIR})
target_link_libraries(search_engine PRIVATE Qt${QT_VERSION_MAJOR}::Widgets nlohmann_json::nlohmann_json)
set_target_properties(search_engine PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
)
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(search_engine)
endif()
код тестового CMAKEcmake_minimum_required(VERSION 3.5)
project(searchenginetest LANGUAGES CXX)
enable_testing()
find_package(QT NAMES Qt6 Qt5 COMPONENTS Gui Test REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Gui Test REQUIRED)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#include_directories(search_engine)
add_executable(searchenginetest tst_searchenginetest.cpp)
add_test(NAME searchenginetest COMMAND searchenginetest)
target_include_directories(searchenginetest PUBLIC ${MY_INCLUDE_DIR})
target_link_libraries(searchenginetest PRIVATE Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Test)