CMake Error: Could NOT find SWIG (missing: SWIG_DIR)

MysteryPancake picture MysteryPancake · Jan 22, 2018 · Viewed 12.5k times · Source

I wanted to test out Pocketsphinx in Node.JS. It says I need to install Swig version 3.0.7 or above.

I think I installed all the other dependencies correctly. I can even type Swig commands in the Terminal now, but I keep getting this error whenever I run npm install pocketsphinx:

CMake Error at /usr/local/Cellar/cmake/3.6.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
  Could NOT find SWIG (missing: SWIG_DIR) (Required is at least version
  "3.0.7")
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.6.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/Cellar/cmake/3.6.3/share/cmake/Modules/FindSWIG.cmake:75 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:4 (find_package)

I tried brew install swig, npm install swig, and npm install -g swig. I tried going to the swig download page and following the installation instructions, but nothing I seem to do stops the error from happening. I'm trying this on a Macbook by the way.

I really have no clue what I'm doing here. I just wanted to test out Pocketsphinx and now I've installed Swig in 4 different places, and CMake can't seem to recognise any of them.

Any help would be wonderful!

Answer

ComicSansMS picture ComicSansMS · Jan 23, 2018

Check the source code for the FindSwig.cmake.

Unfortunately, if a find script does not work as expected and you do not see right away why that is the case, you usually have to dig into its source. In your case, it looks like CMake was able to find and run the SWIG executable, but then failed to obtain the swig directory.

Try manually running swig -swiglib and check that the printed directory indeed contains a swig.swg file. Also, be sure that the swig executable found by CMake is actually the correct one (you can verify this by inspecting the value of SWIG_EXECUTABLE in either the cmake-gui, the ccmake curses interface, or in the CMakeCache.txt file directly).

Note that CMake will not update the executable path once it has been found! So if you make changes to your system that influence the executable location, you will have to clear the cache (eg. by deleting the CMakeCache.txt) and re-run CMake for the changes to take effect.