I managed to create Make Target in Eclipse and add a CMakeListst.txt to a very simple project and it worked.

Now, my next step is to use two external libraries, Boost and Eigen.

My project is in /Users/MyUser/Documents/workspace/Test The libraries are /Users/MyUser/Documents/MyLib/Libraries

Now, in the CMakeLists.txt file I try to find Boost and Eigen, which are in the libraries folder, but always the returned message is

CMake Error at CMake/TPLs/FindBoost.cmake:1126 (message): Unable to find the requested Boost libraries.

Unable to find the Boost header files. Please set BOOST_ROOT to the root directory containing Boost or BOOST_INCLUDEDIR to the directory containing Boost's headers. Call Stack (most recent call first):
CMakeLists.txt:23 (FIND_PACKAGE)

-- Configuring incomplete, errors occurred! CMake Error at /Applications/CMake 2.8-11.app/Contents/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108 (message): Could NOT find Eigen3 (missing: EIGEN3_INCLUDE_DIRS EIGEN3_VERSION_OK) (Required is at least version "2.91.0") Call Stack (most recent call first): /Applications/CMake 2.8-11.app/Contents/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315 (_FPHSA_FAILURE_MESSAGE) CMake/TPLs/FindEigen3.cmake:76 (find_package_handle_standard_args) CMakeLists.txt:30 (FIND_PACKAGE)

I am new to CMake, so I must be missing some way to tell CMake to search in my library folder. How can I find the packages with CMake when building the project?

BTW I'm working under Mac OS X Mavericks.

EDIT

Reading through the file FindEigen3.cmake there should be a variable called EIGEN3_INCLUDE_DIRS that points to the include directory of Eigen, is this true?

Now, from the following message

Could NOT find Eigen3 (missing: EIGEN3_INCLUDE_DIRS EIGEN3_VERSION_OK)

I would think that cmake is actually finding that directory as it says EIGEN3_VERSION_OK but then why can't cmake find the rest of the include files?

Am I still missing something? I created the environment variable within Eclipse and then add a line to the FindEigen3.cmake to test the value of the environment variable EIGEN3_INCLUDE_DIRS

message(STATUS "Eigen version: ${EIGEN3_INCLUDE_DIRS}")

But the message I'm getting is

--Eigen version: EIGEN3_INCLUDE_DIRS-NOTFOUND

Any advise?

EDIT

I tried with the question-related answers but none was able to make Eclipse+CMake find Boost and Eigen libraries. I guess the problem here is how to make Eclipse recognize the system variables.

有帮助吗?

解决方案

When you do not believe in setting environment variables in Eclipse, you can pass Cmake-defines either directly to cmake command:

cmake -E chdir Release/ cmake -G "Unix Makefiles" ... -DBOOST_ROOT:PATHNAME=boost/install/dir ...

or define them in your CMakeLists.txt before find boost/eigen3

SET(BOOST_ROOT boost/install/dir)
...
FIND_PACKAGE(BOOST ... )

or use environment variables within your OS/shell. You must define them before launching the Eclipse. E.g. from bash, do

export BOOST_ROOT=boost/install/dir
eclipse

Note that you have to define all variables needed for both boost and eigen3. You can place some debugging messages in your CMakeLists.txt to confirm that you pass them correctly:

MESSAGE("Boost root: ${BOOST_ROOT}")
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top