cmake-basis / BASIS

CMake BASIS makes it easy to create sharable software and libraries that work together. This is accomplished by combining and documenting some of the best practices and utilities available. This project supplies a fully integrated suite of functionality to make the whole process seamless!
https://cmake-basis.github.io
Other
48 stars 10 forks source link

DEPENDS_MATLAB_DIR problem (perhaps backward compatibility issue) #617

Closed kayhan-batmanghelich closed 7 years ago

kayhan-batmanghelich commented 7 years ago

Hi Andreas,

I hope you are doing well.

I have recently moved some of my older code to a new server but couldn't compile it. The project needs to use mcc. I get this error:

 CMake Error at /pylon2/ms4s88p/batmangh/installed/basis/share/modules/CommonTools.cmake:840 (message):

   Project CgGi requires MATLAB.  Please ensure that the package is installed
   in a standard system location or set DEPENDS_MATLAB_DIR to the installation
   prefix (i.e., root directory of the installation).

   The DEPENDS_MATLAB_DIR variable can alternatively be set to the directory
   containing a MATLABConfig.cmake or matlab-config.cmake file.  If no such
   file exists, contact either the developer of this project or CMake BASIS to
   provide a FindMATLAB.cmake file.

 Call Stack (most recent call first):
   /pylon2/ms4s88p/batmangh/installed/basis/share/modules/ProjectTools.cmake:2139 (basis_find_package)
   /pylon2/ms4s88p/batmangh/installed/basis/share/modules/ProjectTools.cmake:2433 (basis_find_packages)
   /pylon2/ms4s88p/batmangh/installed/basis/share/modules/ProjectTools.cmake:2707 (basis_project_begin)
   CMakeLists.txt:48 (basis_project_impl)

It complains about MATLAB. In the ccmake it shows:

 DEPENDS_MATLAB_DIR              *NOTFOUND

I noticed that in the install folder, FindMATLAB.cmake is in ./share/find-modules/FindMATLAB.cmake while in the previous version it was in the ./share/cmake-modules/FindMATLAB.cmake before. Is that the reason?

Thanks, Kayhan

schuhschuh commented 7 years ago

Hey Kayhan,

what coincidence. I've just had some troubles with this myself just minutes ago... Seems you're on the right track, I didn't think of this yet. But indeed, when you look at your ./lib/cmake/basis/BASISConfig.cmake file, you find the FIND_MODULES_PATH which is indeed incorrect. You could edit this file after installation of BASIS and see if that helps.

Let me know, Andreas

kayhan-batmanghelich commented 7 years ago

Hey Andreas,

This is the fastest reply I got on git issue :) this is what I did, I copied FindMATLAB.cmake to the config folder of my project. It passed that point and now it is complaining about ITK. My ITK installation is not done. If I installed it and it still complains, I will let you know.

Best, K

kayhan-batmanghelich commented 7 years ago

It turned out that it is an issue with every module in the find-module folder. You need to bring them all in.

schuhschuh commented 7 years ago

Yes, instead it's better you edit your BASISConfig.cmake file or try with the new master branch.

kayhan-batmanghelich commented 7 years ago

Nope, I pulled the new master branch, reinstalled the basis, removed the build folder in my project and I still have the same issue.

I still get this:

CMake Error at /pylon2/ms4s88p/batmangh/installed/basis/share/modules/CommonTools.cmake:840 (message):

   Project CgGi requires MATLAB.  Please ensure that the package is installed
   in a standard system location or set DEPENDS_MATLAB_DIR to the installation
   prefix (i.e., root directory of the installation).

   The DEPENDS_MATLAB_DIR variable can alternatively be set to the directory
   containing a MATLABConfig.cmake or matlab-config.cmake file.  If no such
   file exists, contact either the developer of this project or CMake BASIS to
   provide a FindMATLAB.cmake file.

 Call Stack (most recent call first):
   /pylon2/ms4s88p/batmangh/installed/basis/share/modules/ProjectTools.cmake:2139 (basis_find_package)
   /pylon2/ms4s88p/batmangh/installed/basis/share/modules/ProjectTools.cmake:2433 (basis_find_packages)
   /pylon2/ms4s88p/batmangh/installed/basis/share/modules/ProjectTools.cmake:2707 (basis_project_begin)
   CMakeLists.txt:48 (basis_project_impl)
schuhschuh commented 7 years ago

Too bad, it looked like this change had fixed it on my end.

First of all, does it work after you set DEPENDS_MATLAB_DIR to the correct path or when you set the MATLABDIR environment variable before running CMake? Or does it reset DEPENDS_MATLAB_DIR each time you edited it in the GUI and run the configure step again?

The FindMATLAB module should be fine finding the MATLAB executables (matlab, mcc, mex, mexext) when you set DEPENDS_MATLAB_DIR to the directory containing these binaries. With PR #619 which I just committed it should also be enough if you add the bin/ directory of your MATLAB installation to the PATH environment variable. This previously would only work if you use DEPENDS MATLAB or DEPENDS MATLAB{matlab} in your BasisProject.cmake file, i.e., when the matlab executable is declared as dependency. With the change of FindMATLAB today, it will also work if you just specify MATLAB{mcc} as dependency of your project (or mex...).

On a side note, you mentioned you require the MATLAB compiler (mcc). You could thus be more specific in your BasisProject.cmake what components of MATLAB you require in your project instead of just MATLAB. For example, in a project of mine which I used for testing the changes, I have:

basis_project(
  # ...
  DEPENDS
    MATLAB{mex,mcc}
    VTK
)

which means it requires mex to build MEX-files (that use VTK filters) and mcc to compile MATLAB code into a shared library (to use in a C++ program, e.g., to call the eigs function).

I've tested it on macOS with MATLAB 2016b and Ubuntu with MATLAB 2015a. Both worked fine.

Can you verify that your BASIS installation has the right path for Find modules?

> grep FIND_MODULE_PATH /pylon2/ms4s88p/batmangh/installed/basis/lib/cmake/basis/BASISConfig.cmake
basis_set_config (FIND_MODULE_PATH "${${NS}INSTALL_PREFIX}/share/find-modules")

And append some debug messages at the end of FindMATLAB.cmake:

> echo 'message("FindMATLAB: MATLAB_DIR=${MATLAB_DIR}, MATLAB_FOUND=${MATLAB_FOUND}")' >> /pylon2/ms4s88p/batmangh/installed/basis/share/find-modules/FindMATLAB.cmake

Next you can check some MATLAB related entries in your CMake cache of the project you are tring to build:

> cd $build_directory_of_your_project
> grep MATLAB_DIR CMakeCache.txt

This should show a number of variables, all set to the same path:

On macOS, it's for example /Applications/MATLAB_R2016b.app.

kayhan-batmanghelich commented 7 years ago

Hi Andreas,

I finally have time to get back to this. You are right a clean install works.

Thank you,

schuhschuh commented 7 years ago

Glad it works. Closing the ticket then.