diff options
author | Brad King <brad.king@kitware.com> | 2018-11-06 16:40:09 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-11-06 16:40:16 (GMT) |
commit | bfdd1ba604a31b3bb9f0baa29ce6fce467ee2e47 (patch) | |
tree | 29e9cc9cb5b01c10b0962bf0eb210249fd36bddb /Tests | |
parent | 7bed0507554bed0208d66610417b690645768503 (diff) | |
parent | 575e2cc35da7cef40c521bccf0512483012bc136 (diff) | |
download | CMake-bfdd1ba604a31b3bb9f0baa29ce6fce467ee2e47.zip CMake-bfdd1ba604a31b3bb9f0baa29ce6fce467ee2e47.tar.gz CMake-bfdd1ba604a31b3bb9f0baa29ce6fce467ee2e47.tar.bz2 |
Merge topic 'FindPostgreSQL-target'
575e2cc35d FindPostgreSQL: extract the actual version number
7413f29fe6 Tests/FindPostgreSQL: add a test for FindPostgreSQL
d2235fd253 FindPostgreSQL: add an imported target
7a801b7dfb FindPostgreSQL: Modernize documentation layout
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2555
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | Tests/FindPostgreSQL/CMakeLists.txt | 10 | ||||
-rw-r--r-- | Tests/FindPostgreSQL/Test/CMakeLists.txt | 16 | ||||
-rw-r--r-- | Tests/FindPostgreSQL/Test/main.c | 15 |
4 files changed, 45 insertions, 0 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 1c49fea..fe27796 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1465,6 +1465,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() diff --git a/Tests/FindPostgreSQL/CMakeLists.txt b/Tests/FindPostgreSQL/CMakeLists.txt new file mode 100644 index 0000000..50151ee --- /dev/null +++ b/Tests/FindPostgreSQL/CMakeLists.txt @@ -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> + ) diff --git a/Tests/FindPostgreSQL/Test/CMakeLists.txt b/Tests/FindPostgreSQL/Test/CMakeLists.txt new file mode 100644 index 0000000..374e147 --- /dev/null +++ b/Tests/FindPostgreSQL/Test/CMakeLists.txt @@ -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) diff --git a/Tests/FindPostgreSQL/Test/main.c b/Tests/FindPostgreSQL/Test/main.c new file mode 100644 index 0000000..2cfeed0 --- /dev/null +++ b/Tests/FindPostgreSQL/Test/main.c @@ -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); +} |