Commit 7413f29f authored by Ben Boeckel's avatar Ben Boeckel Committed by Brad King

Tests/FindPostgreSQL: add a test for FindPostgreSQL

parent d2235fd2
......@@ -1461,6 +1461,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
add_subdirectory(FindPatch)
endif()
if(CMake_TEST_FindPostgreSQL)
add_subdirectory(FindPostgreSQL)
endif()
if(CMake_TEST_FindProtobuf)
add_subdirectory(FindProtobuf)
endif()
......
add_test(NAME FindPostgreSQL.Test COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/FindPostgreSQL/Test"
"${CMake_BINARY_DIR}/Tests/FindPostgreSQL/Test"
${build_generator_args}
--build-project TestFindPostgreSQL
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
cmake_minimum_required(VERSION 3.10)
project(TestFindPostgreSQL C)
include(CTest)
find_package(PostgreSQL REQUIRED)
add_definitions(-DCMAKE_EXPECTED_POSTGRESQL_VERSION="${PostgreSQL_VERSION_STRING}")
add_executable(test_tgt main.c)
target_link_libraries(test_tgt PostgreSQL::PostgreSQL)
add_test(NAME test_tgt COMMAND test_tgt)
add_executable(test_var main.c)
target_include_directories(test_var PRIVATE ${PostgreSQL_INCLUDE_DIRS})
target_link_libraries(test_var PRIVATE ${PostgreSQL_LIBRARIES})
add_test(NAME test_var COMMAND test_var)
#include <libpq-fe.h>
#include <stdio.h>
#include <string.h>
int main()
{
int version = PQlibVersion();
int major = version / 10000;
int minor = version % 10000;
char version_string[100];
snprintf(version_string, sizeof(version_string), "%d.%d", major, minor);
printf("Found PostgreSQL version %s, expected version %s\n", version_string,
CMAKE_EXPECTED_POSTGRESQL_VERSION);
return strcmp(version_string, CMAKE_EXPECTED_POSTGRESQL_VERSION);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment