浏览代码

Fix: Wrong Eigen3 dependency when using find_package(libigl) #1100 (#1101)

* Fix #1100

When the target Eigen3::Eigen is not present but could be found using
find_package() igl::core and igl::common link against the wrong TARGET
PkgConfig::Eigen3. Fixed this and also did some code cleanup.

* Drop support for PkgConfig

* Simplify configuration code

- Removed redundant call to find_package
- Removed LIBIGL_Eigen3_Target variable
- Echo status message
Stefan Reinhold 6 年之前
父节点
当前提交
7a1e0435a8
共有 1 个文件被更改,包括 13 次插入34 次删除
  1. 13 34
      cmake/libigl-config.cmake.in

+ 13 - 34
cmake/libigl-config.cmake.in

@@ -2,50 +2,29 @@
 
 include(${CMAKE_CURRENT_LIST_DIR}/libigl-export.cmake)
 
-if (TARGET igl::core)
-  if (NOT TARGET Eigen3::Eigen)
-    find_package(Eigen3 QUIET)
-    if (NOT Eigen3_FOUND)
-      # try with PkgCOnfig
-      find_package(PkgConfig REQUIRED)
-      pkg_check_modules(Eigen3 QUIET IMPORTED_TARGET eigen3)
-    endif()
+# Check if Eigen3 target is avaiable, if not try to locate it
+# with find_package.
+message(STATUS "[libigl] Looking for Eigen3")
+if (NOT TARGET Eigen3::Eigen)
+  # Try if Eigen3 can be found with find_package
+  find_package(Eigen3 CONFIG REQUIRED)
+endif()
 
-    if (NOT Eigen3_FOUND)
-      message(FATAL_ERROR "Could not find required dependency Eigen3")
-      set(libigl_core_FOUND FALSE)
-    else()
-      set_target_properties(igl::core PROPERTIES INTERFACE_LINK_LIBRARIES PkgConfig::Eigen3)
-      set(libigl_core_FOUND TRUE)
-    endif()
-  else()
+
+if (TARGET igl::core)
+  if (TARGET Eigen3::Eigen)
+    # Inject dependency
     set_target_properties(igl::core PROPERTIES INTERFACE_LINK_LIBRARIES Eigen3::Eigen)
     set(libigl_core_FOUND TRUE)
   endif()
-
 endif()
 
 if (TARGET igl::common)
-  if (NOT TARGET Eigen3::Eigen)
-    find_package(Eigen3 QUIET)
-    if (NOT Eigen3_FOUND)
-      # try with PkgCOnfig
-      find_package(PkgConfig REQUIRED)
-      pkg_check_modules(Eigen3 QUIET IMPORTED_TARGET eigen3)
-    endif()
-
-    if (NOT Eigen3_FOUND)
-      message(FATAL_ERROR "Could not find required dependency Eigen3")
-      set(libigl_common_FOUND FALSE)
-    else()
-      set_target_properties(igl::common PROPERTIES INTERFACE_LINK_LIBRARIES PkgConfig::Eigen3)
-      set(libigl_common_FOUND TRUE)
-    endif()
-  else()
+  if (TARGET Eigen3::Eigen)
+    # Inject dependency
     set_target_properties(igl::common PROPERTIES INTERFACE_LINK_LIBRARIES Eigen3::Eigen)
     set(libigl_common_FOUND TRUE)
   endif()
-
 endif()
 
 check_required_components(libigl)