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