73 lines
2.1 KiB
CMake
73 lines
2.1 KiB
CMake
# NOTE: VARIABLES
|
|
|
|
# Define the path to the directory with SQL scripts
|
|
set(SQL_SCRIPTS_DIR "${CMAKE_SOURCE_DIR}/core/sql")
|
|
set(SQL_DEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/core/sql")
|
|
|
|
# Define directories for tests
|
|
set(TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests")
|
|
set(TESTS_SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests_sources")
|
|
|
|
# Specify paths to test files
|
|
set(TEST_FILES
|
|
${TESTS_DIR}/main_test.cpp
|
|
${TESTS_DIR}/sqlite_database_crud_test.cpp
|
|
${TESTS_DIR}/sqlite_database_foreign_key_test.cpp
|
|
${TESTS_DIR}/sqlite_database_trigger_test.cpp
|
|
)
|
|
|
|
# Specify paths to test sources
|
|
set(TEST_SOURCES
|
|
${TESTS_SOURCES_DIR}/sqlite_database.cpp
|
|
${TESTS_SOURCES_DIR}/sqlite_file_executor.cpp
|
|
${TESTS_SOURCES_DIR}/sqlite_statement.cpp
|
|
${TESTS_SOURCES_DIR}/file_reader.cpp
|
|
)
|
|
|
|
# NOTE: OUTPUT
|
|
|
|
# Output test file paths to console
|
|
message(STATUS "Test files: ${TEST_FILES}")
|
|
message(STATUS "Test sources: ${TEST_SOURCES}")
|
|
|
|
# Output variable values to console
|
|
message(STATUS "Tests directory: ${TESTS_DIR}")
|
|
message(STATUS "Test sources directory: ${TESTS_SOURCES_DIR}")
|
|
message(STATUS "SQL scripts source directory: ${SQL_SCRIPTS_DIR}")
|
|
message(STATUS "SQL scripts destination directory: ${SQL_DEST_DIR}")
|
|
|
|
# NOTE: BUILD
|
|
|
|
# Create the test executable
|
|
add_executable(tests_schema ${TEST_FILES} ${TEST_SOURCES})
|
|
|
|
# Include directories for headers
|
|
include_directories(${TESTS_SOURCES_DIR})
|
|
|
|
# Link the test executable with required libraries
|
|
target_link_libraries(tests_schema PRIVATE
|
|
GTest::GTest
|
|
GTest::Main
|
|
SQLite::SQLite3
|
|
)
|
|
|
|
# NOTE: BUILD END
|
|
|
|
# Copy SQL scripts to the build directory
|
|
add_custom_target(copy_sql_files ALL
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${SQL_DEST_DIR}
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SQL_SCRIPTS_DIR}/*.sql ${SQL_DEST_DIR}
|
|
COMMENT "Copying SQL scripts to ${SQL_DEST_DIR}"
|
|
)
|
|
|
|
# Ensure SQL scripts are copied before running tests
|
|
add_dependencies(tests_schema copy_sql_files)
|
|
|
|
# Pass the SQL scripts path to the tests via a macro
|
|
target_compile_definitions(tests_schema PRIVATE SQL_SCRIPTS_PATH="${SQL_DEST_DIR}")
|
|
|
|
# Register the tests
|
|
include(GoogleTest)
|
|
gtest_discover_tests(tests_schema)
|
|
|