changeset 33:ce5b6116e6cd

New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 28 May 2020 18:05:18 +0200
parents 30161a429a91
children af63e0fe7a73
files CMakeLists.txt NEWS Resources/Builders/MinGW32-Python3.7/docker-compile.sh Resources/Builders/MinGW32-Python3.7/docker-internal.sh Resources/Builders/MinGW32-Python3.8/docker-compile.sh Resources/Builders/MinGW32-Python3.8/docker-internal.sh Resources/Builders/MinGW64-Python2.7/docker-compile.sh Resources/Builders/MinGW64-Python2.7/docker-internal.sh Resources/Builders/MinGW64-Python3.7/docker-compile.sh Resources/Builders/MinGW64-Python3.7/docker-internal.sh Resources/Builders/MinGW64-Python3.8/docker-compile.sh Resources/Builders/MinGW64-Python3.8/docker-internal.sh
diffstat 12 files changed, 346 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Tue May 12 12:20:50 2020 +0200
+++ b/CMakeLists.txt	Thu May 28 18:05:18 2020 +0200
@@ -6,6 +6,7 @@
 
 set(PYTHON_VERSION "3.6" CACHE STRING "Version of Python to be used")
 set(PYTHON_WINDOWS_ROOT "" CACHE STRING "")
+set(PYTHON_LIBRARY_NAME "" CACHE STRING "")
 set(PYTHON_WINDOWS_USE_RELEASE_LIBS ON CACHE BOOL "Use the release Python libraries when building with Microsoft Visual Studio, even when compiling in _DEBUG mode (set it to OFF if you require linking to a Python debug build)")
 set(USE_SYSTEM_BOOST ON CACHE BOOL "Use the system version of Boost")
 set(USE_SYSTEM_JSONCPP ON CACHE BOOL "Use the system version of JsonCpp")
@@ -26,18 +27,28 @@
 endif()
 
 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
-  if (MSVC)
-    set(Prefix "")
-    set(Suffix ".lib")
-    if(PYTHON_WINDOWS_USE_RELEASE_LIBS)
-      add_definitions(-DORTHANC_PYTHON_WINDOWS_USE_RELEASE_LIBS=1)
+  if ("${PYTHON_LIBRARY_NAME}" STREQUAL "")
+    if (MSVC)
+      set(Prefix "")
+      set(Suffix ".lib")
+      if(PYTHON_WINDOWS_USE_RELEASE_LIBS)
+        add_definitions(-DORTHANC_PYTHON_WINDOWS_USE_RELEASE_LIBS=1)
+      endif()
+    else()
+      list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix)
+      set(Suffix ".a")
     endif()
-  else()
-    list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix)
-    set(Suffix ".a")
+    
+    set(PYTHON_LIBRARY_NAME ${Prefix}python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}${Suffix})
   endif()
   
-  set(PYTHON_LIBRARY_NAME ${Prefix}python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}${Suffix})
+  if (CMAKE_COMPILER_IS_GNUCXX AND
+      "${CMAKE_SIZEOF_VOID_P}" STREQUAL "8" AND
+      "${PYTHON_VERSION}" STREQUAL "2.7")
+    # Fix for MinGW 64bit: https://stackoverflow.com/a/19867426/881731
+    add_definitions(-DMS_WIN64)
+  endif()
+    
   set(PYTHON_INCLUDE_DIRS ${PYTHON_WINDOWS_ROOT}/include)
   set(PYTHON_LIBRARIES ${PYTHON_WINDOWS_ROOT}/libs/${PYTHON_LIBRARY_NAME})
   
@@ -94,10 +105,6 @@
   )
 
 add_library(OrthancPython SHARED
-  ${BOOST_SOURCES}
-  ${JSONCPP_SOURCES}
-  ${ORTHANC_ROOT}/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp
-  ${WINDOWS_RESOURCES}
   Sources/Autogenerated/sdk.cpp
   Sources/OnChangeCallback.cpp
   Sources/OnStoredInstanceCallback.cpp
@@ -108,6 +115,12 @@
   Sources/PythonObject.cpp
   Sources/PythonString.cpp
   Sources/RestCallbacks.cpp
+
+  # Third-party sources
+  ${ORTHANC_ROOT}/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp
+  ${BOOST_SOURCES}
+  ${JSONCPP_SOURCES}
+  ${WINDOWS_RESOURCES}
   )
 
 target_link_libraries(OrthancPython ${PYTHON_LIBRARIES})
--- a/NEWS	Tue May 12 12:20:50 2020 +0200
+++ b/NEWS	Thu May 28 18:05:18 2020 +0200
@@ -3,6 +3,7 @@
 
 * Fix compilation using Visual Studio
 * The "Calling Python..." info logs are disabled if "PythonVerbose" is "false"
+* New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
 
 
 Version 1.0 (2020-04-01)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Builders/MinGW32-Python3.7/docker-compile.sh	Thu May 28 18:05:18 2020 +0200
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+set -ex
+
+if [ "$1" != "Debug" -a "$1" != "Release" ]; then
+    echo "Please provide build type: Debug or Release"
+    exit -1
+fi
+
+if [ -t 1 ]; then
+    # TTY is available => use interactive mode
+    DOCKER_FLAGS='-i'
+fi
+
+ROOT_DIR=`dirname $(readlink -f $0)`/../../..
+
+mkdir -p ${ROOT_DIR}/docker-build/
+
+( cd ${ROOT_DIR}/Resources/Builders/ && \
+        docker build \
+               -f ./Dockerfile-MinGW-BuildEnvironment \
+               -t mingw-python-build . )
+
+docker run -t ${DOCKER_FLAGS} --rm \
+    --user $(id -u):$(id -g) \
+    -v ${ROOT_DIR}:/source:ro \
+    -v ${ROOT_DIR}/docker-build:/target:rw \
+    mingw-python-build \
+    bash /source/Resources/Builders/MinGW32-Python3.7/docker-internal.sh $1
+
+ls -lR ${ROOT_DIR}/docker-build/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Builders/MinGW32-Python3.7/docker-internal.sh	Thu May 28 18:05:18 2020 +0200
@@ -0,0 +1,30 @@
+#!/bin/bash
+set -ex
+
+mkdir /tmp/source-writeable
+
+cp -r /source/CMakeLists.txt /tmp/source-writeable/
+cp -r /source/Sources /tmp/source-writeable/
+cp -r /source/Resources /tmp/source-writeable/
+
+mkdir /tmp/build
+cd /tmp/build
+
+wget http://orthanc.osimis.io/ThirdPartyDownloads/Python/python-3.7.7-win32.zip
+unzip python-3.7.7-win32.zip
+
+cmake /tmp/source-writeable/ \
+      -DCMAKE_BUILD_TYPE=$1 \
+      -DSTATIC_BUILD=ON \
+      -DPYTHON_VERSION=3.7 \
+      -DPYTHON_WINDOWS_ROOT=/tmp/build/python-3.7.7-win32/ \
+      -DCMAKE_TOOLCHAIN_FILE=/source/Resources/Orthanc/Resources/MinGW-W64-Toolchain32.cmake \
+      -DCMAKE_INSTALL_PREFIX=/target 
+
+make -j`nproc`
+
+if [ "$1" == "Release" ]; then
+    i686-w64-mingw32-strip ./libOrthancPython.dll
+fi
+
+make install
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Builders/MinGW32-Python3.8/docker-compile.sh	Thu May 28 18:05:18 2020 +0200
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+set -ex
+
+if [ "$1" != "Debug" -a "$1" != "Release" ]; then
+    echo "Please provide build type: Debug or Release"
+    exit -1
+fi
+
+if [ -t 1 ]; then
+    # TTY is available => use interactive mode
+    DOCKER_FLAGS='-i'
+fi
+
+ROOT_DIR=`dirname $(readlink -f $0)`/../../..
+
+mkdir -p ${ROOT_DIR}/docker-build/
+
+( cd ${ROOT_DIR}/Resources/Builders/ && \
+        docker build \
+               -f ./Dockerfile-MinGW-BuildEnvironment \
+               -t mingw-python-build . )
+
+docker run -t ${DOCKER_FLAGS} --rm \
+    --user $(id -u):$(id -g) \
+    -v ${ROOT_DIR}:/source:ro \
+    -v ${ROOT_DIR}/docker-build:/target:rw \
+    mingw-python-build \
+    bash /source/Resources/Builders/MinGW32-Python3.8/docker-internal.sh $1
+
+ls -lR ${ROOT_DIR}/docker-build/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Builders/MinGW32-Python3.8/docker-internal.sh	Thu May 28 18:05:18 2020 +0200
@@ -0,0 +1,37 @@
+#!/bin/bash
+set -ex
+
+mkdir /tmp/source-writeable
+
+cp -r /source/CMakeLists.txt /tmp/source-writeable/
+cp -r /source/Sources /tmp/source-writeable/
+cp -r /source/Resources /tmp/source-writeable/
+
+mkdir /tmp/build
+cd /tmp/build
+
+wget http://orthanc.osimis.io/ThirdPartyDownloads/Python/python-3.8.3-win32.zip
+unzip python-3.8.3-win32.zip
+
+if [ "$1" == "Release" ]; then
+    LIBRARY_NAME=python38.lib
+else
+    LIBRARY_NAME=python38_d.lib
+fi
+
+cmake /tmp/source-writeable/ \
+      -DCMAKE_BUILD_TYPE=$1 \
+      -DSTATIC_BUILD=ON \
+      -DPYTHON_VERSION=3.8 \
+      -DPYTHON_LIBRARY_NAME=${LIBRARY_NAME} \
+      -DPYTHON_WINDOWS_ROOT=/tmp/build/Python-3.8.3-win32/ \
+      -DCMAKE_TOOLCHAIN_FILE=/source/Resources/Orthanc/Resources/MinGW-W64-Toolchain32.cmake \
+      -DCMAKE_INSTALL_PREFIX=/target 
+
+make -j`nproc`
+
+if [ "$1" == "Release" ]; then
+    i686-w64-mingw32-strip ./libOrthancPython.dll
+fi
+
+make install
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Builders/MinGW64-Python2.7/docker-compile.sh	Thu May 28 18:05:18 2020 +0200
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+set -ex
+
+if [ "$1" != "Debug" -a "$1" != "Release" ]; then
+    echo "Please provide build type: Debug or Release"
+    exit -1
+fi
+
+if [ -t 1 ]; then
+    # TTY is available => use interactive mode
+    DOCKER_FLAGS='-i'
+fi
+
+ROOT_DIR=`dirname $(readlink -f $0)`/../../..
+
+mkdir -p ${ROOT_DIR}/docker-build/
+
+( cd ${ROOT_DIR}/Resources/Builders/ && \
+        docker build \
+               -f ./Dockerfile-MinGW-BuildEnvironment \
+               -t mingw-python-build . )
+
+docker run -t ${DOCKER_FLAGS} --rm \
+    --user $(id -u):$(id -g) \
+    -v ${ROOT_DIR}:/source:ro \
+    -v ${ROOT_DIR}/docker-build:/target:rw \
+    mingw-python-build \
+    bash /source/Resources/Builders/MinGW64-Python2.7/docker-internal.sh $1
+
+ls -lR ${ROOT_DIR}/docker-build/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Builders/MinGW64-Python2.7/docker-internal.sh	Thu May 28 18:05:18 2020 +0200
@@ -0,0 +1,30 @@
+#!/bin/bash
+set -ex
+
+mkdir /tmp/source-writeable
+
+cp -r /source/CMakeLists.txt /tmp/source-writeable/
+cp -r /source/Sources /tmp/source-writeable/
+cp -r /source/Resources /tmp/source-writeable/
+
+mkdir /tmp/build
+cd /tmp/build
+
+wget http://orthanc.osimis.io/ThirdPartyDownloads/Python/python-2.7.17-win64.zip
+unzip python-2.7.17-win64.zip
+
+cmake /tmp/source-writeable/ \
+      -DCMAKE_BUILD_TYPE=$1 \
+      -DSTATIC_BUILD=ON \
+      -DPYTHON_VERSION=2.7 \
+      -DPYTHON_WINDOWS_ROOT=/tmp/build/Python27/ \
+      -DCMAKE_TOOLCHAIN_FILE=/source/Resources/Orthanc/Resources/MinGW-W64-Toolchain64.cmake \
+      -DCMAKE_INSTALL_PREFIX=/target 
+
+make -j`nproc`
+
+if [ "$1" == "Release" ]; then
+    x86_64-w64-mingw32-strip ./libOrthancPython.dll
+fi
+
+make install
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Builders/MinGW64-Python3.7/docker-compile.sh	Thu May 28 18:05:18 2020 +0200
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+set -ex
+
+if [ "$1" != "Debug" -a "$1" != "Release" ]; then
+    echo "Please provide build type: Debug or Release"
+    exit -1
+fi
+
+if [ -t 1 ]; then
+    # TTY is available => use interactive mode
+    DOCKER_FLAGS='-i'
+fi
+
+ROOT_DIR=`dirname $(readlink -f $0)`/../../..
+
+mkdir -p ${ROOT_DIR}/docker-build/
+
+( cd ${ROOT_DIR}/Resources/Builders/ && \
+        docker build \
+               -f ./Dockerfile-MinGW-BuildEnvironment \
+               -t mingw-python-build . )
+
+docker run -t ${DOCKER_FLAGS} --rm \
+    --user $(id -u):$(id -g) \
+    -v ${ROOT_DIR}:/source:ro \
+    -v ${ROOT_DIR}/docker-build:/target:rw \
+    mingw-python-build \
+    bash /source/Resources/Builders/MinGW64-Python3.7/docker-internal.sh $1
+
+ls -lR ${ROOT_DIR}/docker-build/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Builders/MinGW64-Python3.7/docker-internal.sh	Thu May 28 18:05:18 2020 +0200
@@ -0,0 +1,30 @@
+#!/bin/bash
+set -ex
+
+mkdir /tmp/source-writeable
+
+cp -r /source/CMakeLists.txt /tmp/source-writeable/
+cp -r /source/Sources /tmp/source-writeable/
+cp -r /source/Resources /tmp/source-writeable/
+
+mkdir /tmp/build
+cd /tmp/build
+
+wget http://orthanc.osimis.io/ThirdPartyDownloads/Python/python-3.7.7-win64.zip
+unzip python-3.7.7-win64.zip
+
+cmake /tmp/source-writeable/ \
+      -DCMAKE_BUILD_TYPE=$1 \
+      -DSTATIC_BUILD=ON \
+      -DPYTHON_VERSION=3.7 \
+      -DPYTHON_WINDOWS_ROOT=/tmp/build/python-3.7.7-win64/ \
+      -DCMAKE_TOOLCHAIN_FILE=/source/Resources/Orthanc/Resources/MinGW-W64-Toolchain64.cmake \
+      -DCMAKE_INSTALL_PREFIX=/target 
+
+make -j`nproc`
+
+if [ "$1" == "Release" ]; then
+    x86_64-w64-mingw32-strip ./libOrthancPython.dll
+fi
+
+make install
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Builders/MinGW64-Python3.8/docker-compile.sh	Thu May 28 18:05:18 2020 +0200
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+set -ex
+
+if [ "$1" != "Debug" -a "$1" != "Release" ]; then
+    echo "Please provide build type: Debug or Release"
+    exit -1
+fi
+
+if [ -t 1 ]; then
+    # TTY is available => use interactive mode
+    DOCKER_FLAGS='-i'
+fi
+
+ROOT_DIR=`dirname $(readlink -f $0)`/../../..
+
+mkdir -p ${ROOT_DIR}/docker-build/
+
+( cd ${ROOT_DIR}/Resources/Builders/ && \
+        docker build \
+               -f ./Dockerfile-MinGW-BuildEnvironment \
+               -t mingw-python-build . )
+
+docker run -t ${DOCKER_FLAGS} --rm \
+    --user $(id -u):$(id -g) \
+    -v ${ROOT_DIR}:/source:ro \
+    -v ${ROOT_DIR}/docker-build:/target:rw \
+    mingw-python-build \
+    bash /source/Resources/Builders/MinGW64-Python3.8/docker-internal.sh $1
+
+ls -lR ${ROOT_DIR}/docker-build/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Builders/MinGW64-Python3.8/docker-internal.sh	Thu May 28 18:05:18 2020 +0200
@@ -0,0 +1,37 @@
+#!/bin/bash
+set -ex
+
+mkdir /tmp/source-writeable
+
+cp -r /source/CMakeLists.txt /tmp/source-writeable/
+cp -r /source/Sources /tmp/source-writeable/
+cp -r /source/Resources /tmp/source-writeable/
+
+mkdir /tmp/build
+cd /tmp/build
+
+wget http://orthanc.osimis.io/ThirdPartyDownloads/Python/python-3.8.3-win64.zip
+unzip python-3.8.3-win64.zip
+
+if [ "$1" == "Release" ]; then
+    LIBRARY_NAME=python38.lib
+else
+    LIBRARY_NAME=python38_d.lib
+fi
+
+cmake /tmp/source-writeable/ \
+      -DCMAKE_BUILD_TYPE=$1 \
+      -DSTATIC_BUILD=ON \
+      -DPYTHON_VERSION=3.8 \
+      -DPYTHON_LIBRARY_NAME=${LIBRARY_NAME} \
+      -DPYTHON_WINDOWS_ROOT=/tmp/build/Python38 \
+      -DCMAKE_TOOLCHAIN_FILE=/source/Resources/Orthanc/Resources/MinGW-W64-Toolchain64.cmake \
+      -DCMAKE_INSTALL_PREFIX=/target 
+
+make -j`nproc`
+
+if [ "$1" == "Release" ]; then
+    x86_64-w64-mingw32-strip ./libOrthancPython.dll
+fi
+
+make install