Mercurial > hg > orthanc-python
annotate CMakeLists.txt @ 26:b0d1308280d8
Added the PYTHON_WINDOWS_USE_RELEASE_LIBS CMake option
to allow usage of debug or release Python builds when building
in debug mode under Windows with Visual Studio.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 06 Apr 2020 20:39:49 +0200 |
parents | 3b59f5dd7e72 |
children | ec7860ac40e9 |
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 "") | |
26
b0d1308280d8
Added the PYTHON_WINDOWS_USE_RELEASE_LIBS CMake option
Benjamin Golinvaux <bgo@osimis.io>
parents:
25
diff
changeset
|
9 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 | 10 set(USE_SYSTEM_BOOST ON CACHE BOOL "Use the system version of Boost") |
11 set(USE_SYSTEM_JSONCPP ON CACHE BOOL "Use the system version of JsonCpp") | |
12 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)") | |
13 | |
14 include(CheckIncludeFile) | |
15 include(CheckIncludeFileCXX) | |
16 include(CheckIncludeFiles) | |
17 include(CheckLibraryExists) | |
16
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
18 include(FindPythonInterp) |
0 | 19 |
21
67f48fc2fd69
fix linking with Python on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
17
diff
changeset
|
20 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
|
21 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
|
22 |
67f48fc2fd69
fix linking with Python on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
17
diff
changeset
|
23 if (NOT PYTHON_VERSION STREQUAL |
67f48fc2fd69
fix linking with Python on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
17
diff
changeset
|
24 "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}") |
67f48fc2fd69
fix linking with Python on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
17
diff
changeset
|
25 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
|
26 endif() |
67f48fc2fd69
fix linking with Python on Windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
17
diff
changeset
|
27 |
0 | 28 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") |
23
874a3fef26ff
fix suffix of Windows library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
21
diff
changeset
|
29 if (MSVC) |
24
3bed39e4b85f
fix prefix and suffix for Windows Python libraries
Benjamin Golinvaux <bgo@osimis.io>
parents:
23
diff
changeset
|
30 set(Prefix "") |
23
874a3fef26ff
fix suffix of Windows library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
21
diff
changeset
|
31 set(Suffix ".lib") |
26
b0d1308280d8
Added the PYTHON_WINDOWS_USE_RELEASE_LIBS CMake option
Benjamin Golinvaux <bgo@osimis.io>
parents:
25
diff
changeset
|
32 if(PYTHON_WINDOWS_USE_RELEASE_LIBS) |
b0d1308280d8
Added the PYTHON_WINDOWS_USE_RELEASE_LIBS CMake option
Benjamin Golinvaux <bgo@osimis.io>
parents:
25
diff
changeset
|
33 add_definitions(-DORTHANC_PYTHON_WINDOWS_USE_RELEASE_LIBS=1) |
b0d1308280d8
Added the PYTHON_WINDOWS_USE_RELEASE_LIBS CMake option
Benjamin Golinvaux <bgo@osimis.io>
parents:
25
diff
changeset
|
34 endif() |
23
874a3fef26ff
fix suffix of Windows library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
21
diff
changeset
|
35 else() |
25
3b59f5dd7e72
improved prefix detection if mingw
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
36 list(GET CMAKE_FIND_LIBRARY_PREFIXES 0 Prefix) |
23
874a3fef26ff
fix suffix of Windows library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
21
diff
changeset
|
37 set(Suffix ".a") |
874a3fef26ff
fix suffix of Windows library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
21
diff
changeset
|
38 endif() |
874a3fef26ff
fix suffix of Windows library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
21
diff
changeset
|
39 |
24
3bed39e4b85f
fix prefix and suffix for Windows Python libraries
Benjamin Golinvaux <bgo@osimis.io>
parents:
23
diff
changeset
|
40 set(PYTHON_LIBRARY_NAME ${Prefix}python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}${Suffix}) |
0 | 41 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
|
42 set(PYTHON_LIBRARIES ${PYTHON_WINDOWS_ROOT}/libs/${PYTHON_LIBRARY_NAME}) |
0 | 43 |
44 else() | |
45 find_package(PkgConfig REQUIRED) | |
46 pkg_check_modules(PYTHON_1 python-${PYTHON_VERSION}-embed) | |
47 | |
48 if (PYTHON_1_FOUND) | |
49 set(PYTHON_INCLUDE_DIRS ${PYTHON_1_INCLUDE_DIRS}) | |
50 set(PYTHON_LIBRARIES ${PYTHON_1_LIBRARIES}) | |
51 else() | |
52 pkg_check_modules(PYTHON_2 REQUIRED python-${PYTHON_VERSION}) | |
53 set(PYTHON_INCLUDE_DIRS ${PYTHON_2_INCLUDE_DIRS}) | |
54 set(PYTHON_LIBRARIES ${PYTHON_2_LIBRARIES}) | |
55 endif() | |
56 endif() | |
57 | |
58 set(ORTHANC_ROOT ${CMAKE_SOURCE_DIR}/Resources/Orthanc) | |
59 include(${ORTHANC_ROOT}/Resources/CMake/Compiler.cmake) | |
60 include(${ORTHANC_ROOT}/Resources/CMake/DownloadPackage.cmake) | |
61 include(${ORTHANC_ROOT}/Resources/CMake/BoostConfiguration.cmake) | |
62 include(${ORTHANC_ROOT}/Resources/CMake/JsonCppConfiguration.cmake) | |
63 | |
16
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
64 |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
65 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
66 execute_process( |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
67 COMMAND |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
68 ${PYTHON_EXECUTABLE} ${ORTHANC_ROOT}/Resources/WindowsResources.py |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
69 ${PLUGIN_VERSION} "Python plugin" OrthancPython.dll |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
70 "Plugin to create Orthanc plugins using Python" |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
71 ERROR_VARIABLE Failure |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
72 OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/Version.rc |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
73 ) |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
74 |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
75 if (Failure) |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
76 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
|
77 endif() |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
78 |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
79 set(WINDOWS_RESOURCES ${CMAKE_CURRENT_BINARY_DIR}/Version.rc) |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
80 endif() |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
81 |
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
82 |
4
e3128420249d
fixing the SDK version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
83 include_directories( |
26
b0d1308280d8
Added the PYTHON_WINDOWS_USE_RELEASE_LIBS CMake option
Benjamin Golinvaux <bgo@osimis.io>
parents:
25
diff
changeset
|
84 #${CMAKE_SOURCE_DIR}/Sources |
4
e3128420249d
fixing the SDK version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
85 ${ORTHANC_ROOT}/Sdk-1.5.7 |
e3128420249d
fixing the SDK version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
86 ) |
0 | 87 |
88 add_definitions( | |
89 -DHAS_ORTHANC_EXCEPTION=0 | |
90 ) | |
91 | |
92 include_directories( | |
93 ${ORTHANC_ROOT}/Plugins/Samples/Common | |
94 ${PYTHON_INCLUDE_DIRS} | |
95 ) | |
96 | |
97 add_library(OrthancPython SHARED | |
98 ${BOOST_SOURCES} | |
99 ${JSONCPP_SOURCES} | |
100 ${ORTHANC_ROOT}/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp | |
16
777b677cc9fc
generation of windows resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
101 ${WINDOWS_RESOURCES} |
0 | 102 Sources/Autogenerated/sdk.cpp |
103 Sources/OnChangeCallback.cpp | |
104 Sources/OnStoredInstanceCallback.cpp | |
105 Sources/Plugin.cpp | |
106 Sources/PythonFunction.cpp | |
107 Sources/PythonLock.cpp | |
108 Sources/PythonModule.cpp | |
109 Sources/PythonObject.cpp | |
110 Sources/PythonString.cpp | |
111 Sources/RestCallbacks.cpp | |
112 ) | |
113 | |
114 target_link_libraries(OrthancPython ${PYTHON_LIBRARIES}) | |
115 | |
116 add_definitions(-DPLUGIN_VERSION="${PLUGIN_VERSION}") | |
117 | |
118 set_target_properties(OrthancPython PROPERTIES | |
119 VERSION ${PLUGIN_VERSION} | |
120 SOVERSION ${PLUGIN_VERSION} | |
121 ) | |
122 | |
123 install( | |
124 TARGETS OrthancPython | |
125 RUNTIME DESTINATION lib # Destination for Windows | |
126 LIBRARY DESTINATION share/orthanc/plugins # Destination for Linux | |
127 ) |