CMake find_package使用主目录中的<package> Config.cmake而不是系统路径中的一个

时间:2019-07-18 12:36:46

标签: cmake cron eigen3

我在构建项目时遇到了一个问题,该项目依赖于具有cron作业的Eigen3库。如果我通过登录服务器手动构建它,则不会出现问题。 Eigen库是从源代码编译并安装的:

cd /home/robotronics/Libraries
git clone https://github.com/eigenteam/eigen-git-mirror.git
git checkout 3.3.7
mkdir build
cd build
cmake ../
make
sudo make install

用于重现我的问题的最小项目CMakeLists如下:

cmake_minimum_required(VERSION 3.0.0)
project(ProblemWithEigen CXX)

message("CMAKE_MODULE_PATH:  ${CMAKE_MODULE_PATH}")
message("CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
message("CMAKE_FRAMEWORK_PATH: ${CMAKE_FRAMEWORK_PATH}")
message("CMAKE_APPBUNDLE_PATH: ${CMAKE_APPBUNDLE_PATH}")

message("CMAKE_SYSTEM_PREFIX_PATH: ${CMAKE_SYSTEM_PREFIX_PATH}")
message("CMAKE_SYSTEM_FRAMEWORK_PATH: ${CMAKE_SYSTEM_FRAMEWORK_PATH}")
message("CMAKE_SYSTEM_APPBUNDLE_PATH: ${CMAKE_SYSTEM_APPBUNDLE_PATH}")

find_package(Eigen3 REQUIRED)

message("Eigen3_CONFIG: ${Eigen3_CONFIG}")
message("Eigen3_CONSIDERED_CONFIGS: ${Eigen3_CONSIDERED_CONFIGS}")
message("EIGEN3_INCLUDE_DIRS: ${EIGEN3_INCLUDE_DIRS}")

现在,如果我以使用ssh登录的cmake -DCMAKE_FIND_DEBUG_MODE=ON ../用户的身份对项目执行robotronics命令,则可以正确找到Eigen3库:

-- The CXX compiler identification is GNU 6.3.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMAKE_MODULE_PATH:  
CMAKE_PREFIX_PATH: 
CMAKE_FRAMEWORK_PATH: 
CMAKE_APPBUNDLE_PATH: 
CMAKE_SYSTEM_PREFIX_PATH: /usr/local;/usr;/;/usr;/usr/local
CMAKE_SYSTEM_FRAMEWORK_PATH: 
CMAKE_SYSTEM_APPBUNDLE_PATH: 
Checking prefix [/usr/local/]
Checking file [/usr/local/Eigen3Config.cmake]
Checking file [/usr/local/eigen3-config.cmake]
Checking file [/usr/local/share/eigen3/Eigen3Config.cmake]
Checking file [/usr/local/share/eigen3/eigen3-config.cmake]
Checking file [/usr/local/share/eigen3/cmake/Eigen3Config.cmake]
Eigen3_CONFIG: /usr/local/share/eigen3/cmake/Eigen3Config.cmake
Eigen3_CONSIDERED_CONFIGS: /usr/local/share/eigen3/cmake/Eigen3Config.cmake
EIGEN3_INCLUDE_DIRS: /usr/local/include/eigen3
-- Configuring done
-- Generating done
-- Build files have been written to: /home/robotronics/Projects/ProblemWithEigen/build

但是,如果我在与crone作业相同的环境下执行cmake

/usr/bin/env -i $(cat cron-env) /home/robotronics/Projects/ProblemWithEigen/dbgScript.sh

cron-env在哪里

HOME=/home/robotronics
LOGNAME=robotronics
PATH=/usr/bin:/bin
LANG=en_US.UTF-8
SHELL=/bin/sh
PWD=/home/robotronics

dbgScript.sh

#!/bin/bash
ROOT_DIR=/home/robotronics/Projects/ProblemWithEigen
cd ${ROOT_DIR}
mkdir build
cd build
cmake -DCMAKE_FIND_DEBUG_MODE=ON ../ &> output

我明白了:

-- The CXX compiler identification is GNU 6.3.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMAKE_MODULE_PATH:  
CMAKE_PREFIX_PATH: 
CMAKE_FRAMEWORK_PATH: 
CMAKE_APPBUNDLE_PATH: 
CMAKE_SYSTEM_PREFIX_PATH: /usr/local;/usr;/;/usr;/usr/local
CMAKE_SYSTEM_FRAMEWORK_PATH: 
CMAKE_SYSTEM_APPBUNDLE_PATH: 
Checking prefix [/usr/]
Checking file [/usr/Eigen3Config.cmake]
Checking file [/usr/eigen3-config.cmake]
Checking prefix [/]
Checking file [/Eigen3Config.cmake]
Checking file [/eigen3-config.cmake]
Checking prefix [/home/robotronics/Libraries/eigen-git-mirror/build/]
Checking file [/home/robotronics/Libraries/eigen-git-mirror/build/Eigen3Config.cmake]
Eigen3_CONFIG: /home/robotronics/Libraries/eigen-git-mirror/build/Eigen3Config.cmake
Eigen3_CONSIDERED_CONFIGS: /home/robotronics/Libraries/eigen-git-mirror/build/Eigen3Config.cmake
EIGEN3_INCLUDE_DIRS: /home/robotronics/include/eigen3
-- Configuring done
-- Generating done
-- Build files have been written to: /home/robotronics/Projects/ProblemWithEigen/build

为什么cmake在以下路径中寻找:/home/robotronics/Libraries/eigen-git-mirror/build/用于Eigen3配置文件?

cmake --version
cmake version 3.7.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

0 个答案:

没有答案