'PostgreSQL libpq windows 10 CMake missing PostgreSQL_LIBRARY

I'm rying to setup a CMake project under windows 10 using PostgreSQL.

When I try to find_package

find_package(PostgreSQL REQUIRED)

I get the following error

  Could NOT find PostgreSQL (missing: PostgreSQL_LIBRARY) (found version
  "10.4")
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.8/Modules/FindPackageHandleStandardArgs.cmake:377 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files/CMake/share/cmake-3.8/Modules/FindPostgreSQL.cmake:175 (find_package_handle_standard_args)
  server/CMakeLists.txt:13 (find_package)

It seems like it has found "10.4" version but it's missing the PostgreSQL_LIBRARY.

How can I fix that?



Solution 1:[1]

My FindPostgreSQL.cmake has this note:

# Note:
# PostgreSQL_ADDITIONAL_VERSIONS is a variable that can be used to set the
# version number of the implementation of PostgreSQL.
# In Windows the default installation of PostgreSQL uses that as part of the path.
# E.g C:\Program Files\PostgreSQL\8.4.
# Currently, the following version numbers are known to this module:
# "10" "9.6" "9.5" "9.4" "9.3" "9.2" "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0"
#
# To use this variable just do something like this:
# set(PostgreSQL_ADDITIONAL_VERSIONS "9.2" "8.4.4")
# before calling find_package(PostgreSQL) in your CMakeLists.txt file.
# This will mean that the versions you set here will be found first in the order
# specified before the default ones are searched.
#
# ----------------------------------------------------------------------------
# You may need to manually set:
#  PostgreSQL_INCLUDE_DIR  - the path to where the PostgreSQL include files are.
#  PostgreSQL_LIBRARY_DIR  - The path to where the PostgreSQL library files are.
# If FindPostgreSQL.cmake cannot find the include files or the library files.

HTH

Mike

Solution 2:[2]

Add postgreSQL lib, bin, include directories to the environment variables

Solution 3:[3]

I had the same goal - trying to use PostgreSQL libpq on Windows 10 in a CMake project, and I had the same error. Following on from Mike's reply I added set(PostgreSQL_ADDITIONAL_VERSIONS "14") before the call to find_package(PostgreSQL REQUIRED) and can confirm this fixed the problem. Just confirming that Mike's solution worked for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Michael Surette
Solution 2 basjak
Solution 3 davidxmiller