Cmake/matlab: FIND_PROGRAM 没有找到 mex 和 mexext

Cmake/matlab: FIND_PROGRAM does not find mex and mexext

我对编译东西绝对陌生,我正在尝试使用以下(减少的)内容制作 CMakeList.txt(评论是我对代码功能的解释):

FIND_PROGRAM(MEX_CMD mex)  # find programm mex and save in variable MEX_CMD
FIND_PROGRAM(MEXEXT_CMD mexext) # same for mexext

IF(MEX_CMD AND MEXEXT_CMD) # returns true if both variables exist, currently always returns false
    ...
ELSE()
MESSAGE(SEND_ERROR
    "Cannot find MATLAB or Octave instalation. Make sure that the 'bin' directory from the MATLAB instalation is in PATH"
)

由于 if 语句总是 returns FALSE 并且我收到错误消息,我想它没有找到 mex or/and mexext。我试图将包含这两个文件的目录添加到路径但没有任何效果:

INCLUDE_DIRECTORIES(/usr/local/MATLAB/R2016a/bin)

现在我没主意了。问题出在哪里?在旁注中,bash which -a mexext returns 什么都没有。我正在使用 ubuntu 16.10,cmake 3.5.2.

根据 find_program documentation 你有几种可能 "hint" CMake 关于程序的位置。

通过 CMakeLists.txt 的修改(如果您是脚本的作者):

  • PATHSHINTS 选项 find_program:

    find_program(MEX_CMD mex PATHS /usr/local/MATLAB/R2016a/bin)
    
  • 设置CMake变量CMAKE_PROGRAM_PATH:

    list(APPEND CMAKE_PROGRAM_PATH "/usr/local/MATLAB/R2016a/bin")
    
  • 设置CMake变量CMAKE_PREFIX_PATH(不带/bin后缀):

    list(APPEND CMAKE_PREFIX_PATH "/usr/local/MATLAB/R2016a")
    

未修改 of CMakeLists.txt:

  • 设置PATH环境变量(来自shell,执行cmake之前):

     export PATH=$PATH:/usr/local/MATLAB/R2016a/bin
    
  • 将 CMake 变量 CMAKE_PROGRAM_PATH 传递给 cmake:

     cmake -DCMAKE_PROGRAM_PATH=/usr/local/MATLAB/R2016a/bin <...>
    
  • 将CMake变量CMAKE_PREFIX_PATH(不带/bin后缀)传递给cmake:

     cmake -DCMAKE_PREFIX_PATH=/usr/local/MATLAB/R2016a <...>