mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-21 14:40:26 -06:00
Tests/FindPostgreSQL: add a test for FindPostgreSQL
This commit is contained in:
@@ -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()
|
||||
|
||||
10
Tests/FindPostgreSQL/CMakeLists.txt
Normal file
10
Tests/FindPostgreSQL/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
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>
|
||||
)
|
||||
16
Tests/FindPostgreSQL/Test/CMakeLists.txt
Normal file
16
Tests/FindPostgreSQL/Test/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
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)
|
||||
15
Tests/FindPostgreSQL/Test/main.c
Normal file
15
Tests/FindPostgreSQL/Test/main.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user