Why can't cmake find a package installed using Mac ports? - cmake

I installed cxWidgets as follows:
sudo install wxWidgets-3.0
In the cmake file of a project I am trying to build, find_package is called:
find_package(wxWidgets REQUIRED)
However, cmake complains that it can't find the package:
CMake Error at /opt/local/share/cmake-3.4/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES
wxWidgets_INCLUDE_DIRS)
My question is, given that cxWidgets is installed (I have confirmed by running port installed), why can't cmake find it?

The problem is that MacPorts has to support multiple versions of wxWidgets and I have no good idea how to automatically let CMake find the requested version.
You have two options.
The first one is to run sudo port select wxWidgets wxWidgets-3.0. Then CMake should automatically find wxWidgets 3.0.
The second option is to add an additional argument to cmake that depends on the software you are trying to compile.
Usually one of these flags should work:
-DwxWidgets_CONFIG_EXECUTABLE=/opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/bin/wx-config
-DwxWidgets_wxrc_EXECUTABLE=/opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/bin/wxrc

Related

wxWidgets CMake Windows Setup Troubles

I am really struggling to setup wxWidgets to work on Windows and CMake and would appreciate some help.
I have downloaded wxWidgets 3.1.4, run the setup (which extracted to C:\CPP_lib\wxWidgets) and then ran the following commands in the terminal:
cd C:\CPP_lib
mkdir wxWidgets-install
cmake C:\CPP_lib\wxWidgets -DCMAKE_INSTALL_PREFIX=C:\CPP_lib\wxWidgets-install -DwxBUILD_SHARED=OFF
cd wxWidgets-install
cmake --build . --target install
I have environment variables CMAKE_PREFIX_PATH set to C:\CPP_lib and wxWidgets_DIR and wxWidgets_ROOT_DIR both set to C:\CPP_lib\wxWidgets-install.
However, when I have a simple CMake project that calls find_package(wxWidgets), I get the following message in the terminal:
Found wxWidgets: winmm;comctl32;uuid;oleacc;uxtheme;rpcrt4;shlwapi;version;wsock32
missing components: core base png tiff jpeg zlib regex expat
Please help - I have been struggling for a while now :(
It turns out the issue was a very specific one related to vcpkg.
I had pointed CMake to my vcpkg toolchain file (even though wxWidgets was installed independent of vcpkg) and this was causing issues with finding wxWidgets i.e. vcpkg was preventing wxWidgets (a non-vcpkg installation) from being found.
I believe this is a vcpkg bug, although am not sure, but have reported it anyways.

How to enable pkg-config support in eigen3 on Windows?

I am compiling a 3rd party library which uses the following commands to find Eigen3:
find_package( PkgConfig )
pkg_check_modules( EIGEN3 REQUIRED eigen3 )
include_directories(${EIGEN3_INCLUDE_DIRS})
The find_package( PkgConfig ) command runs correctly because I specified the PKG_CONFIG_EXECUTABLE variable. But pkg_check_modules( EIGEN3 REQUIRED eigen3 ) returns an error:
-- Checking for module 'eigen3'
-- No package 'eigen3' found
The Eigen3's official webpage says "It is not necessary to use CMake or install anything." It took me quite a while to realize this statement is wrong. So I ran the following to compile and install Eigen3 (version 3.3.5):
cmake -DCMAKE_CONFIGURATION_TYPES=Release -DCMAKE_INSTALL_PREFIX=E:\3rd-parties\eigen-3.3.5\install_ -G"Visual Studio 14 2015 Win64" ..
The compilation and installation process were both successful because I didn't see any failure in VS2015. But, when I go back to the build folder of the 3rd party library and run cmake again, I got exactly the same error. Eigen3 official website only provides an instruction using find_package, but not pkg-config.exe, so I next searched Google and find this thread. The answer says we need to "enable pkg-config support in the eigen3 cmake". I don't know how to enable it. Is there any specific CMake variable for this purpose? Since it is a new problem, and Eigen's main page says "To get help, stackoverflow is your best resource." so I come here for help. My question is: how to enable pkg-config support in eigen3? Or to put it another way: how to pass the pkg_check_modules( EIGEN3 REQUIRED eigen3 ) cmake command? Thanks a lot.
PS: I am working on Windows 10.
According to the Eigen3 sources, an option EIGEN_BUILD_PKGCONFIG is responsible on pkg-config support.
On Windows the whole option is disabled, but you may try to set it:
cmake -DEIGEN_BUILD_PKGCONFIG=ON <... other arguments>
When use pkg-config for find Eigen3 in CMake script, make sure that installation directory of Eigen3 is listed in CMAKE_PREFIX_PATH variable. (If CMake version used by a project is less than 3.1, then you need to additionally set PKG_CONFIG_USE_CMAKE_PREFIX_PATH to ON for tell pkgconfig module to use variable CMAKE_PREFIX_PATH. See more in the documentation for pkgconfig module.)

Why won't find_library find libgmp

I'm trying to build a cmake project, and the repo I have been given has the lines
find_library(gmp gmp)
if(NOT gmp)
message(FATAL_ERROR "gmp not found")
endif()
which cause CMake configuration to fail.
I have been told this CMake works on Redhat Enterprise Linux 7.3.
I have also been told this repo should build in any Linux environment with the correct libraries installed, and an Ubuntu environment has been specifically referenced.
I am building in Debian 9.4.0, I have installed gmp, libgmp.so is located at /usr/lib/x86_64-linux-gnu/openssl-1.0.2/engines/libgmp.so
and I also have a libgmp.so.10 at /usr/lib/x86_64-linux-gnu/libgmp.so.10.
So, to recap, I have been handed a repo I have been told builds, but it does not build, it fails at this specific step, and I can't get google to give me any relevant results on how to fix the issue/what I am doing wrong.
libgmp is installed, but the development libraries are not.
Cmake find_libraries looks for the files required for software development, and while the libgmp package is installed, the libgmp-dev package is not.
Install libgmp-dev.
CMake doesn't search "so-version" files:
If find_library is called for "gmp" library name, CMake searches libgmp.so file, but not libgmp.so.10 one.
Normally, the library file without so-version is just a soft link to the newest so-version file. If your Linux distro doesn't create such link, you may create it manually:
ln -s libgmp.so libgmp.so.10
If you want CMake to find /usr/lib/x86_64-linux-gnu/openssl-1.0.2/engines/libgmp.so file, which is not under directory normally searched by CMake, you need to hint CMake about it. E.g. with PATHS option:
find_library(gmp gmp PATHS "/usr/lib/x86_64-linux-gnu/openssl-1.0.2/engines")

Cmake errors when using LLVM 5.0.0 from brew

I'm trying to use the stock LLVM 5.0.0 provided by Homebrew (MacOS High Sierra 10.13.3). LLVM is installed on my machine under /usr/local/Cellar/llvm/5.0.0/
Now, in my project, I have the following lines in CMakeLists.txt:
# Find the LLVM library
find_package( LLVM 5.0.0 REQUIRED )
include_directories( "${LLVM_INCLUDE_DIRS}" )
link_directories(${LLVM_LIBRARY_DIRS})
message(STATUS "LLVM include dirs: ${LLVM_INCLUDE_DIRS}")
If I run CMake without any parameters, I get:
CMake Error at CMakeLists.txt:74 (find_package):
By not providing "FindLLVM.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "LLVM", but
CMake did not find one.
Could not find a package configuration file provided by "LLVM" (requested
version 5.0.0) with any of the following names:
LLVMConfig.cmake
llvm-config.cmake
Add the installation prefix of "LLVM" to CMAKE_PREFIX_PATH or set
"LLVM_DIR" to a directory containing one of the above files. If "LLVM"
provides a separate development package or SDK, be sure it has been
installed.
It tells me that it couldn't find LLVM. So, I pass the path to the LLVM_DIR, like this:
cmake .. -DLLVM_DIR=/usr/local/Cellar/llvm/5.0.0/share/cmake/modules/
I would expect everything to work. Instead I get the following error:
CMake Error at CMakeLists.txt:74 (find_package):
Could not find a configuration file for package "LLVM" that is compatible
with requested version "5.0.0".
The following configuration files were considered but not accepted:
/usr/local/Cellar/llvm/5.0.0/share/cmake/modules/llvm-config.cmake,
version: unknown
For some reason the version is not present anywhere in the share/cmake/modules directory.
How can I fix this, without changing the brew-installed LLVM?
Found the answer. I was passing a wrong path to LLVM_DIR.
I just have to use another directory (buried in lib, not in share):
cmake .. -DLLVM_DIR=/usr/local/Cellar/llvm/5.0.0/lib/cmake/llvm/
Not sure why brew decided to install 2 versions of CMake helpers for LLVM, one in share and one in lib.

Where should I install FindXXX.cmake file of my own project and how to find it?

I am developing two CMake projects: libABC and libXYZ. libXYZ requires libABC, and so I would like install FindABC.cmake in an appropriate location on Mac and Linux machines.
libABC and its related files are installed under /usr/local by default, and I think FindABC.cmake also should be installed under the same directory. I tried installing it in the following six different locations.
/usr/local/lib/cmake/ABC/FindABC.cmake
/usr/local/share/cmake/ABC/FindABC.cmake
/usr/local/lib/ABC/FindABC.cmake
/usr/local/share/ABC/FindABC.cmake
/usr/local/lib/ABC/cmake/FindABC.cmake
/usr/local/share/ABC/cmake/FindABC.cmake
However CMakeList.txt of libXYZ cannot find it with the following error.
CMake Error at CMakeLists.txt:51 (find_package):
By not providing "FindABC.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"ABC", but CMake did not find one.
My cmake command was installed under /opt/local by using MacPorts on OS X. So I think it searches not /usr/local but only /opt/local.
I know that defining CMAKE_MODULE_PATH when executing cmake command solve this issue (e.g., cmake -DCMAKE_MODULE_PATH=/usr/local/lib/cmake/ABC), but I do not want to ask all users to do it every time.
My questions are
Q1. Where should I install FindABC.cmake during the libABC installation process?
Q2. How do I properly find FindABC.cmake in CMakeLists.txt of libXYZ without hard-coding CMAKE_MODULE_PATH in it?