Commit ab59804b authored by AlQuemist's avatar AlQuemist Committed by Wuttke, Joachim
Browse files

SWIG: Copy the Python library files to a dedicated folder [Windows]

On Windows, the location of the produced library depends on the build
configuration; hence, for the correct functioning of the Python package,
the library and its Python wrapper must be copied into a dedicated folder.
parent 76f9ea39
......@@ -7,7 +7,8 @@ if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Cla
add_compile_options(-Wno-unused-parameter;-Wno-deprecated-declarations;-Wno-sometimes-uninitialized;-Wno-missing-field-initializers)
endif()
set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR})
set(CMAKE_SWIG_OUTDIR "${CMAKE_CURRENT_BINARY_DIR}")
message(STATUS "SWIG: output dir = '${CMAKE_SWIG_OUTDIR}'")
include_directories(${CMAKE_SOURCE_DIR})
include_directories(${Python3_INCLUDE_DIRS} ${Python3_NumPy_INCLUDE_DIRS})
......@@ -27,6 +28,47 @@ set_property(SOURCE pyohkl.i PROPERTY SWIG_FLAGS ${PYOHKL_SWIG_INCLUDE_DIRECTORI
swig_add_library(pyohkl TYPE MODULE LANGUAGE python SOURCES pyohkl.i)
swig_link_libraries(pyohkl ${Python3_LIBRARIES} openhklcore)
swig_link_libraries(pyohkl openhklcore ${Python3_LIBRARIES})
configure_file("${CMAKE_SOURCE_DIR}/swig/pypackage/__init__.py.in" "${CMAKE_BINARY_DIR}/swig/__init__.py" @ONLY)
if(WIN32)
# On Windows, the location of the produced library depends
# on the build configuration; hence, for the correct functioning of
# the Python package, the library and its Python wrapper must be
# copied into a dedicated folder.
# output directory for the Python package
set(WIN_PYPACK_OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/pyohkl")
file(MAKE_DIRECTORY "${WIN_PYPACK_OUTDIR}")
# Package init file
configure_file("${CMAKE_SOURCE_DIR}/swig/pypackage/__init__.py.in"
"${WIN_PYPACK_OUTDIR}/__init__.py" @ONLY)
message(STATUS "SWIG: Package output dir = '${WIN_PYPACK_OUTDIR}'")
# shared library
set(pylib_file "$<TARGET_FILE_NAME:pyohkl>")
set(pylib_org "$<TARGET_FILE_DIR:pyohkl>/${pylib_file}")
set(pylib_dst "${WIN_PYPACK_OUTDIR}/${pylib_file}")
# Python wrapper
set(pywrap_file "pyohkl.py")
set(pywrap_org "${CMAKE_SWIG_OUTDIR}/${pywrap_file}")
set(pywrap_dst "${WIN_PYPACK_OUTDIR}/${pywrap_file}")
add_custom_command(
TARGET pyohkl
POST_BUILD
# copy the shared library (.pyd)
COMMAND ${CMAKE_COMMAND} -E copy "${pylib_org}" "${pylib_dst}"
COMMAND ${CMAKE_COMMAND} -E echo
"-- [Windows] SWIG: Copied shared library '${pylib_org}' => '${pylib_dst}'"
# copy the Python wrapper (.py)
COMMAND ${CMAKE_COMMAND} -E copy "${pywrap_org}" "${pywrap_dst}"
COMMAND ${CMAKE_COMMAND} -E echo
"-- [Windows] SWIG: Copied Python wrapper '${pywrap_org}' => '${pywrap_dst}'")
else()
# Python wrapper
configure_file("${CMAKE_SOURCE_DIR}/swig/pypackage/__init__.py.in"
"${CMAKE_SWIG_OUTDIR}/__init__.py" @ONLY)
endif(WIN32)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment