forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
165 lines (146 loc) · 5.51 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Common definitions
add_definitions(
-DBOOST_PYTHON_NO_LIB -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
)
if(CMAKE_COMPILER_IS_GNUCXX
AND Boost_MAJOR_VERSION EQUAL "1"
AND Boost_MINOR_VERSION GREATER "63"
AND Boost_MINOR_VERSION LESS "66"
)
# Several bugs in boost 1.64-1.65 prevent python modules from loading on gcc
# without this definition: https://github.com/boostorg/python/issues/131
add_definitions(-DBOOST_PYTHON_USE_GCC_SYMBOL_VISIBILITY)
endif()
set(PYTHON_DEPS ${MPI_CXX_LIBRARIES})
# Keep boost python separate from other boost
set(_boost_libs_orig ${Boost_LIBRARIES})
set(Boost_LIBRARIES)
find_package(BoostPython REQUIRED)
set(BoostPython_LIBRARIES ${Boost_LIBRARIES})
set(Boost_LIBRARIES ${_boost_libs_orig})
unset(_boost_libs_orig)
# First, common Python code
add_subdirectory(core)
# A function for generating the exports - MODULE_TEMPLATE: The file containing
# the @EXPORT_FUNCTIONS@ and @EXPORT_DECLARE@ flags to replace - OUTPUT_FILE:The
# path to the generated output file - ... The list of export files
function(CREATE_MODULE MODULE_TEMPLATE OUTPUT_FILE)
set(_fwd_declarations)
set(_function_calls)
foreach(_cppfile ${ARGN})
# pull out all functions named 'void export...'
file(STRINGS ${_cppfile} _definitions REGEX "( *)?void *export.*().*")
foreach(_func_definition ${_definitions})
# create a forward declaration and function call
string(STRIP "${_func_definition}" _func_definition)
string(REGEX REPLACE "(void *export.*\\(\\)).*" "\\1" _func_declaration
"${_func_definition}"
)
# add to list of declarations
set(_fwd_declarations "${_fwd_declarations}\n${_func_declaration}\;")
# strip void and add to call list
string(REGEX REPLACE "void *" "" _func_call "${_func_declaration}")
set(_function_calls "${_function_calls}\n${_func_call}\;")
endforeach()
endforeach()
string(STRIP "${_fwd_declarations}" _fwd_declarations)
string(STRIP "${_function_calls}" _function_calls)
# Configure the final file
set(EXPORT_DECLARE ${_fwd_declarations})
set(EXPORT_FUNCTIONS ${_function_calls})
configure_file(${MODULE_TEMPLATE} ${OUTPUT_FILE})
endfunction()
# A function for setting the correct properties on the individual targets
function(SET_PYTHON_PROPERTIES TARGET TARGET_NAME)
# No library prefixes
set_target_properties(${TARGET} PROPERTIES PREFIX "")
# Library name needs to end in .pyd for Windows
if(MSVC)
set_target_properties(
${TARGET} PROPERTIES SUFFIX .pyd COMPILE_FLAGS "/bigobj /w44005 /w44244"
) # bigobj required for intensive templating
elseif(APPLE)
# and in .so on the Mac
set_target_properties(${TARGET} PROPERTIES SUFFIX .so)
endif()
# Set the name
set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME ${TARGET_NAME})
# Debug python library expects imported module names to end in _d
if(PYTHON_DEBUG_LIBRARY)
set_target_properties(
${TARGET} PROPERTIES DEBUG_OUTPUT_NAME ${TARGET_NAME}_d
)
endif()
# Group within VS
set_property(TARGET ${TARGET} PROPERTY FOLDER "MantidFramework/Python")
endfunction()
# ##############################################################################
# mantid package
# ##############################################################################
# Common install RPATH setting for all extension modules
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(EXT_INSTALL_RPATH ${DL_ORIGIN_TAG}/../../../MacOS)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(EXT_INSTALL_RPATH ${DL_ORIGIN_TAG}/../../../${LIB_DIR})
endif()
# All targets can see these includes
include_directories(core/inc)
# TODO: Move all common code to the core library to remove the need for linking
# submodules together
include_directories(inc)
add_subdirectory(mantid)
include(PythonPackageTargetFunctions)
# Adds `mantid` as a target in the `MantidFramework/Python` folder
if(APPLE)
set(_install_lib_dirs)
list(APPEND _install_lib_dirs ${WORKBENCH_SITE_PACKAGES})
else()
set(_install_lib_dirs "${SITE_PACKAGES}")
endif()
add_python_package(
PythonInterface
EGGLINKNAME mantid
INSTALL_LIB_DIRS ${_install_lib_dirs}
GENERATE_SITECUSTOMIZE
)
set_property(TARGET PythonInterface PROPERTY FOLDER "MantidFramework/Python")
add_dependencies(
PythonInterface
PythonInterfaceCore
PythonKernelModule
PythonGeometryModule
PythonAPIModule
PythonDataObjectsModule
PythonCurveFittingModule
)
# Clear any leftover bin/$(Configuration)/mantid/ folder, from when
# PythonInterface was being copied over. The last semicolon is there to have an
# iteration with an empty string which makes the last check just bin/mantid for
# non-Windows builds
set(_windows_configurations "Debug/;Release/;")
foreach(_configuration IN LISTS _windows_configurations)
set(_old_mantid_dir ${CMAKE_BINARY_DIR}/bin/${_configuration}mantid)
if(EXISTS ${_old_mantid_dir})
message("Removing old mantid PythonInterface directory: ${_old_mantid_dir}")
file(REMOVE_RECURSE ${_old_mantid_dir})
endif()
endforeach(_configuration)
# ##############################################################################
# Python algorithms
# ##############################################################################
clean_orphaned_pyc_files(${CMAKE_CURRENT_SOURCE_DIR}/plugins)
add_subdirectory(plugins)
# tests
set(PYTHONINTERFACE_PLUGINS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/plugins)
add_subdirectory(test)
# Installation settings
# Python algorithms
mtd_install_dirs(
DIRECTORY
plugins/
INSTALL_DIRS
${PLUGINS_DIR}/python
${WORKBENCH_PLUGINS_DIR}/python
EXCLUDE
"*.pyc"
)