UseSWIG: fails to run with USE_SWIG_DEPENDENCIES when using custom OUTFILE_DIR
Given
cmake_minimum_required(VERSION 3.22)
project(Foo)
find_package(SWIG REQUIRED)
include(UseSWIG)
find_package(Python REQUIRED Development)
set(SWIG_USE_SWIG_DEPENDENCIES TRUE)
file(WRITE foo.i [[
%module foo
]])
swig_add_library(Foo
LANGUAGE
Python
TYPE
MODULE
OUTFILE_DIR
${CMAKE_CURRENT_BINARY_DIR}
SOURCES
foo.i
)
target_link_libraries(Foo PRIVATE Python::Python)
I wanted to try out the new implicit dependency support for SWIG in CMake 3.22 with Visual Studio 2019. Trying to build the above project results in e.g.:
2>Swig compile foo.i for python
2>Unable to open file C:/Users/n.gladitz/Desktop/repo-build/CMakeFiles/Foo.dir/foo.i.d: No such file or directory
The issue seems to be that the output directory (CMakeFiles/Foo.dir
) for the dependency file is not implicitly created.
Manually creating the output directory works around the issue.
Edited by Brad King