我的旧
CMakeLists.txt
测试项目的 libigl
文件包含以下部分:
project(libigl)
set(LIBIGL_HOME $ENV{HOME}/apps/libigl)
set(CMAKE_PREFIX_PATH ${LIBIGL_HOME})
set(CMAKE_MODULE_PATH ${LIBIGL_HOME}/cmake)
find_package(${PROJECT_NAME} CONFIGS libigl.cmake REQUIRED)
if(${PROJECT_NAME}_FOUND)
message("-- Found ${PROJECT_NAME}")
else()
message(FATAL_ERROR "${PROJECT_NAME} is not found")
endif()
我尝试使用
libigl
库的新版本 2.4.0 构建此项目并收到以下消息:
CMake Error at /home/hekto/apps/libigl/cmake/libigl.cmake:5 (message):
You included libigl.cmake directly from your own project. This behavior is
not supported anymore. Please add libigl to your project via
add_subdirectory(<path_to_libigl>). See the libigl example project for
more information: https://github.com/libigl/libigl-example-project/
Call Stack (most recent call first):
CMakeLists.txt:43 (find_package)
因此,他们建议对客户端项目使用
add_subdirectory
命令。我查看了推荐的 GitHub 示例项目中的 CMakeLists.txt
文件,找不到 add_subdirectory
命令:
cmake_minimum_required(VERSION 3.16)
project(example)
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Libigl
include(libigl)
# Enable the target igl::glfw
igl_include(glfw)
# Add your project files
file(GLOB SRC_FILES *.cpp)
add_executable(${PROJECT_NAME} ${SRC_FILES})
target_link_libraries(${PROJECT_NAME} PUBLIC igl::glfw)
我应该如何使用 2.4.0 的新版本
libigl
进行构建?
只是为了在评论中结束讨论 - 也许,这个答案会对某人有所帮助......
所以,最小的
CMakeLists.txt
文件(它可以帮助我编译一个简单的测试,显示“兔子”网格)如下:
cmake_minimum_required(VERSION 3.10)
project(bunny)
set(CMAKE_PREFIX_PATH $ENV{HOME}/apps/CGAL/current)
find_package(CGAL CONFIG REQUIRED)
add_subdirectory($ENV{HOME}/apps/libigl/current ${CMAKE_BINARY_DIR}/libigl)
igl_include(copyleft cgal)
igl_include(glfw)
add_executable(bunny bunny.cpp)
target_link_libraries(bunny CGAL::CGAL igl::core igl::glfw)
您可以在这里看到,
CGAL
和libigl
库都安装在我的主目录中。 CGAL
版本是6.0.1,libigl
是2.4.0。如果系统目录中有这些库,那么 CMakeLists.txt
文件会更简单。来源bunny.cpp
如下:
#include <Eigen/Dense>
#include <igl/read_triangle_mesh.h>
#include <igl/opengl/glfw/Viewer.h>
int main()
{
Eigen::MatrixXd V;
Eigen::MatrixXi F;
// ------ load a mesh
igl::read_triangle_mesh("data/bunny.off", V, F);
// ------ plot the mesh
igl::opengl::glfw::Viewer viewer;
viewer.data().set_mesh(V, F);
viewer.launch();
}
祝您好运
libigl
!