Mercurial > hg > orthanc-python
annotate 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 |
rev | line source |
---|---|
0 | 1 cmake_minimum_required(VERSION 2.8) |
2 project(OrthancPython) | |
3 | |
15 | 4 set(PLUGIN_VERSION "mainline") |
0 | 5 |
6 | |
7 set(PYTHON_VERSION "3.6" CACHE STRING "Version of Python to be used") | |
8 set(PYTHON_WINDOWS_ROOT "" CACHE STRING "") | |
33
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
9 set(PYTHON_LIBRARY_NAME "" CACHE STRING "") |
26
b0d1308280d8
Added the PYTHON_WINDOWS_USE_RELEASE_LIBS CMake option
Benjamin Golinvaux <bgo@osimis.io>
parents:
25
diff
changeset
|
10 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)") |
0 | 11 set(USE_SYSTEM_BOOST ON CACHE BOOL "Use the system version of Boost") |
12 set(USE_SYSTEM_JSONCPP ON CACHE BOOL "Use the system version of JsonCpp") | |
13 set(USE_LEGACY_JSONCPP OFF CACHE BOOL "Use the old branch 0.x.y of JsonCpp, that does not require a C++11 compiler (for LSB and old versions of Visual Studio)") | |
14 | |
15 include(CheckIncludeFile) | |
16 include(CheckIncludeFileCXX) | |
17 include(CheckIncludeFiles) | |
18 include(CheckLibraryExists) | |
16
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
19 include(FindPythonInterp) |
0 | 20 |
21
67f48fc2fd69
fix linking with Python on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
17
diff
changeset
|
21 string(REGEX REPLACE "^([0-9]*)\\.([0-9]*)$" "\\1" PYTHON_VERSION_MAJOR ${PYTHON_VERSION}) |
67f48fc2fd69
fix linking with Python on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
17
diff
changeset
|
22 string(REGEX REPLACE "^([0-9]*)\\.([0-9]*)$" "\\2" PYTHON_VERSION_MINOR ${PYTHON_VERSION}) |
67f48fc2fd69
fix linking with Python on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
17
diff
changeset
|
23 |
67f48fc2fd69
fix linking with Python on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
17
diff
changeset
|
24 if (NOT PYTHON_VERSION STREQUAL |
67f48fc2fd69
fix linking with Python on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
17
diff
changeset
|
25 "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}") |
67f48fc2fd69
fix linking with Python on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
17
diff
changeset
|
26 message(FATAL_ERROR "Error in the (x.y) format of the Python version: ${PYTHON_VERSION}") |
67f48fc2fd69
fix linking with Python on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
17
diff
changeset
|
27 endif() |
67f48fc2fd69
fix linking with Python on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
17
diff
changeset
|
28 |
0 | 29 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") |
33
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
30 if ("${PYTHON_LIBRARY_NAME}" STREQUAL "") |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
31 if (MSVC) |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
32 set(Prefix "") |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
33 set(Suffix ".lib") |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
34 if(PYTHON_WINDOWS_USE_RELEASE_LIBS) |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
35 add_definitions(-DORTHANC_PYTHON_WINDOWS_USE_RELEASE_LIBS=1) |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
36 endif() |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
37 else() |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
38 list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix) |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
39 set(Suffix ".a") |
26
b0d1308280d8
Added the PYTHON_WINDOWS_USE_RELEASE_LIBS CMake option
Benjamin Golinvaux <bgo@osimis.io>
parents:
25
diff
changeset
|
40 endif() |
33
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
41 |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
42 set(PYTHON_LIBRARY_NAME ${Prefix}python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}${Suffix}) |
23
874a3fef26ff
fix suffix of Windows library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
21
diff
changeset
|
43 endif() |
874a3fef26ff
fix suffix of Windows library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
21
diff
changeset
|
44 |
33
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
45 if (CMAKE_COMPILER_IS_GNUCXX AND |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
46 "${CMAKE_SIZEOF_VOID_P}" STREQUAL "8" AND |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
47 "${PYTHON_VERSION}" STREQUAL "2.7") |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
48 # Fix for MinGW 64bit: https://stackoverflow.com/a/19867426/881731 |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
49 add_definitions(-DMS_WIN64) |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
50 endif() |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
51 |
0 | 52 set(PYTHON_INCLUDE_DIRS ${PYTHON_WINDOWS_ROOT}/include) |
21
67f48fc2fd69
fix linking with Python on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
17
diff
changeset
|
53 set(PYTHON_LIBRARIES ${PYTHON_WINDOWS_ROOT}/libs/${PYTHON_LIBRARY_NAME}) |
0 | 54 |
55 else() | |
56 find_package(PkgConfig REQUIRED) | |
57 pkg_check_modules(PYTHON_1 python-${PYTHON_VERSION}-embed) | |
58 | |
59 if (PYTHON_1_FOUND) | |
60 set(PYTHON_INCLUDE_DIRS ${PYTHON_1_INCLUDE_DIRS}) | |
61 set(PYTHON_LIBRARIES ${PYTHON_1_LIBRARIES}) | |
62 else() | |
63 pkg_check_modules(PYTHON_2 REQUIRED python-${PYTHON_VERSION}) | |
64 set(PYTHON_INCLUDE_DIRS ${PYTHON_2_INCLUDE_DIRS}) | |
65 set(PYTHON_LIBRARIES ${PYTHON_2_LIBRARIES}) | |
66 endif() | |
67 endif() | |
68 | |
69 set(ORTHANC_ROOT ${CMAKE_SOURCE_DIR}/Resources/Orthanc) | |
70 include(${ORTHANC_ROOT}/Resources/CMake/Compiler.cmake) | |
71 include(${ORTHANC_ROOT}/Resources/CMake/DownloadPackage.cmake) | |
72 include(${ORTHANC_ROOT}/Resources/CMake/BoostConfiguration.cmake) | |
73 include(${ORTHANC_ROOT}/Resources/CMake/JsonCppConfiguration.cmake) | |
74 | |
16
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
75 |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
76 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
77 execute_process( |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
78 COMMAND |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
79 ${PYTHON_EXECUTABLE} ${ORTHANC_ROOT}/Resources/WindowsResources.py |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
80 ${PLUGIN_VERSION} "Python plugin" OrthancPython.dll |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
81 "Plugin to create Orthanc plugins using Python" |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
82 ERROR_VARIABLE Failure |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
83 OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/Version.rc |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
84 ) |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
85 |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
86 if (Failure) |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
87 message(FATAL_ERROR "Error while computing the version information: ${Failure}") |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
88 endif() |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
89 |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
90 set(WINDOWS_RESOURCES ${CMAKE_CURRENT_BINARY_DIR}/Version.rc) |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
91 endif() |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
92 |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
93 |
4
e3128420249d
fixing the SDK version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
94 include_directories( |
e3128420249d
fixing the SDK version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
95 ${ORTHANC_ROOT}/Sdk-1.5.7 |
e3128420249d
fixing the SDK version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
96 ) |
0 | 97 |
98 add_definitions( | |
99 -DHAS_ORTHANC_EXCEPTION=0 | |
100 ) | |
101 | |
102 include_directories( | |
103 ${ORTHANC_ROOT}/Plugins/Samples/Common | |
104 ${PYTHON_INCLUDE_DIRS} | |
105 ) | |
106 | |
107 add_library(OrthancPython SHARED | |
108 Sources/Autogenerated/sdk.cpp | |
109 Sources/OnChangeCallback.cpp | |
110 Sources/OnStoredInstanceCallback.cpp | |
111 Sources/Plugin.cpp | |
112 Sources/PythonFunction.cpp | |
113 Sources/PythonLock.cpp | |
114 Sources/PythonModule.cpp | |
115 Sources/PythonObject.cpp | |
116 Sources/PythonString.cpp | |
117 Sources/RestCallbacks.cpp | |
33
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
118 |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
119 # Third-party sources |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
120 ${ORTHANC_ROOT}/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
121 ${BOOST_SOURCES} |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
122 ${JSONCPP_SOURCES} |
ce5b6116e6cd
New builders for Windows: Supporting 32 / 64bit with Python 2.7 / 3.7 / 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
123 ${WINDOWS_RESOURCES} |
0 | 124 ) |
125 | |
126 target_link_libraries(OrthancPython ${PYTHON_LIBRARIES}) | |
127 | |
128 add_definitions(-DPLUGIN_VERSION="${PLUGIN_VERSION}") | |
129 | |
130 set_target_properties(OrthancPython PROPERTIES | |
131 VERSION ${PLUGIN_VERSION} | |
132 SOVERSION ${PLUGIN_VERSION} | |
133 ) | |
134 | |
135 install( | |
136 TARGETS OrthancPython | |
137 RUNTIME DESTINATION lib # Destination for Windows | |
138 LIBRARY DESTINATION share/orthanc/plugins # Destination for Linux | |
139 ) |