geopro/tests/CMakeLists.txt

50 lines
2.2 KiB
CMake
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 单元测试(设计 §12。M1 spike 阶段先放一个 gtest 冒烟用例,
# 验证 gtest 经 vcpkg 接入、ctest 可跑;随 core/data/algo 实现补充真实用例。
find_package(GTest CONFIG REQUIRED)
add_executable(geopro_tests smoke_test.cpp)
target_link_libraries(geopro_tests PRIVATE GTest::gtest GTest::gtest_main)
include(GoogleTest)
# PROJ 运行时需要数据目录proj.db 等。vcpkg 把数据装在 share/proj 下。
# 通过测试环境变量 PROJ_DATA 注入,使 `ctest -R CrsTransform` 无需调用方手动 set。
file(GLOB _proj_data_dirs
"${CMAKE_BINARY_DIR}/vcpkg_installed/*/share/proj"
)
# DISCOVERY_MODE PRE_TEST把用例枚举推迟到 ctest 运行时执行,而非构建后立即跑
# exe。因 geopro_data 链 Qt6::Core构建期发现会因 Qt6Core.dll 尚未拷贝到 exe 旁而
# 失败0xc0000135推迟到运行期时 POST_BUILD 已把运行时 DLL 拷到位。
if(_proj_data_dirs)
list(GET _proj_data_dirs 0 GEOPRO_PROJ_DATA)
gtest_discover_tests(geopro_tests
DISCOVERY_MODE PRE_TEST
PROPERTIES ENVIRONMENT "PROJ_DATA=${GEOPRO_PROJ_DATA}")
else()
gtest_discover_tests(geopro_tests DISCOVERY_MODE PRE_TEST)
endif()
target_sources(geopro_tests PRIVATE core/test_local_frame.cpp)
target_sources(geopro_tests PRIVATE core/test_model.cpp)
target_sources(geopro_tests PRIVATE core/test_color_scale.cpp)
target_sources(geopro_tests PRIVATE core/test_idw.cpp)
target_sources(geopro_tests PRIVATE core/test_crs_transform.cpp)
target_sources(geopro_tests PRIVATE core/test_model_data.cpp)
target_link_libraries(geopro_tests PRIVATE geopro_core)
target_sources(geopro_tests PRIVATE data/test_parsers.cpp)
target_sources(geopro_tests PRIVATE data/test_local_repo.cpp)
target_link_libraries(geopro_tests PRIVATE geopro_data)
# geopro_data 链 Qt6::Core测试 exe 运行(含 gtest 发现)需要 Qt6Core.dll 等运行时
# DLL 在旁。复用 app 同样的 TARGET_RUNTIME_DLLS POST_BUILD 拷贝。
if(WIN32)
add_custom_command(TARGET geopro_tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_RUNTIME_DLLS:geopro_tests> $<TARGET_FILE_DIR:geopro_tests>
COMMAND_EXPAND_LISTS)
endif()
add_subdirectory(spike) # spike S3: banded contour 渲染验证