TopicCMakeGuide.dox 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. namespace Eigen {
  2. /**
  3. \page TopicCMakeGuide Using %Eigen in CMake Projects
  4. %Eigen provides native CMake support which allows the library to be easily
  5. used in CMake projects.
  6. \note %CMake 3.0 (or later) is required to enable this functionality.
  7. %Eigen exports a CMake target called `Eigen3::Eigen` which can be imported
  8. using the `find_package` CMake command and used by calling
  9. `target_link_libraries` as in the following example:
  10. \code{.cmake}
  11. cmake_minimum_required (VERSION 3.0)
  12. project (myproject)
  13. find_package (Eigen3 3.3 REQUIRED NO_MODULE)
  14. add_executable (example example.cpp)
  15. target_link_libraries (example Eigen3::Eigen)
  16. \endcode
  17. The above code snippet must be placed in a file called `CMakeLists.txt` alongside
  18. `example.cpp`. After running
  19. \code{.sh}
  20. $ cmake path-to-example-directory
  21. \endcode
  22. CMake will produce project files that generate an executable called `example`
  23. which requires at least version 3.3 of %Eigen. Here, `path-to-example-directory`
  24. is the path to the directory that contains both `CMakeLists.txt` and
  25. `example.cpp`.
  26. If you have multiple installed version of %Eigen, you can pick your favorite one by setting the \c Eigen3_DIR cmake's variable to the respective path containing the \c Eigen3*.cmake files. For instance:
  27. \code
  28. cmake path-to-example-directory -DEigen3_DIR=$HOME/mypackages/share/eigen3/cmake/
  29. \endcode
  30. If the `REQUIRED` option is omitted when locating %Eigen using
  31. `find_package`, one can check whether the package was found as follows:
  32. \code{.cmake}
  33. find_package (Eigen3 3.3 NO_MODULE)
  34. if (TARGET Eigen3::Eigen)
  35. # Use the imported target
  36. endif (TARGET Eigen3::Eigen)
  37. \endcode
  38. */
  39. }