1. CMAKE_PREFIX_PATH
CMAKE_PREFIX_PATH
是一个分号分隔的路径列表,用来指明软件/库安装路径前缀,以供
find_package()
,
find_program()
,
find_library()
,
find_file()
和
find_path()
命令搜索使用,这样就方便搜索可执行文件、头文件、库文件及相关配置文件等。
CMAKE_PREFIX_PATH文档
2. 演示
笔者将
Eigen-3.4.0
安装在了
/opt/eigen-3.4.0
目录下,在使用时可以这样写
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(program LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
list(APPEND CMAKE_PREFIX_PATH "/opt/eigen-3.4.0") # 安装路径前缀
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})
message("** Found Eigen3 in: ${EIGEN3_ROOT_DIR}")
add_executable(${PROJECT_NAME} main.cpp)
命令cmake
运行日志
-- The CXX compiler identification is GNU 9.4.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
** Found Eigen3 in: /opt/eigen-3.4.0
-- Configuring done
-- Generating done
-- Build files have been written to: (这个路径内容太长,删掉了)
测试程序如下
#include <iostream>
#include <Eigen/Eigen>
int main(int argc, char* argv[])
std::cout << "Eigen3 version is : "
<< EIGEN_WORLD_VERSION << "."
<< EIGEN_MAJOR_VERSION << "."
<< EIGEN_MINOR_VERSION << std::endl;
return 0;