Skip to content
This repository has been archived by the owner on Jun 10, 2021. It is now read-only.

Commit

Permalink
Do not search Eigen system-wide if EIGEN3_ROOT is set
Browse files Browse the repository at this point in the history
Fixes #25.
  • Loading branch information
guillaumekln committed Sep 28, 2017
1 parent 2aa2b53 commit 195d560
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
if (EIGEN_ROOT)
set(ENV{EIGEN3_ROOT} ${EIGEN_ROOT})
endif()
if (EIGEN3_ROOT)
set(ENV{EIGEN3_ROOT} ${EIGEN3_ROOT})
endif()

find_package(Eigen3 3.3 REQUIRED)
if(WITH_CUDA)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ CTranslate also bundles OpenNMT's [Tokenizer](https://github.com/OpenNMT/Tokeniz

### Options

* To give hints about Eigen location, use the `-DEIGEN_ROOT=<path to Eigen library>` option.
* To give hints about Eigen location, use the `-DEIGEN3_ROOT=<path to Eigen library>` option.
* To compile only the library, use the `-DLIB_ONLY=ON` flag.
* To disable [OpenMP](http://www.openmp.org), use the `-DWITH_OPENMP=OFF` flag.

Expand Down
35 changes: 21 additions & 14 deletions cmake/FindEigen3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,37 @@ macro(_eigen3_check_version)
endif(NOT EIGEN3_VERSION_OK)
endmacro(_eigen3_check_version)

if (EIGEN3_INCLUDE_DIR)

# in cache already
_eigen3_check_version()
set(EIGEN3_FOUND ${EIGEN3_VERSION_OK})

else (EIGEN3_INCLUDE_DIR)

# search first if an Eigen3Config.cmake is available in the system,
# if successful this would set EIGEN3_INCLUDE_DIR and the rest of
# the script will work as usual
find_package(Eigen3 ${Eigen3_FIND_VERSION} NO_MODULE QUIET)

macro(_search_eigen3)
if(NOT EIGEN3_INCLUDE_DIR)
find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
HINTS
ENV EIGEN3_ROOT
ENV EIGEN3_ROOT
ENV EIGEN3_ROOT_DIR
PATHS
${CMAKE_INSTALL_PREFIX}/include
${KDE4_INCLUDE_DIR}
PATH_SUFFIXES eigen3 eigen
)
endif(NOT EIGEN3_INCLUDE_DIR)
endmacro(_search_eigen3)

if (EIGEN3_INCLUDE_DIR)

# in cache already
_eigen3_check_version()
set(EIGEN3_FOUND ${EIGEN3_VERSION_OK})

else (EIGEN3_INCLUDE_DIR)

if(DEFINED ENV{EIGEN3_ROOT})
_search_eigen3()
else()
# search if an Eigen3Config.cmake is available in the system,
# if successful this would set EIGEN3_INCLUDE_DIR and the rest of
# the script will work as usual
find_package(Eigen3 ${Eigen3_FIND_VERSION} NO_MODULE QUIET)
_search_eigen3()
endif()

if(EIGEN3_INCLUDE_DIR)
_eigen3_check_version()
Expand Down

0 comments on commit 195d560

Please sign in to comment.