Swig doesn't generate Python-file when called via CMake

Hi,

I want to run Swig from CMake.
My CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.22.0)
project(PyTest CXX)

find_package(SWIG 4.0 REQUIRED python)
include(UseSWIG)

set(UseSWIG_MODULE_VERSION 1)
set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_LIST_DIR}/bin)
set(SWIG_OUTFILE_DIR ${CMAKE_CURRENT_LIST_DIR}/bin)
set(SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE)
set (UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
find_package(Python3 REQUIRED COMPONENTS Development)

#set(CMAKE_SWIG_FLAGS "")

swig_add_library(test TYPE SHARED LANGUAGE python SOURCES test.i)
set_target_properties(test PROPERTIES LINKER_LANGUAGE CXX)

target_link_libraries(test PRIVATE Python3::Module)

When I run this, a _test.so file is created in my build-folder.
However, it doesn’t create the desired bin-folders, it doesn’t generate a python-file and it doesn’t throw an error.

I have already tried to debug the UseSWIG.cmake file. What else can I do? Is Swig still supported by CMake or is it suggested to use a custom script for this purpose?

Thanks
oz

Why do you need a .py file? Can you import _test directly? Or is SWIG expected to also generate some Python-ic interface on top of its generated glue (I’m not that familiar with SWIG myself)?

I am not able to reproduce your problem.

Are you sure there are no files generated under your bin directory, which is inside your source file tree? If you want to generate files in your build folder, use “${CMAKE_CURRENT_BINARY_DIR}” rather than “${CMAKE_CURRENT_LIST_DIR}”.