Commit f06e53c5 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

Merge branch 'winCI' into 'main'

Build and test the SWIG-Produced Python interface on Windows

See merge request !473
parents ef7d3bf0 1f39d569
Pipeline #72302 passed with stage
in 1 minute and 10 seconds
......@@ -6,15 +6,25 @@ stages:
# - Windows
# stage: build
# script:
# - New-Item -ItemType "directory" -Confirm:$false -Force:$true -Name "build"
# - cd build
# - cmd.exe "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
# - cmake -G "Visual Studio 16 2019" -A x64 -T host=x64 -DLIB_MAN=OFF -DLIB_INSTALL=OFF -B. ..
# - cmake --build . --config Release
# - Get-Location
# - dir
# - dir Release
# - ctest -C Release --output-on-failure
# - mkdir -Force build
# - cd build
# - $OPT_DIR = "C:/Users/scguser/vcpkg/installed/x64-windows;C:/opt/x64"
# - $QT_MSVC_DIR = "C:/Qt/msvc"
# - $QTCMake_DIR = "$QT_MSVC_DIR/lib/cmake"
# - $QTDIR = "$QT_MSVC_DIR"
# - $BOOST_DIR = "$OPT_DIR/boost_current"
# - $BOOST_INCLUDE_DIR = "$BOOST_DIR/include"
# - $LIB_DIRS = "C:/Program Files/HDF_Group/HDF5/1.12.2/lib;C:/opt/x64/lib"
# - $INCLUDE_DIRS = "C:/Program Files/HDF_Group/HDF5/1.12.2/include;C:/opt/x64/include/libtiff;${BOOST_INCLUDE_DIR}"
# - $SWIG_DIR = "C:/Program Files/swigwin"
# - cmake -G "Visual Studio 17 2022" -A x64 -T host=x64 -DCMAKE_PREFIX_PATH="$OPT_DIR" -DQTDIR="$QT_MSVC_DIR" -DCMAKE_INCLUDE_PATH="$INCLUDE_DIRS" -DCMAKE_LIBRARY_PATH="$LIB_DIRS" -DCMAKE_C_COMPILER="cl.exe" -DBUILD_DOCUMENTATION=OFF -DBUILD_PDF_DOCUMENTATION=OFF -DCMAKE_CXX_COMPILER="cl.exe" -B. ..
# - cmake --build . --config Release
# - ctest -C Release --parallel 8 --output-on-failure
# - cpack -C Release -B ./winpackage
# artifacts:
# paths:
# - build/OpenHKL*.exe
# expire_in: 10 days
mac10_15:
tags:
......
......@@ -206,7 +206,7 @@ if(OHKL_PYTHON AND NOT MSVC AND BUILD_TESTING)
list(APPEND allsources ${sources})
endforeach()
add_test(NAME "CodeLineLength"
COMMAND ${PYTHON_EXECUTABLE}
COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/devtools/check-line-length.py 200 ${allsources})
endif()
......@@ -272,7 +272,7 @@ endif()
if (APPLE)
install(TARGETS OpenHKL DESTINATION .)
elseif(WIN32)
# TODO
install(TARGETS OpenHKL DESTINATION .)
else()
set_property(TARGET OpenHKL PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
......
......@@ -35,47 +35,37 @@ if(HDF5_INCLUDE_DIRS AND HDF5_LIBRARIES)
message(" versions: ${HDF5_VERSION}")
message(" libraries: ${HDF5_LIBRARIES}")
message(" headers: ${HDF5_INCLUDE_DIRS}")
message(" CXX path: ${HDF5_LIB_PATH}")
message(" CXX library: ${HDF5_CXX_LIBRARY_hdf5_cpp}")
else()
message(FATAL_ERROR "HDF5 not found")
endif()
###### Find Python
if(OHKL_PYTHON)
# python-dev and interpreter
set(Python_ADDITIONAL_VERSIONS 3.7 3.6 3.5 3.4)
find_package(PythonInterp 3)
find_package(PythonLibs 3)
execute_process (
COMMAND ${PYTHON_EXECUTABLE} -c "from __future__ import print_function; import numpy; print(numpy.get_include())"
ERROR_VARIABLE NUMPY_FIND_ERROR
RESULT_VARIABLE NUMPY_FIND_RESULT
OUTPUT_VARIABLE NUMPY_FIND_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
## process the output from the execution of the command
if(NOT NUMPY_FIND_RESULT)
set (NUMPY_INCLUDES ${NUMPY_FIND_OUTPUT})
message(STATUS "numpy includes ${NUMPY_INCLUDES}")
include_directories(SYSTEM ${NUMPY_INCLUDES})
else()
message(FATAL_ERROR "Could NOT find numpy headers")
set(pyver_min 3.9)
find_package(Python3 ${pyver_min} QUIET
COMPONENTS Interpreter Development NumPy)
if(NOT Python3_FOUND)
message(FATAL_ERROR
"Python 3 not found (minimum version ${pyver_min}).")
endif()
# Python packages dir
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c
"from distutils import sysconfig as sc; print(sc.get_python_lib(prefix='', plat_specific=True))"
RESULT_VARIABLE PYTHON_SITE_RESULT
OUTPUT_VARIABLE PYTHON_SITE
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(PYTHON_SITE_RESULT)
message(FATAL_ERROR "Failed running PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} to determine"
" Python package directory; output = '${PYTHON_SITE}'")
endif()
message(STATUS "Python package destination is ${PYTHON_SITE}")
message(STATUS " Python3_VERSION: ${Python3_VERSION}")
message(STATUS " Python3_VERSION_MINOR: ${Python3_VERSION_MINOR}")
message(STATUS " Python3_VERSION_PATCH: ${Python3_VERSION_PATCH}")
message(STATUS " Python3_INTERPRETER_ID: ${Python3_INTERPRETER_ID}")
message(STATUS " Python3_EXECUTABLE: ${Python3_EXECUTABLE}")
message(STATUS " Python3_STDLIB: ${Python3_STDLIB}")
message(STATUS " Python3_SITELIB: ${Python3_SITELIB}")
message(STATUS " Python3_INCLUDE_DIRS: ${Python3_INCLUDE_DIRS}")
message(STATUS " Python3_LIBRARIES: ${Python3_LIBRARIES}")
message(STATUS " Python3_LIBRARY_RELEASE: ${Python3_LIBRARY_RELEASE}")
if(WIN32)
message(STATUS " Python3_LIBRARY_DLL: ${Python3_LIBRARY_DLL}")
endif(WIN32)
message(STATUS " Python3_LIBRARY_DIRS: ${Python3_LIBRARY_DIRS}")
message(STATUS " Python3_NumPy_VERSION: ${Python3_NumPy_VERSION}")
message(STATUS " Python3_NumPy_INCLUDE_DIRS: ${Python3_NumPy_INCLUDE_DIRS}")
# swig
find_package(SWIG REQUIRED)
......@@ -107,3 +97,21 @@ include_directories(SYSTEM ${EIGEN3_INCLUDE_DIR})
##### Find QHull
find_package(Qhull MODULE REQUIRED)
include_directories(SYSTEM ${QHULL_INCLUDE_DIR})
##### Find Boost
set(Boost_NO_BOOST_CMAKE ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
add_definitions(-DBOOST_ALL_DYN_LINK) # line is needed for MSVC
add_definitions(-DBOOST_UUID_FORCE_AUTO_LINK) # line is needed to link bcrypt for MSVC
# amends problems with bimap and MSVC, serialization of bimap is currently not needed
add_definitions(-DBOOST_BIMAP_DISABLE_SERIALIZATION)
find_package(Boost 1.65.1 REQUIRED)
if(Boost_FOUND)
include_directories(SYSTEM "${Boost_INCLUDE_DIRS}")
message(STATUS "Found boost:")
message(STATUS " version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}")
message(STATUS " libraries: ${Boost_LIBRARIES}")
message(STATUS " headers: ${Boost_INCLUDE_DIRS}")
endif()
......@@ -45,7 +45,7 @@ foreach(comp ${QtComponents})
install(FILES ${dll} DESTINATION bin)
endforeach()
set(QTDIR "C:/Qt/5.15.2/msvc2019_64")
#set(QTDIR "C:/Qt/5.15.2/msvc2019_64")
install(FILES ${QTDIR}/plugins/platforms/qwindows.dll DESTINATION bin/platforms)
install(FILES ${QTDIR}/plugins/iconengines/qsvgicon.dll DESTINATION bin/iconengines)
......
#!/usr/bin/env python
#!/usr/bin/env python3
"""
......
#*** Powershell Build Script ***
# This script is only intended for debugging purposes on MS-Windows platform.
# execute under windows:
# $ powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -f <build-script>
# build a particular MSBuild project:
# $ msbuild BornAgainBase.vcxproj [-target:BornAgainBase] -property:Configuration=Release
# set minimal path for build
$Env:PATH = "C:\Qt\msvc\bin;C:\Program Files\Python39\Scripts\;C:\Program Files\Python39\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\opt\x64\include;C:\Program Files\CMake\bin;C:\opt\x64\boost_current\lib;C:\Program Files (x86)\NSIS;C:\Program Files\Ninja;C:\msys64\mingw64\bin;C:\Program Files\HDF_Group\HDF5\1.12.2\bin\;C:\Program Files\swigwin"
$OPT_DIR = "C:/opt/x64"
$QT_MSVC_DIR = "C:/Qt/msvc"
$QTCMake_DIR = "$QT_MSVC_DIR/lib/cmake"
$QTDIR = "$QT_MSVC_DIR"
$BOOST_DIR = "$OPT_DIR/boost_current"
$BOOST_INCLUDE_DIR = "$BOOST_DIR/include"
$HDF5_INCLUDE_DIR = "C:/Program Files/HDF_Group/HDF5/1.12.2/include"
$HDF5_LIB_DIR = "C:/Program Files/HDF_Group/HDF5/1.12.2/lib"
$INCLUDE_DIRS = "C:/opt/x64/include;$BOOST_INCLUDE_DIR;$HDF5_INCLUDE_DIR"
$LIB_DIRS = "C:/opt/x64/lib;$HDF5_LIB_DIR"
$SWIG_DIR = "C:/Program Files/swigwin"
mkdir build
cd build
cmake -G "Visual Studio 17 2022" -A x64 -T host=x64 -B . -S .. `
-DCMAKE_PREFIX_PATH="$OPT_DIR" -DQTDIR="$QT_MSVC_DIR" -DCMAKE_INCLUDE_PATH="$INCLUDE_DIRS" -DCMAKE_LIBRARY_PATH="$LIB_DIRS" -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" `
-DBUILD_DOCUMENTATION=OFF -DBUILD_PDF_DOCUMENTATION=OFF `
-DTIFF_INCLUDE_DIR="C:/opt/x64/include/libtiff" `
-DOHKL_PYTHON=ON `
# cmake --build . --config Release
......@@ -7,10 +7,11 @@ 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(${PYTHON_INCLUDE_DIRS})
include_directories(${Python3_INCLUDE_DIRS} ${Python3_NumPy_INCLUDE_DIRS})
set_property(SOURCE pyohkl.i PROPERTY CPLUSPLUS ON)
set_property(SOURCE pyohkl.i PROPERTY SWIG_MODULE_NAME pyohkl)
......@@ -22,10 +23,52 @@ set(PYOHKL_SWIG_INCLUDE_DIRECTORIES)
foreach(it ${PYOHKL_INCLUDE_DIRECTORIES})
set(PYOHKL_SWIG_INCLUDE_DIRECTORIES ${PYOHKL_SWIG_INCLUDE_DIRECTORIES} "-I${it}")
endforeach()
set_property(SOURCE pyohkl.i PROPERTY SWIG_FLAGS ${PYOHKL_SWIG_INCLUDE_DIRECTORIES})
swig_add_library(pyohkl TYPE MODULE LANGUAGE python SOURCES pyohkl.i)
swig_link_libraries(pyohkl ${PYTHON_LIBRARIES} openhklcore)
swig_link_libraries(pyohkl openhklcore ${Python3_LIBRARIES})
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}")
configure_file("${CMAKE_SOURCE_DIR}/swig/pypackage/__init__.py.in" "${CMAKE_BINARY_DIR}/swig/__init__.py" @ONLY)
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)
# init file for the Python package
# init file for the testing the Python package
import sys, os
# version
version_str = "@NSXTool_VERSION_MAJOR@.@NSXTool_VERSION_MINOR@.@NSXTool_VERSION_PATCH@"
version = (@NSXTool_VERSION_MAJOR@, @NSXTool_VERSION_MINOR@, @NSXTool_VERSION_PATCH@)
version_str = "@OpenHKL_VERSION_MAJOR@.@OpenHKL_VERSION_MINOR@.@OpenHKL_VERSION_PATCH@"
version = (@OpenHKL_VERSION_MAJOR@, @OpenHKL_VERSION_MINOR@, @OpenHKL_VERSION_PATCH@)
from .pynsx import *
# this is needed to adapt to the changes in Python 3.8 on Windows regarding dll loading
# see https://docs.python.org/3/whatsnew/3.8.html#ctypes
if sys.version_info >= (3, 8, 0) and sys.platform == 'win32':
if "PATH" in os.environ:
for p in os.environ['PATH'].split(';'):
if p and os.path.exists(p):
os.add_dll_directory(os.path.abspath(p))
from .pyohkl import *
......@@ -4,7 +4,7 @@ file(GLOB python_tests *.py)
foreach(python_script ${python_tests})
get_filename_component(base_name ${python_script} NAME)
add_test(NAME ${base_name} COMMAND ${PYTHON_EXECUTABLE} ${python_script}
add_test(NAME ${base_name} COMMAND ${Python3_EXECUTABLE} ${python_script}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test/data)
set_tests_properties(${base_name} PROPERTIES
ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/swig")
......
......@@ -4,7 +4,7 @@ if (OHKL_FULL_WORKFLOW_TEST)
file(GLOB python_tests *.py)
foreach(python_script ${python_tests})
get_filename_component(base_name ${python_script} NAME)
add_test(NAME ${base_name} COMMAND ${PYTHON_EXECUTABLE} ${python_script}
add_test(NAME ${base_name} COMMAND ${Python3_EXECUTABLE} ${python_script}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test/data)
set_tests_properties(${base_name} PROPERTIES
ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/swig"
......
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