1
- cmake_minimum_required (VERSION 2.8 )
2
- include ( ${CMAKE_CURRENT_SOURCE_DIR} /../CheckCXXCompiler.cmake )
1
+ include (${CMAKE_CURRENT_SOURCE_DIR} /../CheckCXXCompiler.cmake )
3
2
4
3
set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /../cmake_modules/" )
5
4
6
- find_package (PythonInterp REQUIRED )
5
+ execute_process (COMMAND
6
+ ${PYTHON_EXECUTABLE} -c "import numpy;print(numpy.get_include())"
7
+ OUTPUT_VARIABLE NUMPY_INCLUDE_DIRS
8
+ OUTPUT_STRIP_TRAILING_WHITESPACE )
9
+
10
+ if ("${NUMPY_INCLUDE_DIRS} " STREQUAL "" )
11
+ message (FATAL_ERROR "Could not find numpy: ${NUMPY_INCLUDE_DIRS} " )
12
+ else ()
13
+ message (STATUS "Numpy is found at ${NUMPY_INCLUDE_DIRS} " )
14
+ endif ()
7
15
8
- # Find Numpy
9
- find_package (NumPy REQUIRED )
10
16
include_directories (${NUMPY_INCLUDE_DIRS} )
11
- add_definitions ( -std=c++11 )
17
+ add_definitions (-std=c++11 )
12
18
add_definitions (-DUSE_NUMPY )
13
19
add_definitions (-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION )
14
20
15
21
# set module extensiton. default is .so. Also check ../python/setup.cmake.py
16
- execute_process ( COMMAND
22
+ execute_process (COMMAND
17
23
${PYTHON_EXECUTABLE} -c
18
24
"import importlib.machinery
19
25
print(importlib.machinery.EXTENSION_SUFFIXES[-1])"
20
26
OUTPUT_VARIABLE PYTHON_SO_EXTENSION
21
- OUTPUT_STRIP_TRAILING_WHITESPACE
22
- )
27
+ OUTPUT_STRIP_TRAILING_WHITESPACE )
23
28
if (NOT PYTHON_SO_EXTENSION )
24
29
message (STATUS "Python so ext could not be determined. Using default .so" )
25
30
set (PYTHON_SO_EXTENSION ".so" )
@@ -44,38 +49,36 @@ set(PYMOOSE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../python/moose")
44
49
message (STATUS "Python module will be saved to ${PYMOOSE_OUTPUT_DIRECTORY} " )
45
50
46
51
# make sure the Python.h is found.
47
- find_package ( PythonLibs )
48
- if (PYTHON_INCLUDE_DIRS )
49
- include_directories ( ${PYTHON_INCLUDE_DIRS} )
50
- else ()
51
- # Use python executable to find include paths. For building wheel, we are
52
- # stuck with cmake-2.8 with which PythonLibs module might fail.
53
- message ( STATUS "Using ${PYTHON_EXECUTABLE} -config to find Python.h" )
54
- execute_process ( COMMAND ${PYTHON_EXECUTABLE} -config --includes
55
- OUTPUT_VARIABLE PYTHON_INCLUDE_FLAGS
56
- OUTPUT_STRIP_TRAILING_WHITESPACE
57
- )
58
- execute_process ( COMMAND ${PYTHON_EXECUTABLE} -config --libs
59
- OUTPUT_VARIABLE PYTHON_LIBRARIES
60
- OUTPUT_STRIP_TRAILING_WHITESPACE
61
- )
62
- message ( STATUS "Python include flags: ${PYTHON_INCLUDE_FLAGS} " )
63
- set_target_properties (_moose PROPERTIES
64
- COMPILE_DEFINITIONS "PYMOOSE"
65
- COMPILE_FLAGS "${PYTHON_INCLUDE_FLAGS} "
66
- )
52
+ # Use python executable to find include paths. For building wheel, we are
53
+ # stuck with cmake-2.8 with which PythonLibs module might fail.
54
+ message (STATUS "Using ${PYTHON_EXECUTABLE} -config to find Python.h" )
55
+ execute_process ( COMMAND ${PYTHON_EXECUTABLE} -config --includes
56
+ OUTPUT_VARIABLE PYTHON_INCLUDE_FLAGS
57
+ OUTPUT_STRIP_TRAILING_WHITESPACE )
67
58
59
+ if ("${PYTHON_INCLUDE_FLAGS} " STREQUAL "" )
60
+ message (FATAL_ERROR "Could not determine path of Python.h." )
61
+ else ()
62
+ message (STATUS "Python.h is found at ${PYTHON_INCLUDE_FLAGS} " )
68
63
endif ()
69
64
65
+ execute_process ( COMMAND ${PYTHON_EXECUTABLE} -config --libs
66
+ OUTPUT_VARIABLE PYTHON_LIBRARIES
67
+ OUTPUT_STRIP_TRAILING_WHITESPACE )
68
+
69
+ set_target_properties (_moose PROPERTIES
70
+ COMPILE_DEFINITIONS "PYMOOSE"
71
+ COMPILE_FLAGS "${COMPILE_FLAGS} ${PYTHON_INCLUDE_FLAGS} "
72
+ )
73
+
70
74
# Remove prefix lib from python module.
71
75
if (NOT (PYTHON_SO_EXTENSION STREQUAL "" ))
72
76
set_target_properties (_moose PROPERTIES SUFFIX ${PYTHON_SO_EXTENSION} )
73
77
endif ()
74
78
set_target_properties (_moose PROPERTIES
75
79
LIBRARY_OUTPUT_DIRECTORY ${PYMOOSE_OUTPUT_DIRECTORY}
76
80
PREFIX ""
77
- SUFFIX ${PYTHON_SO_EXTENSION}
78
- )
81
+ SUFFIX ${PYTHON_SO_EXTENSION} )
79
82
80
83
# see issue #80
81
84
if (HDF5_FOUND AND WITH_NSDF )
@@ -85,37 +88,33 @@ endif()
85
88
if (APPLE )
86
89
set (CMAKE_MODULE_LINKER_FLAGS "-undefined dynamic_lookup" )
87
90
message (STATUS "ADDING some linker flags ${CMAKE_EXE_LINKER_FLAGS} " )
88
- endif (APPLE )
89
-
90
- # cmake --help-policy CMP0042
91
- if (APPLE )
91
+ # cmake --help-policy CMP0042
92
92
set_target_properties ( _moose PROPERTIES MACOSX_RPATH OFF )
93
93
endif (APPLE )
94
94
95
95
if (APPLE )
96
- target_link_libraries ( _moose
97
- "-Wl,-all_load"
98
- ${MOOSE_LIBRARIES}
99
- ${STATIC_LIBRARIES}
100
- )
101
- target_link_libraries (_moose
102
- ${SYSTEM_SHARED_LIBS}
103
- )
96
+ target_link_libraries ( _moose
97
+ "-Wl,-all_load"
98
+ ${MOOSE_LIBRARIES}
99
+ ${STATIC_LIBRARIES}
100
+ )
101
+ target_link_libraries (_moose
102
+ ${SYSTEM_SHARED_LIBS}
103
+ )
104
104
else (APPLE )
105
- target_link_libraries (_moose
106
- "-Wl,--whole-archive"
107
- ${MOOSE_LIBRARIES}
108
- ${STATIC_LIBRARIES}
109
- "-Wl,--no-whole-archive"
110
- ${SYSTEM_SHARED_LIBS}
111
- )
112
- endif ( APPLE )
105
+ target_link_libraries (_moose
106
+ "-Wl,--whole-archive"
107
+ ${MOOSE_LIBRARIES}
108
+ ${STATIC_LIBRARIES}
109
+ "-Wl,--no-whole-archive"
110
+ ${SYSTEM_SHARED_LIBS} )
111
+ endif ( )
112
+
113
113
add_custom_command (TARGET _moose POST_BUILD
114
114
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan
115
115
"MOOSE python extention is successfully built. Now "
116
116
" Run 'sudo make install' to install it. "
117
117
" "
118
118
"NOTE: Run 'pip uninstall moose' to uninstall moose."
119
- VERBATIM
120
- )
119
+ VERBATIM )
121
120
0 commit comments