FindPostgreSQL.cmake won't work on ubuntu - cmake

Ubuntu 12.04
CMake 2.8.9
Postgresql 9.2.2
I'm trying to get the FindPostgreSQL module to find /usr/include/postgresql/libpq-fe.h.
Here's what I have in my CMakeLists.txt:
find_package(PostgreSQL REQUIRED)
This is the error I get:
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (MESSAGE):
Could NOT find PostgreSQL (missing: PostgreSQL_TYPE_INCLUDE_DIR) (found
version "9.2.2")
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:288 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindPostgreSQL.cmake:155 (find_package_handle_standard_args)
CMakeLists.txt:7 (find_package)
I added the following lines before calling find_package but it didn't seem to have any effect.
set(PostgreSQL_ADDITIONAL_VERSIONS "9.2.2")
set(PostgreSQL_ADDITIONAL_SEARCH_PATHS ${PostgreSQL_ADDITIONAL_SEARCH_PATHS} "/usr/include/postgresql")
I also tried googling for PostgreSQL_TYPE_INCLUDE_DIR but didn't find anything. What else can I try?

Make sure you've installed both libpq-dev\ and postgresql-server-dev-all (or specific version e.g. postgresql-server-dev-9.4)
$ dpkg --get-selections | grep -e "libpq-dev\|postgresql-server-dev"
in case you're missing some package
apt-get install libpq-dev postgresql-server-dev-all
should fix it.

After a bit more debugging I figured out that it's getting stuck trying to find pg_type.h
This file is located in /usr/include/postgresql/catalog/pg_types.h but the module is expecting to find it in /usr/include/postgresql/server/catalog/pg_types.h
find_path(PostgreSQL_TYPE_INCLUDE_DIR
NAMES catalog/pg_type.h
PATHS
# Look in other places.
${PostgreSQL_ROOT_DIRECTORIES}
PATH_SUFFIXES
pgsql/server
postgresql/server
include/server
# Help the user find it if we cannot.
DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
)
It works if I add postgresql to the PATH_SUFFIXES
find_path(PostgreSQL_TYPE_INCLUDE_DIR
NAMES catalog/pg_type.h
PATHS
# Look in other places.
${PostgreSQL_ROOT_DIRECTORIES}
PATH_SUFFIXES
postgresql
pgsql/server
postgresql/server
include/server
# Help the user find it if we cannot.
DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
)

On Ubuntu you can also work around that issue by calling cmake with having PostgreSQL_TYPE_INCLUDE_DIR defined like this:
cmake -DPostgreSQL_TYPE_INCLUDE_DIR=/usr/include/postgresql/
See the bug report [1] for this issue and a potential fix [2]. Álso see the discussion about the reasoning behind the move on the debian mailinglist at [3].
On Ubuntu/Debian, starting with PostgreSQL 9.3 the header file pg_type.h
is moved to a separate package (from libpq-dev to postgresql-server-dev)
and consequently the file pg_type.h is moved to a new location
[1] https://gitlab.kitware.com/cmake/cmake/issues/17223
[2] https://gitlab.kitware.com/cmake/cmake/commit/d4fd30d8d8f5b9c4b5a110b4676cad2a19d7c314
[3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=314427

From Linux Mint 17.3 ("Rosa") with PostgreSQL 9.3, I had to adjust ilia choly's solution (interestingly, the suggested postgres entry in the list was already present in the file, but wasn't enough to fix things).
I had to edit /usr/share/cmake-2.8/Modules/FindPostgreSQL.cmake around line 114 and add postgresql/9.3 so that the find_path call looks like
find_path(PostgreSQL_TYPE_INCLUDE_DIR
NAMES catalog/pg_type.h
PATHS
# Look in other places.
${PostgreSQL_ROOT_DIRECTORIES}
PATH_SUFFIXES
postgresql/9.3
postgresql
pgsql/server
postgresql/server
include/server
# Help the user find it if we cannot.
DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
)

Related

CMake hunter error: `Unexpected MSVC_VERSION`

First of all, thank you for taking your time to help!
System: Windows 10 x64
cmake version: 3.24.1
Visual Studio 2022 v17.3.3
Console with admin privileges: Developer Command Prompt for VS 2022
Perl (Strawberry Perl): perl 5, version 32, subversion 1 (v5.32.1) built for MSWin32-x64-multi-thread
I am trying to compile kawpowminer from https://github.com/RavenCommunity/kawpowminer.
I already found some other solutions to similar errors but they haven't helped me.
Looked into those files (every single one printed out in the error) and found the lines with "hunter_add_package" as the cause of those errors.
I also changed 2019 to 2022 and 15 to 17 in those config files and edited the paths if needed.
I cloned at C:\Users\MEuser\kp the described git-project from "https://github.com/RavenCommunity/kawpowminer".
This is my script, the last line is causing the error. No errors are printed out before.
mkdir kp
cd kp
git clone https://github.com/RavenCommunity/kawpowminer
cd kawpowminer
git submodule update --init --recursive
cd build
cmake -G "Visual Studio 16 2019" -A X64 -H. -Bbuild -DETHASHCL=ON -DETHASHCUDA=ON -DAPICORE=ON ..
cd build
cmake --build . --config Release
Console: Developer Command Prompt for VS 2022
CMake Warning: Ignoring extra path from command line:
"C:/Users/Meuser/k2/kawpowminer/build"
-- [cable ] Cable 0.2.14 initialized
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
-- [cable ] Configurations: Release;RelWithDebInfo
-- [hunter] Calculating Toolchain-SHA1
-- [hunter] Calculating Config-SHA1
-- [hunter] HUNTER_ROOT: C:/.hunter
-- [hunter] [ Hunter-ID: e14bc15 | Toolchain-ID: b0b5bc7 | Config-ID: 196746b ]
[hunter ** INTERNAL **] Unexpected MSVC_VERSION: '1933' [hunter **
INTERNAL **] [Directory:C:/Users/MEuser/k2/kawpowminer]
--lol------------------------- ERROR ------------------------lol--
https://docs.hunter.sh/en/latest/reference/errors/error.internal.html
------------------------------------------------------------------
CMake Error at
C:/.hunter/_Base/Download/Hunter/0.23.214/e14bc15/Unpacked/cmake/modules/hunter_error_page.cmake:12
(message): Call Stack (most recent call first):
C:/.hunter/_Base/Download/Hunter/0.23.214/e14bc15/Unpacked/cmake/modules/hunter_internal_error.cmake:13 (hunter_error_page)
C:/.hunter/_Base/Download/Hunter/0.23.214/e14bc15/Unpacked/cmake/modules/hunter_setup_msvc.cmake:73
(hunter_internal_error)
C:/.hunter/_Base/Download/Hunter/0.23.214/e14bc15/Unpacked/cmake/modules/hunter_finalize.cmake:117
(hunter_setup_msvc)
C:/.hunter/_Base/Download/Hunter/0.23.214/e14bc15/Unpacked/cmake/modules/hunter_add_package.cmake:23
(hunter_finalize) CMakeLists.txt:56 (hunter_add_package)
-- Configuring incomplete, errors occurred!
I did found similar errors in the internet and on stack but nothing really helped me.
I also searched through the files and the config (CMakeLists.txt) and researched some lines, but I really didnt found anything interesting, similar or working.
(it's 5am in my country, please don't assume I didn't researched a lot or anything, I am just lost)
I also tried different includes for the HunterGate like
include("cmake/HunterGate.make")
HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.23.33.tar.gz"
SHA1 "abcf4b9b77b5a0160abc1da1cdda35f64b14196a"
)
But at this point I have to admit, I don't know what I am actually doing...
Investigating your error message,
[hunter ** INTERNAL **] Unexpected MSVC_VERSION: '1933' [hunter **
INTERNAL **] [Directory:C:/Users/MEuser/k2/kawpowminer]
I'm pretty sure this is fixed by this hunter PR ("Add support for Visual Studio 17 2022" #484), which added the following to :/cmake/modules/hunter_setup_msvc.cmake:
# ...
string(REGEX MATCH "^193[0-9]$" _vs_17_2022 "${MSVC_VERSION}")
# ...
elseif(_vs_17_2022)
set(HUNTER_MSVC_VERSION "17")
set(HUNTER_MSVC_YEAR "2022")
# ...
The solution is to update your hunter version to get this fix.
I think the Hunter first step docs should be all the information you need. Just change the HunterGate URL to use v0.23.317.
You get a gold star from me for providing so many details in your question (I think you were just missing what hunter version you're using).
If I could add a bit more to my answer, I'd say that reading long error messages to find the important parts and googling key phrases is useful (a skill? / a helpful trick?). If this is truly the cause of your issue, with luck, it's possible to find the answer yourself in less than 5 minutes. I just read your error message, and googled:
hunter "Unexpected MSVC_VERSION"
(the quotes means to look for an exact match)
, which led me to hunter_setup_msvc.cmake in the old hunter repo, and then I just went to the new repo, went to the file, and (by luck) the GitHub banner for most recent commit said "tnixeu add msvc17_2022 to huter_setup_msvc.cmake (#484)".
* Bonus link to wikipedia on MSVC versions.

Missing protobuf configuration when installing via ue4-conan

I'm trying to get gRPC running in Unreal Engine 4, using the conan-ue4cli tool. I use the provided grpc-ue4 recipe linked here: https://github.com/adamrehn/ue4-conan-recipes/tree/master/grpc-ue4
While running ue4 conan build "grpc-ue4" an error is thrown "Could not find a package configuration file provided by "Protobuf""
Output:
...
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- Found c-ares: C:/Users/Redux Gamer/.conan/data/cares-ue4/1.16.1/adamrehn/4.27/package/7333dc905312a2df09e78e1a60d59e628a5f0321/lib/cmake/c-ares/c-ares-config.cmake (found suitable version "1.16.1", minimum required is "1.13.0")
CMake Error at cmake/protobuf.cmake:58 (find_package):
Could not find a package configuration file provided by "Protobuf" with any
of the following names:
ProtobufConfig.cmake
protobuf-config.cmake
Add the installation prefix of "Protobuf" to CMAKE_PREFIX_PATH or set
"Protobuf_DIR" to a directory containing one of the above files. If
"Protobuf" provides a separate development package or SDK, be sure it has
been installed.
Call Stack (most recent call first):
CMakeLists.txt:224 (include)
-- Configuring incomplete, errors occurred!
See also "C:/.conan/9d531a/1/CMakeFiles/CMakeOutput.log".
See also "C:/.conan/9d531a/1/CMakeFiles/CMakeError.log".
grpc-ue4/1.30.2#adamrehn/4.27:
grpc-ue4/1.30.2#adamrehn/4.27: ERROR: Package 'bf9f4e336e64d98ce96ba6aaac093ac1ff3705d4' build failed
grpc-ue4/1.30.2#adamrehn/4.27: WARN: Build folder C:\.conan\9d531a\1
ERROR: grpc-ue4/1.30.2#adamrehn/4.27: Error in build() method, line 98
cmake.configure(source_folder="grpc", args=self.cmake_flags())
ConanException: Error 1 while executing cd C:\.conan\9d531a\1 && ...
I'm running Windows 10, UE4.27, python 3.7.8, cmake 3.21.3. I tried searching for the missing protobuf-config.cmake but it also can't be found in the conan or project folder.
Any suggestions or pointers where to look would be greatly appreciated.
The responsible conan-file is here: https://github.com/adamrehn/ue4-conan-recipes/tree/master/grpc-ue4/1.30.2
This got broken with commit 865c38e99f694e63fd109ae06423472ebb7885a3 (see: https://github.com/adamrehn/ue4-conan-recipes/pull/8)
Reverting this change solved it for me.
To manually fix this:
Go to C:\Users\USERNAME.conan\data\grpc-ue4\1.30.2\adamrehn\4.27\export\conanfile.py and in line 51 change:
"-DProtobuf_DIR=" + os.path.join(protobuf.rootpath, "lib/cmake/protobuf"),
to
"-DProtobuf_DIR=" + os.path.join(protobuf.rootpath, "cmake"),
Then you need to run the command with the --no-cache parameter (otherwise the recipe will be replaced again by the original)
ue4 conan build grpc-ue4 --no-cache

CMake find_package_handle_standard_args not silently failing when wrong version is found?

I'm writing a custom FindXXX.cmake for an imported target, at some point I call
find_package_handle_standard_args(XXX
REQUIRED_VARS XXX_ROOT_DIR
VERSION_VAR XXX_VERSION)
Now, it may happen that I found the imported target (XXX_ROOT_DIR is defined), but that the version is incorrect. In this case, I'd expect something like this:
find_package(XXX 4.5) # no REQUIRED
...to not fail and simply set XXX_Found to false. Currently, this throw a hard-error.
Can I achieve this with find_package_handle_standard_args? I could unset XXX_ROOT_DIR if the version is not correct but then I'd not to perform whatever is done in find_package_handle_standard_args twice.
The actual error is
CMake Error at I:/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:160 (set):
Syntax error in cmake code at
I:/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:160
when parsing string
Could NOT find XXX: Found unsuitable version "4.7", but required is exact version "3.8" (found I:\Softwares\XXX)
Invalid character escape '\S'.
Call Stack (most recent call first):
I:/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:456 (_FPHSA_FAILURE_MESSAGE)
I:/.../FindXXX.cmake:106 (find_package_handle_standard_args)
CMakeLists.txt:8 (find_package)
Answering here since someone might found this while facing a similar issue...
The problem is not at all find_package_handle_standard_args but a bug (I guess we can call it that) in CMake that breaks find_package_handle_standard_args when one of the variable contains \, typically Windows path.
Converting the \ into CMake / using
file(TO_CMAKE_PATH "${XXX_ROOT_DIR}" XXX_ROOT_DIR)
...solves the issue.

Undefined symbol for HDF5 when installing with cmake in Linux environment

I have been able to install and start a program with CMake (with HDF5) but once I access the "about" drop-down link for said program it crashes with the following error:
python: symbol lookup error: /nobackup/<user id>/program-devel/dist_linux/bin_linux/libprogramDLL.so: undefined symbol: h5lib_MP_h5get_libversion_f_
I believe it is an issue with linking static libraries but I am, unfortunately, quite new to CMake and unable to isolate the root problem. I know that this "symbol" is tied somehow to a libhdf5_fortran.a and this is listed in my Cache with:
$ grep -rnw '/nobackup/<user id>/program-devel/build' -e "libhdf5_fortran"
/nobackup/<user id>/program-devel/build/CMakeCache.txt:234:ToolkitLib_LIB_DEPENDS:STATIC=general;SomeLib;general;libz.a;general;libhdf5.a;general;libhdf5_fortran.a;
I’m not sure if this might be where the problem is or not but this is from the ToolKit file - CMakeLists.txt.
if (${USE_HDF5})
#link_directories (${HDF5_DIRECTORY}/lib)
if (WIN32)
target_link_libraries(ToolkitLib libszip libzlib libhdf5 libhdf5_f90cstub libhdf5_fortran)
else ()
# doesn't seem to work on Linux for some reason....
#target_link_libraries(ToolkitLib libsz libz libhdf5 libhdf5_fortran)
# ... try this ... seems to be getting the shared libs...not the static ones...
# set(HDF5_LINK_FLAGS "-L${HDF5_DIRECTORY}/lib -lz -lhdf5_fortran -lhdf5")
# SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${HDF5_LINK_FLAGS}")
# SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${HDF5_LINK_FLAGS}")
# ... doesn't work either ...
target_link_libraries(ToolkitLib libz.a libhdf5.a libhdf5_fortran.a)
endif()
endif()
The last 4 "target_link_library" elements are in directories I've added to my LD_LIBRARY_PATH (although, I've heard this isn't the preferred approach). There is also a final output line when I issue gmake install that might be relevant:
-- Set runtime path of "/nobackup/<user id>/program-devel/dist_linux/bin_linux/libProgramDLL.so" to "$ORIGIN/"
It seems I fixed my problem by adding a --with-pic on the hdf5 installation bash scripts. I also had to remove a -standard-semantics from the CMAKE_Fortran_FLAGS in the src directory. Those two things along with the help you provided fixed my problem. Thanks a lot Pierre de Buyl!

What (if any) path for OpenNI should show up in environmental variables

I recently had it pointed out to me that I might have OpenNI installed correctly but PCL is unable to access it. I've been trying to use various packages with the Kinect and when cmake compiling I always encounter the same error:
-- checking for module 'openni-dev'
-- package 'openni-dev' not found
-- Could NOT find openni (missing: OPENNI_INCLUDE_DIRS)
** WARNING ** io features related to openni will be disabled
I used printenv and received this output:
printenv
SSH_AGENT_PID=2570
GPG_AGENT_INFO=/tmp/keyring-xXJFL7/gpg:0:1
TERM=xterm
SHELL=/bin/bash
ROS_ROOT=/opt/ros/hydro/share/ros
XDG_SESSION_COOKIE=aa6e36316433d5c21f6f3b1500000008-1400098211.848077-377195861
ROS_PACKAGE_PATH=/opt/ros/hydro/share
ROS_MASTER_URI=http://localhost:11311
WINDOWID=56623110
GNOME_KEYRING_CONTROL=/tmp/keyring-xXJFL7
USER=robot2
LD_LIBRARY_PATH=/opt/ros/hydro/lib
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
CPATH=/opt/ros/hydro/include
SSH_AUTH_SOCK=/tmp/keyring-xXJFL7/ssh
SESSION_MANAGER=local/robot2-Precision-T7600:#/tmp/.ICE-unix/2535,unix/robot2-Precision-T7600:/tmp/.ICE-unix/2535
DEFAULTS_PATH=/usr/share/gconf/ubuntu.default.path
XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
PATH=/opt/ros/hydro/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
DESKTOP_SESSION=ubuntu
PWD=/home/robot2
GNOME_KEYRING_PID=2524
LANG=en_US.UTF-8
MANDATORY_PATH=/usr/share/gconf/ubuntu.mandatory.path
UBUNTU_MENUPROXY=libappmenu.so
COMPIZ_CONFIG_PROFILE=ubuntu
GDMSESSION=ubuntu
SHLVL=1
HOME=/home/robot2
ROS_DISTRO=hydro
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
PYTHONPATH=/opt/ros/hydro/lib/python2.7/dist-packages
LOGNAME=robot2
XDG_DATA_DIRS=/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-DdLQNdIXso,guid=2440d412c31af4bd219f648600000030
PKG_CONFIG_PATH=/opt/ros/hydro/lib/pkgconfig
LESSOPEN=| /usr/bin/lesspipe %s
CMAKE_PREFIX_PATH=/opt/ros/hydro
DISPLAY=:0.0
XDG_CURRENT_DESKTOP=Unity
LESSCLOSE=/usr/bin/lesspipe %s %s
ROS_ETC_DIR=/opt/ros/hydro/etc/ros
COLORTERM=gnome-terminal
XAUTHORITY=/home/robot2/.Xauthority
_=/usr/bin/printenv
Does anyone have any ideas? Is this potentially a path issue?
It seems you have installed OpenNI into some non-standard ocation, that's why CMake can't locate it. Help it by setting CMAKE_PREFIX_PATH to the dir where OpenNI's include/ is located.