Skip to content

fix eigen include when Eigen3::Eigen is defined#10

Merged
jdumas merged 2 commits intolibigl:masterfrom
ShuangLiu1992:patch-1
Oct 18, 2019
Merged

fix eigen include when Eigen3::Eigen is defined#10
jdumas merged 2 commits intolibigl:masterfrom
ShuangLiu1992:patch-1

Conversation

@ShuangLiu1992
Copy link
Copy Markdown
Contributor

following libigl.cmake line 98~108

# Eigen
if(TARGET Eigen3::Eigen)
  # If an imported target already exists, use it
  target_link_libraries(igl_common INTERFACE Eigen3::Eigen)
else()
  igl_download_eigen()
  target_include_directories(igl_common SYSTEM INTERFACE
    $<BUILD_INTERFACE:${LIBIGL_EXTERNAL}/eigen>
    $<INSTALL_INTERFACE:include>
  )
endif()

when add libigl as a subproject by calling add_subdirectory(), if Eigen3::Eigen is already defined then libigl.cmake won't download Eigen and would only link to Eigen3::Eigen, in this case CoMiSo's eigen include would fail because ${CMAKE_CURRENT_SOURCE_DIR}/../eigen doesn't exists

following libigl.cmake line 98~108
```
# Eigen
if(TARGET Eigen3::Eigen)
  # If an imported target already exists, use it
  target_link_libraries(igl_common INTERFACE Eigen3::Eigen)
else()
  igl_download_eigen()
  target_include_directories(igl_common SYSTEM INTERFACE
    $<BUILD_INTERFACE:${LIBIGL_EXTERNAL}/eigen>
    $<INSTALL_INTERFACE:include>
  )
endif()
```

when add libigl as a subproject by calling add_subdirectory(), if Eigen3::Eigen is already defined then libigl.cmake won't download Eigen and would only link to Eigen3::Eigen, in this case CoMiSo's eigen include would fail because `${CMAKE_CURRENT_SOURCE_DIR}/../eigen` doesn't exists
@ShuangLiu1992
Copy link
Copy Markdown
Contributor Author

@jdumas could you please take a look at the PR when you have time? shouldn't break anything and it would be useful for projects that depend on libigl by invoking add_subdirectory

@jdumas
Copy link
Copy Markdown
Collaborator

jdumas commented Sep 26, 2019

Yes. I'm actually thinking that a "better" fix might be to always define a Eigen3::Eigen target in the main libigl.cmake, and then link CoMiSo to Eigen3::Eigen in all cases.

For example, the libigl.cmake part could be changed to the following:

# Eigen
if(NOT TARGET Eigen3::Eigen)
  igl_download_eigen()
  add_library(Eigen3_Eigen SYSTEM INTERFACE
    $<BUILD_INTERFACE:${LIBIGL_EXTERNAL}/eigen>
    $<INSTALL_INTERFACE:include>
  )
  add_library(Eigen3::Eigen ALIAS Eigen3_Eigen)
endif()
target_link_libraries(igl_common PUBLIC Eigen3::Eigen)

Would you mind creating a PR for that and updating this one accordingly?

ShuangLiu1992 added a commit to ShuangLiu1992/libigl that referenced this pull request Sep 27, 2019
libigl/CoMISo#10

fix Eigen include issue for CoMISo when libigl is being added as a subproject via invoking add_subdirectory, while the master project has already defined Eigen3::Eigen
@ShuangLiu1992
Copy link
Copy Markdown
Contributor Author

please take a look at this PR: libigl/libigl#1299

jdumas pushed a commit to libigl/libigl that referenced this pull request Oct 18, 2019
* Update libigl.cmake

libigl/CoMISo#10

fix Eigen include issue for CoMISo when libigl is being added as a subproject via invoking add_subdirectory, while the master project has already defined Eigen3::Eigen

* Update libigl.cmake

* Update libigl.cmake

* Update libigl.cmake
@jdumas jdumas merged commit d60aa47 into libigl:master Oct 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants