diff CMakeLists.txt @ 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 ec7860ac40e9
children fd58eb5749ed
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})