CMake Error: Could NOT find SWIG (missing: SWIG_DIR)
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.
Came here looking for the Windows-based error. I found a solution that seems to work for me, so decided to post it here.
- Create two environment variables in the "System Variables" section:
SWIG_DIR
andSWIG_EXECUTABLE
. These must point to/path/to/the/swig/dir/
and/path/to/the/swig/dir/swig.exe
respectively. - After this, add one more entry to the PATH variable:
/path/to/the/swig/dir
. Test this out by typingswig
in the command prompt. It should display a messagemust specify an input file. Use -help for available options
. - Restart the computer to apply all environment variable changes.
find_package(SWIG required)
should work correctly now.