How to remove a path from CMake variable set by find_package - cmake

Problem
I am trying to remove a particular path from CMake variables VTK_INCLUDE_DIRS and VTK_LIBRARIES that are set by find_package(VTK).
In CMakeLists.txt of the PCL library, the VTK library is first searched by find_package(VTK). However, the python path /home/w/.conda/envs/py36/lib seems to get in and causes a conflict with libz.so.1 in /usr/lib/x86_64-linux-gnu. (I believe this is because the VTK library was built with Python3 wrapper in the Anaconda environment.):
cmake ..
...
-- VTK found (
include: /usr/local/include/vtk-8.2;/home/w/.conda/envs/py36/include/python3.6m,
lib: vtksys; ...;/home/w/.conda/envs/py36/lib/libpython3.6m.so;vtkPythonInterpreter; ...
...
CMake Warning at cmake/pcl_targets.cmake:263 (add_executable):
Cannot generate a safe runtime search path for target pcl_generate because
files in some directories may conflict with libraries in implicit
directories:
runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/w/.conda/envs/py36/lib
Some of these libraries may not be found correctly.
Call Stack (most recent call first):
tools/CMakeLists.txt:148 (PCL_ADD_EXECUTABLE)
Try 1
I tried to remove the Python3 path by modifying the CMakeLists.txt as follows:
if(WITH_VTK AND NOT ANDROID)
find_package(VTK)
list(REMOVE_ITEM VTK_INCLUDE_DIRS "/home/w/.conda/envs/py36/include/python3.6m")
list(REMOVE_ITEM VTK_LIBRARIES "/home/w/.conda/envs/py36/lib/libpython3.6m.so")
if(VTK_FOUND)
...
message(STATUS "VTK found (include: ${VTK_INCLUDE_DIRS}, lib: ${VTK_LIBRARIES}")
This does change the CMake message that prints out, but doestn't solve the problem; the problem still persists:
-- VTK found (
include: /usr/local/include/vtk-8.2,
lib: vtksys; ...;vtkPythonInterpreter; ...
...
runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/w/.conda/envs/py36/lib
Question
So list(REMOVE_ITEM VTK_INCLUDE_DIRS "/home/w/.conda/envs/py36/include/python3.6m") does remove this path from the VTK_INCLUDE_DIRS variable, but doesn't seem to change the actual inclue path internally. I must have missed some inportant concept of CMake.
How should I solve this problem?

Related

Cannot generate a safe runtime search path for target caffe because files in some directories may conflict with libraries in implicit directories

I am trying to install this code https://github.com/NVlabs/ssn_superpixels but get an error at the cmake .. step
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_cublas_LIBRARY (ADVANCED)
linked by target "caffe" in directory /home/haziq/ASTAR/scripts/ssn_superpixels/lib/video_prop_networks/lib/caffe/src/caffe
So I deleted the build folder, recreated it and cd into it and ran cmake .. -DCUDA_cublas_LIBRARY=/usr/lib/x86_64-linux-gnu/libcublas.so.9.1 but now get the following messages.
CMake Warning at src/caffe/CMakeLists.txt:20 (add_library):
Cannot generate a safe runtime search path for target caffe because files
in some directories may conflict with libraries in implicit directories:
runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/haziq/anaconda3/envs/ssn/lib
Some of these libraries may not be found correctly.
CMake Warning at src/caffe/test/CMakeLists.txt:29 (add_executable):
Cannot generate a safe runtime search path for target test.testbin because
files in some directories may conflict with libraries in implicit
directories:
runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/haziq/anaconda3/envs/ssn/lib
Some of these libraries may not be found correctly.
CMake Warning at tools/CMakeLists.txt:14 (add_executable):
Cannot generate a safe runtime search path for target extract_features
because files in some directories may conflict with libraries in implicit
directories:
runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/haziq/anaconda3/envs/ssn/lib
Some of these libraries may not be found correctly.
CMake Warning at tools/CMakeLists.txt:14 (add_executable):
Cannot generate a safe runtime search path for target device_query because
files in some directories may conflict with libraries in implicit
directories:
runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/haziq/anaconda3/envs/ssn/lib
Some of these libraries may not be found correctly.
CMake Warning at tools/CMakeLists.txt:14 (add_executable):
Cannot generate a safe runtime search path for target convert_imageset
because files in some directories may conflict with libraries in implicit
directories:
runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/haziq/anaconda3/envs/ssn/lib
Some of these libraries may not be found correctly.
CMake Warning at tools/CMakeLists.txt:14 (add_executable):
Cannot generate a safe runtime search path for target test_net because
files in some directories may conflict with libraries in implicit
directories:
runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/haziq/anaconda3/envs/ssn/lib
Some of these libraries may not be found correctly.
CMake Warning at tools/CMakeLists.txt:14 (add_executable):
Cannot generate a safe runtime search path for target net_speed_benchmark
because files in some directories may conflict with libraries in implicit
directories:
runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/haziq/anaconda3/envs/ssn/lib
Some of these libraries may not be found correctly.
CMake Warning at tools/CMakeLists.txt:14 (add_executable):
Cannot generate a safe runtime search path for target compute_image_mean
because files in some directories may conflict with libraries in implicit
directories:
runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/haziq/anaconda3/envs/ssn/lib
Some of these libraries may not be found correctly.
CMake Warning at tools/CMakeLists.txt:14 (add_executable):
Cannot generate a safe runtime search path for target train_net because
files in some directories may conflict with libraries in implicit
directories:
runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/haziq/anaconda3/envs/ssn/lib
Some of these libraries may not be found correctly.
CMake Warning at tools/CMakeLists.txt:14 (add_executable):
Cannot generate a safe runtime search path for target finetune_net because
files in some directories may conflict with libraries in implicit
directories:
runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/haziq/anaconda3/envs/ssn/lib
Some of these libraries may not be found correctly.
CMake Warning at tools/CMakeLists.txt:14 (add_executable):
Cannot generate a safe runtime search path for target
upgrade_net_proto_binary because files in some directories may conflict
with libraries in implicit directories:
runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/haziq/anaconda3/envs/ssn/lib
Some of these libraries may not be found correctly.
CMake Warning at tools/CMakeLists.txt:14 (add_executable):
Cannot generate a safe runtime search path for target
upgrade_net_proto_text because files in some directories may conflict with
libraries in implicit directories:
runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/haziq/anaconda3/envs/ssn/lib
Some of these libraries may not be found correctly.
CMake Warning at tools/CMakeLists.txt:14 (add_executable):
Cannot generate a safe runtime search path for target
upgrade_solver_proto_text because files in some directories may conflict
with libraries in implicit directories:
runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/haziq/anaconda3/envs/ssn/lib
Some of these libraries may not be found correctly.
CMake Warning at tools/CMakeLists.txt:14 (add_executable):
Cannot generate a safe runtime search path for target caffe.bin because
files in some directories may conflict with libraries in implicit
directories:
runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/haziq/anaconda3/envs/ssn/lib
Some of these libraries may not be found correctly.
CMake Warning at python/CMakeLists.txt:9 (add_library):
Cannot generate a safe runtime search path for target pycaffe because files
in some directories may conflict with libraries in implicit directories:
runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/haziq/anaconda3/envs/ssn/lib
Some of these libraries may not be found correctly.
I found a post here CMake cannot resolve runtime directory path that provides a solution for find_library and find_package but mine is add_library. Anyway I tried fixing the first CMake warning
CMake Warning at src/caffe/CMakeLists.txt:20 (add_library):
Cannot generate a safe runtime search path for target caffe because files
in some directories may conflict with libraries in implicit directories:
runtime library [libsnappy.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/haziq/anaconda3/envs/ssn/lib
Some of these libraries may not be found correctly.
by editing line 20 of src/caffe/CMakeLists.txt by replacing add_library(caffe ${srcs}) with add_library(caffe ${srcs} NO_DEFAULT_PATH) but now get this message.
CMake Error at src/caffe/CMakeLists.txt:20 (add_library):
Cannot find source file:
NO_DEFAULT_PATH
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
What can I try next?
install libcublas 10 then run again

Explicitly tell to CMake target_link_libraries() to read dependency as target and not as a file from system path?

I got multiple warnings:
CMake Warning at libsysev/src/CMakeLists.txt:17 (add_library):
Cannot generate a safe runtime search path for target sysev because files
in some directories may conflict with libraries in implicit directories:
runtime library [libzlog.so] in /usr/lib/arm-linux-gnueabihf may be hidden by files in:
/home/user/project/BUILD/libzlog/src
Some of these libraries may not be found correctly.
Target defined as following:
add_library(sysev SHARED main.cpp)
target_link_libraries(sysev PUBLIC zlog)
zlog provided in source code and also installed to the system.
Root CMakeLists.txt looks like:
project(xxx)
add_subdirectory(zlog)
add_subdirectory(sysev)
I want to disambiguate zlog. CMake must know this is a target and not a file from system path.

Use cmake FindBLAS to link OpenBLAS

I am using cmake 3.16, and I know that cmake supports finding OpenBLAS by using FindBLAS (here).
I am trying to link OpenBLAS to my c++ project. Here is my CMakeLists.txt.
cmake_minimum_required(VERSION 3.15)
project(my_project)
# source file
file(GLOB SOURCES "src/*.cpp")
# executable file
add_executable(main.exe ${SOURCES})
# link openblas
set(BLA_VENDER OpenBLAS)
find_package(BLAS REQUIRED)
if(BLAS_FOUND)
message("OpenBLAS found.")
include_directories(${BLAS_INCLUDE_DIRS})
target_link_libraries(main.exe ${BLAS_LIBRARIES})
endif(BLAS_FOUND)
If I run cmake, it runs just find, and outputs OpenBLAS found.. However, if I start to compile the codes (make VERBOSE=1), the library is not linked, so that the codes fail to compile. Here is the error info:
fatal error: cblas.h: No such file or directory
#include <cblas.h>
^~~~~~~~~
compilation terminated.
I installed OpenBLAS successfully. The header files are in /opt/OpenBLAS/include, and the shared libraries are in /opt/OpenBLAS/lib. My OS is ubuntu 18.04.
Any help? Thank you!
Thanks Tsyvarev. I found the problem.
I tried to use message() to print out the variables.
message(${BLAS_LIBRARIES})
Which gives:
/opt/OpenBLAS/lib/libopenblas.so
So the shared library is found.
However, for BLAS_INCLUDE_DIRS, it gives:
message(${BLAS_INCLUDE_DIRS})
CMake Error at CMakeLists.txt:27 (message):
message called with incorrect number of arguments
It turns out that BLAS_INCLUDE_DIRS is not in the FindBLAS variables. So I add the include header files manually:
set(BLA_VENDER OpenBLAS)
find_package(BLAS REQUIRED)
if(BLAS_FOUND)
message("OpenBLAS found.")
include_directories(/opt/OpenBLAS/include/)
target_link_libraries(main.exe ${BLAS_LIBRARIES})
endif(BLAS_FOUND)
This time it compiles without error. Instead of using include_directories(), you could also try find_path() (check this).

How to set up CMakeLists.txt to find a .PC file (pkg-config with pkg_search_module) in a non-default path?

I am trying to create a simple project using SDL2 and SDL2_image extension. As SDL2_image doesn't provide official support for Find*.cmake modules, my alternative was to use pkg-config to find those libraries.
However, I built SDL2 and SDL2_image myself and installed them in a custom path (~/Library/SDL2 and ~/Library/SDL2_image).
CMake seems to be able to find SDL2 properly, but it can't find SDL2_image, even if I put the .PC file in the system default path (/usr/share/pkgconfig).
How do I tell CMake to look for a .PC file in a non-default (system) path? I need that to build a simple project using SDL2 and SDL2_image.
I've tried to put the SDL2_image.pc file in the default system path for .PC files (/usr/share/pkgconfig), but it seems not to be changing anything.
find_package(PkgConfig)
# SDL2 can be found and included
pkg_search_module(SDL2 REQUIRED sdl2)
# SDL2_image cannot be found and thus the project doesn't configure/generate.
pkg_search_module(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
Error message when running "cmake":
-- Checking for one of the modules 'SDL2_image>=2.0.0'
CMake Error at /usr/share/cmake-3.7/Modules/FindPkgConfig.cmake:637 (message):
None of the required 'SDL2_image>=2.0.0' found
Call Stack (most recent call first):
CMakeLists.txt:12 (pkg_search_module)
Find pkg-config *.pc file, and export the path:
export PKG_CONFIG_PATH="/path/lib/pkgconfig"

CMake find_package() Eclipse, OS X

I managed to create Make Target in Eclipse and add a CMakeListst.txt to a very simple project and it worked.
Now, my next step is to use two external libraries, Boost and Eigen.
My project is in /Users/MyUser/Documents/workspace/Test
The libraries are /Users/MyUser/Documents/MyLib/Libraries
Now, in the CMakeLists.txt file I try to find Boost and Eigen, which are in the libraries folder, but always the returned message is
CMake Error at CMake/TPLs/FindBoost.cmake:1126 (message): Unable to
find the requested Boost libraries.
Unable to find the Boost header files. Please set BOOST_ROOT to the
root directory containing Boost or BOOST_INCLUDEDIR to the directory
containing Boost's headers. Call Stack (most recent call first):
CMakeLists.txt:23 (FIND_PACKAGE)
-- Configuring incomplete, errors occurred! CMake Error at /Applications/CMake
2.8-11.app/Contents/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108
(message): Could NOT find Eigen3 (missing: EIGEN3_INCLUDE_DIRS
EIGEN3_VERSION_OK) (Required is at least version "2.91.0") Call
Stack (most recent call first): /Applications/CMake
2.8-11.app/Contents/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315
(_FPHSA_FAILURE_MESSAGE) CMake/TPLs/FindEigen3.cmake:76
(find_package_handle_standard_args) CMakeLists.txt:30 (FIND_PACKAGE)
I am new to CMake, so I must be missing some way to tell CMake to search in my library folder. How can I find the packages with CMake when building the project?
BTW I'm working under Mac OS X Mavericks.
EDIT
Reading through the file FindEigen3.cmake there should be a variable called EIGEN3_INCLUDE_DIRS that points to the include directory of Eigen, is this true?
Now, from the following message
Could NOT find Eigen3 (missing: EIGEN3_INCLUDE_DIRS EIGEN3_VERSION_OK)
I would think that cmake is actually finding that directory as it says EIGEN3_VERSION_OK but then why can't cmake find the rest of the include files?
Am I still missing something? I created the environment variable within Eclipse and then add a line to the FindEigen3.cmake to test the value of the environment variable EIGEN3_INCLUDE_DIRS
message(STATUS "Eigen version: ${EIGEN3_INCLUDE_DIRS}")
But the message I'm getting is
--Eigen version: EIGEN3_INCLUDE_DIRS-NOTFOUND
Any advise?
EDIT
I tried with the question-related answers but none was able to make Eclipse+CMake find Boost and Eigen libraries. I guess the problem here is how to make Eclipse recognize the system variables.
When you do not believe in setting environment variables in Eclipse, you can pass Cmake-defines either directly to cmake command:
cmake -E chdir Release/ cmake -G "Unix Makefiles" ... -DBOOST_ROOT:PATHNAME=boost/install/dir ...
or define them in your CMakeLists.txt before find boost/eigen3
SET(BOOST_ROOT boost/install/dir)
...
FIND_PACKAGE(BOOST ... )
or use environment variables within your OS/shell. You must define them before launching the Eclipse. E.g. from bash, do
export BOOST_ROOT=boost/install/dir
eclipse
Note that you have to define all variables needed for both boost and eigen3. You can place some debugging messages in your CMakeLists.txt to confirm that you pass them correctly:
MESSAGE("Boost root: ${BOOST_ROOT}")