Mercurial > hg > orthanc-python
comparison CMakeLists.txt @ 47:42de8b600c0c
Support of Apple OS X
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 04 Aug 2020 15:32:49 +0200 |
parents | 3e2ff3616e57 |
children | 9e466631660a |
comparison
equal
deleted
inserted
replaced
46:3e2ff3616e57 | 47:42de8b600c0c |
---|---|
10 set(ORTHANC_FRAMEWORK_DEFAULT_VERSION "1.7.2") | 10 set(ORTHANC_FRAMEWORK_DEFAULT_VERSION "1.7.2") |
11 set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "web") | 11 set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "web") |
12 endif() | 12 endif() |
13 | 13 |
14 | 14 |
15 set(PYTHON_VERSION "3.6" CACHE STRING "Version of Python to be used") | 15 if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") |
16 set(PYTHON_WINDOWS_ROOT "" CACHE STRING "") | 16 # The Python version cannot be controlled on OS X (yet) |
17 set(PYTHON_LIBRARY_NAME "" CACHE STRING "") | 17 set(PYTHON_VERSION "3.6" CACHE STRING "Version of Python to be used") |
18 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)") | 18 endif() |
19 | |
20 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") | |
21 # Windows-specific options | |
22 set(PYTHON_WINDOWS_ROOT "" CACHE STRING "") | |
23 set(PYTHON_LIBRARY_NAME "" CACHE STRING "") | |
24 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)") | |
25 endif() | |
26 | |
19 | 27 |
20 | 28 |
21 # Parameters of the build | 29 # Parameters of the build |
22 set(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)") | 30 set(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)") |
23 set(ALLOW_DOWNLOADS OFF CACHE BOOL "Allow CMake to download packages") | 31 set(ALLOW_DOWNLOADS OFF CACHE BOOL "Allow CMake to download packages") |
58 include(CheckIncludeFileCXX) | 66 include(CheckIncludeFileCXX) |
59 include(CheckIncludeFiles) | 67 include(CheckIncludeFiles) |
60 include(CheckLibraryExists) | 68 include(CheckLibraryExists) |
61 include(FindPythonInterp) | 69 include(FindPythonInterp) |
62 | 70 |
63 string(REGEX REPLACE "^([0-9]*)\\.([0-9]*)$" "\\1" PYTHON_VERSION_MAJOR ${PYTHON_VERSION}) | |
64 string(REGEX REPLACE "^([0-9]*)\\.([0-9]*)$" "\\2" PYTHON_VERSION_MINOR ${PYTHON_VERSION}) | |
65 | 71 |
66 if (NOT PYTHON_VERSION STREQUAL | 72 if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") |
67 "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}") | 73 find_package(PythonLibs) |
68 message(FATAL_ERROR "Error in the (x.y) format of the Python version: ${PYTHON_VERSION}") | 74 if (NOT PYTHONLIBS_FOUND) |
69 endif() | 75 message(FATAL_ERROR "Cannot find the Python libraries") |
76 endif() | |
70 | 77 |
71 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") | 78 message("Python library - Found version: ${PYTHONLIBS_VERSION_STRING}") |
72 if ("${PYTHON_LIBRARY_NAME}" STREQUAL "") | 79 message("Python library - Path to include directory: ${PYTHON_INCLUDE_DIRS}") |
73 if (MSVC) | 80 message("Python library - Shared library: ${PYTHON_LIBRARIES}") |
74 set(Prefix "") | 81 |
75 set(Suffix ".lib") | 82 else() |
76 if(PYTHON_WINDOWS_USE_RELEASE_LIBS) | 83 string(REGEX REPLACE "^([0-9]*)\\.([0-9]*)$" "\\1" PYTHON_VERSION_MAJOR ${PYTHON_VERSION}) |
77 add_definitions(-DORTHANC_PYTHON_WINDOWS_USE_RELEASE_LIBS=1) | 84 string(REGEX REPLACE "^([0-9]*)\\.([0-9]*)$" "\\2" PYTHON_VERSION_MINOR ${PYTHON_VERSION}) |
85 | |
86 if (NOT PYTHON_VERSION STREQUAL | |
87 "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}") | |
88 message(FATAL_ERROR "Error in the (x.y) format of the Python version: ${PYTHON_VERSION}") | |
89 endif() | |
90 | |
91 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") | |
92 if ("${PYTHON_LIBRARY_NAME}" STREQUAL "") | |
93 if (MSVC) | |
94 set(Prefix "") | |
95 set(Suffix ".lib") | |
96 if(PYTHON_WINDOWS_USE_RELEASE_LIBS) | |
97 add_definitions(-DORTHANC_PYTHON_WINDOWS_USE_RELEASE_LIBS=1) | |
98 endif() | |
99 else() | |
100 list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix) | |
101 set(Suffix ".a") | |
78 endif() | 102 endif() |
79 else() | 103 |
80 list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix) | 104 set(PYTHON_LIBRARY_NAME ${Prefix}python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}${Suffix}) |
81 set(Suffix ".a") | |
82 endif() | 105 endif() |
83 | 106 |
84 set(PYTHON_LIBRARY_NAME ${Prefix}python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}${Suffix}) | 107 if (CMAKE_COMPILER_IS_GNUCXX AND |
108 "${CMAKE_SIZEOF_VOID_P}" STREQUAL "8" AND | |
109 "${PYTHON_VERSION}" STREQUAL "2.7") | |
110 # Fix for MinGW 64bit: https://stackoverflow.com/a/19867426/881731 | |
111 add_definitions(-DMS_WIN64) | |
112 endif() | |
113 | |
114 set(PYTHON_INCLUDE_DIRS ${PYTHON_WINDOWS_ROOT}/include) | |
115 set(PYTHON_LIBRARIES ${PYTHON_WINDOWS_ROOT}/libs/${PYTHON_LIBRARY_NAME}) | |
116 | |
117 execute_process( | |
118 COMMAND | |
119 ${PYTHON_EXECUTABLE} ${ORTHANC_FRAMEWORK_ROOT}/../Resources/WindowsResources.py | |
120 ${PLUGIN_VERSION} "Python plugin" OrthancPython.dll | |
121 "Plugin to create Orthanc plugins using Python" | |
122 ERROR_VARIABLE Failure | |
123 OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/Version.rc | |
124 ) | |
125 | |
126 if (Failure) | |
127 message(FATAL_ERROR "Error while computing the version information: ${Failure}") | |
128 endif() | |
129 | |
130 set(WINDOWS_RESOURCES ${CMAKE_CURRENT_BINARY_DIR}/Version.rc) | |
131 | |
132 else() | |
133 find_package(PkgConfig REQUIRED) | |
134 pkg_check_modules(PYTHON_1 python-${PYTHON_VERSION}-embed) | |
135 | |
136 if (PYTHON_1_FOUND) | |
137 set(PYTHON_INCLUDE_DIRS ${PYTHON_1_INCLUDE_DIRS}) | |
138 set(PYTHON_LIBRARIES ${PYTHON_1_LIBRARIES}) | |
139 else() | |
140 pkg_check_modules(PYTHON_2 REQUIRED python-${PYTHON_VERSION}) | |
141 set(PYTHON_INCLUDE_DIRS ${PYTHON_2_INCLUDE_DIRS}) | |
142 set(PYTHON_LIBRARIES ${PYTHON_2_LIBRARIES}) | |
143 endif() | |
85 endif() | 144 endif() |
86 | |
87 if (CMAKE_COMPILER_IS_GNUCXX AND | |
88 "${CMAKE_SIZEOF_VOID_P}" STREQUAL "8" AND | |
89 "${PYTHON_VERSION}" STREQUAL "2.7") | |
90 # Fix for MinGW 64bit: https://stackoverflow.com/a/19867426/881731 | |
91 add_definitions(-DMS_WIN64) | |
92 endif() | |
93 | |
94 set(PYTHON_INCLUDE_DIRS ${PYTHON_WINDOWS_ROOT}/include) | |
95 set(PYTHON_LIBRARIES ${PYTHON_WINDOWS_ROOT}/libs/${PYTHON_LIBRARY_NAME}) | |
96 | |
97 else() | |
98 find_package(PkgConfig REQUIRED) | |
99 pkg_check_modules(PYTHON_1 python-${PYTHON_VERSION}-embed) | |
100 | |
101 if (PYTHON_1_FOUND) | |
102 set(PYTHON_INCLUDE_DIRS ${PYTHON_1_INCLUDE_DIRS}) | |
103 set(PYTHON_LIBRARIES ${PYTHON_1_LIBRARIES}) | |
104 else() | |
105 pkg_check_modules(PYTHON_2 REQUIRED python-${PYTHON_VERSION}) | |
106 set(PYTHON_INCLUDE_DIRS ${PYTHON_2_INCLUDE_DIRS}) | |
107 set(PYTHON_LIBRARIES ${PYTHON_2_LIBRARIES}) | |
108 endif() | |
109 endif() | |
110 | |
111 | |
112 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") | |
113 execute_process( | |
114 COMMAND | |
115 ${PYTHON_EXECUTABLE} ${ORTHANC_FRAMEWORK_ROOT}/../Resources/WindowsResources.py | |
116 ${PLUGIN_VERSION} "Python plugin" OrthancPython.dll | |
117 "Plugin to create Orthanc plugins using Python" | |
118 ERROR_VARIABLE Failure | |
119 OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/Version.rc | |
120 ) | |
121 | |
122 if (Failure) | |
123 message(FATAL_ERROR "Error while computing the version information: ${Failure}") | |
124 endif() | |
125 | |
126 set(WINDOWS_RESOURCES ${CMAKE_CURRENT_BINARY_DIR}/Version.rc) | |
127 endif() | 145 endif() |
128 | 146 |
129 | 147 |
130 include_directories( | 148 include_directories( |
131 ${CMAKE_SOURCE_DIR}/Resources/Orthanc/Sdk-1.7.2 | 149 ${CMAKE_SOURCE_DIR}/Resources/Orthanc/Sdk-1.7.2 |