浏览代码

FindPostgreSQL: add an imported target

Ben Boeckel 7 年之前
父节点
当前提交
d2235fd253
共有 2 个文件被更改,包括 18 次插入0 次删除
  1. 4 0
      Help/release/dev/FindPostgreSQL-target.rst
  2. 14 0
      Modules/FindPostgreSQL.cmake

+ 4 - 0
Help/release/dev/FindPostgreSQL-target.rst

@@ -0,0 +1,4 @@
+FindPostgreSQL-target
+---------------------
+
+* The :module:`FindPostgreSQL` module now provides an imported target.

+ 14 - 0
Modules/FindPostgreSQL.cmake

@@ -7,6 +7,12 @@ FindPostgreSQL
 
 
 Find the PostgreSQL installation.
 Find the PostgreSQL installation.
 
 
+IMPORTED Targets
+^^^^^^^^^^^^^^^^
+
+This module defines :prop_tgt:`IMPORTED` target ``PostgreSQL::PostgreSQL``
+if PostgreSQL has been found.
+
 Result Variables
 Result Variables
 ^^^^^^^^^^^^^^^^
 ^^^^^^^^^^^^^^^^
 
 
@@ -56,6 +62,8 @@ This module will set the following variables in your project:
 #  PostgreSQL_LIBRARY_DIRS  - Link directories for PostgreSQL libraries
 #  PostgreSQL_LIBRARY_DIRS  - Link directories for PostgreSQL libraries
 #  PostgreSQL_LIBRARIES     - The PostgreSQL libraries.
 #  PostgreSQL_LIBRARIES     - The PostgreSQL libraries.
 #
 #
+# The ``PostgreSQL::PostgreSQL`` imported target is also created.
+#
 # ----------------------------------------------------------------------------
 # ----------------------------------------------------------------------------
 # If you have installed PostgreSQL in a non-standard location.
 # If you have installed PostgreSQL in a non-standard location.
 # (Please note that in the following comments, it is assumed that <Your Path>
 # (Please note that in the following comments, it is assumed that <Your Path>
@@ -187,6 +195,12 @@ set(PostgreSQL_FOUND  ${POSTGRESQL_FOUND})
 
 
 # Now try to get the include and library path.
 # Now try to get the include and library path.
 if(PostgreSQL_FOUND)
 if(PostgreSQL_FOUND)
+  if (NOT TARGET PostgreSQL::PostgreSQL)
+    add_library(PostgreSQL::PostgreSQL UNKNOWN IMPORTED)
+    set_target_properties(PostgreSQL::PostgreSQL PROPERTIES
+      IMPORTED_LOCATION "${PostgreSQL_LIBRARY}"
+      INTERFACE_INCLUDE_DIRECTORIES "${PostgreSQL_INCLUDE_DIR};${PostgreSQL_TYPE_INCLUDE_DIR}")
+  endif ()
   set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR} ${PostgreSQL_TYPE_INCLUDE_DIR} )
   set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR} ${PostgreSQL_TYPE_INCLUDE_DIR} )
   set(PostgreSQL_LIBRARY_DIRS ${PostgreSQL_LIBRARY_DIR} )
   set(PostgreSQL_LIBRARY_DIRS ${PostgreSQL_LIBRARY_DIR} )
   set(PostgreSQL_LIBRARIES ${PostgreSQL_LIBRARY})
   set(PostgreSQL_LIBRARIES ${PostgreSQL_LIBRARY})