python - Swig -outdir option doesn't include the .so file -
i have small project use cmake system create python module out of c++ files. in cmakelists.txt file have swig integrated follows:
# swig part here find_package(swig required) include(${swig_use_file}) find_package(pythonlibs) include_directories(${python_include_path}) set(cmake_swig_outdir ${project_binary_dir}/../lib/foo) set_source_files_properties(swig/interface.i properties cplusplus on) set_source_files_properties(swig/interface.i swig_flags "-includeall;-c++;-shadow") swig_add_module(foo python swig/interface.i code/foo.cpp) swig_link_libraries(foo foolib ${python_libraries})
my first question why not both foo.py and _foo.so created in location specified cmake_swig_outdir
? .py file created in directory. bug of cmake useswig.cmake file? .so file still in project_binary_dir
location. result, can't load module in python if location cmake_swig_outdir
in python_path
environment variable. solve problem either:
- add
project_binary_dir
directorypython_path
. - copy .so file
cmake_swig_outdir
or create symbolic link using cmake system. - don't set
cmake_swig_outdir
variable created inproject_binary_dir
, add locationpython_path
.
but none of these seem logic thing do, cmake_swig_outdir
should used output both .py , .so files. missing here?
i'm not sure why cmake_swig_outdir not affect location of .so file gets generated. however, can tell of simpler , cleaner way of indicating .so file should generated.
after swig_add_module(foo ...)
, cmake target called _foo
gets created. can edit target's properties , change library (.so file) gets generated - set_target_properties(.. library_output_directory <so_file_output_dir>)
.
so in code, add set_target_properties(..)
line shown below:
... swig_add_module(foo python swig/interface.i code/foo.cpp) set_target_properties(_foo properties library_output_directory ${cmake_swig_outdir}) swig_link_libraries(foo foolib ${python_libraries}) ...
Comments
Post a Comment