My CMakeLists.txt
file for my old libigl
testing project contains the piece below:
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()
I tried to build this project with the new version 2.4.0 of the libigl
library and got this message:
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)
So, they recommend to use the add_subdirectory
command for client projects. I looked at the CMakeLists.txt
file from the recommended GitHub example project and couldn't find the add_subdirectory
command:
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)
How should I build with the new version 2.4.0 of the libigl
?
Just to wrap up the discussion in comments - may be, this answer will help somebody...
So, the minimal CMakeLists.txt
file, which worked for me to compile a simple test, showing the "bunny" mesh, is below:
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(${PROJECT_NAME} ${PROJECT_NAME}.cpp)
target_link_libraries(${PROJECT_NAME} CGAL::CGAL igl::core igl::glfw)
You can see here, that both CGAL
and libigl
libraries are installed in my home directory. The CGAL
version is 6.0.1, the libigl
is 2.4.0. If you have these libraries in system directories, then the CMakeLists.txt
file will be even simpler. The source bunny.cpp
is below:
#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();
}
Good luck with the libigl
!