I'm working on a C++ project where I'm already using the Eigen library.
I now want to add library that will allow me to build a surface mesh. I thought about CGAL but it seems to be too heavy and complex for what I need. So I found Polygon Mesh Processing Library or PMP, that will probably do the job just fine.
The problem with the PMP is that it already depends on Eigen (see here).
So when I changed my root CMakeLists.txt
to:
# Add Eigen using CPM
CPMAddPackage(
NAME Eigen
GITLAB_REPOSITORY libeigen/eigen
GIT_TAG 3.4
OPTIONS
"EIGEN_BUILD_DOC OFF" # Do not build documentation
"EIGEN_BUILD_PKGCONFIG OFF" # Optional, disables pkg-config
"BUILD_TESTING OFF" # Disable building and running tests
)
# Add PMP library using CPM
CPMAddPackage(
NAME PMP
GITHUB_REPOSITORY pmp-library/pmp-library
GIT_TAG 3.0.0 # Specify the version you need, or leave it out for the latest
)
I got an error
CMake Error at cmake-build-debug/_deps/pmp-src/examples/CMakeLists.txt:16 (add_executable):
add_executable cannot create target "eigen" because another target with the
same name already exists. The existing target is an interface library
created in source directory.
See documentation for policy CMP0002 for more details.
I'm obviously no CMake expert. Is there a solution to this? Can I convince PMP to use my instance of Eigen? Do I have to find a different meshing library, one independant of Eigen?
As suggested by Botje, I fixed my Cmake to:
# Add Eigen using CPM
CPMAddPackage(
NAME Eigen
GITLAB_REPOSITORY libeigen/eigen
GIT_TAG 3.4.0
OPTIONS
"EIGEN_BUILD_DOC OFF" # Do not build documentation
"EIGEN_BUILD_PKGCONFIG OFF" # Optional, disables pkg-config
"BUILD_TESTING OFF" # Disable building and running tests
)
# Add PMP library using CPM
# Set EIGEN3_INCLUDE_DIR if it is not already defined
message("${Eigen_SOURCE_DIR}/Eigen")
if (NOT DEFINED EIGEN3_INCLUDE_DIR)
set(EIGEN3_INCLUDE_DIR "${Eigen_SOURCE_DIR}/Eigen")
endif()
find_package(Eigen 3.4.0 REQUIRED)
CPMAddPackage(
NAME PMP
GITHUB_REPOSITORY pmp-library/pmp-library
GIT_TAG 3.0.0 # Specify the version you need, or leave it out for the latest
)
This is for sure a step forward, but I get a new error regarding the paths:
C:/Users/.../cmake-build-debug/_deps/eigen-src/Eigen
-- CPM: Adding package PMP@3.0.0 (3.0.0)
-- Using Win32 for window creation
CMake Error at cmake-build-debug/_deps/pmp-src/cmake/FindEigen3.cmake:39 (file):
file failed to open for reading (No such file or directory):
C:/Users/.../cmake-build-debug/_deps/eigen-src/Eigen/Eigen/src/Core/util/Macros.h
C:/Users/.../cmake-build-debug/_deps/eigen-src/Eigen/**Eigen**/src/Core/util/Macros.h
is indeed wrong. I don't know why the Eigen is repeated twice in the path eigen-src/Eigen/Eigen
.The CMakeLists.txt for pmp-library contains this snippet:
if(NOT DEFINED EIGEN3_INCLUDE_DIR)
set(EIGEN3_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/external/eigen-3.4.0")
endif()
find_package(Eigen3 3.4.0 REQUIRED)
If you set this variable in your CPMAddPackage
call, pmp-library will use your copy of eigen instead of shipping its own.
The other error stems from PMP defining an eigen
target as part of its example suite. You can set PMP_BUILD_EXAMPLES
to NO
to fix that.
The final error is due to PMP v3.0.0 setting GLFW_SOURCE_DIR
to override a variable that GLFW uses internally. In the main branch you will see it actually defines GLFW_SOURCE_DIR_INTERNAL
to avoid conflicting.