1- cmake_minimum_required (VERSION 2.8)
2- include ( ${CMAKE_CURRENT_SOURCE_DIR} /../CheckCXXCompiler.cmake)
1+ include (${CMAKE_CURRENT_SOURCE_DIR} /../CheckCXXCompiler.cmake)
32
43set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /../cmake_modules/" )
54
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 ()
715
8- # Find Numpy
9- find_package (NumPy REQUIRED)
1016include_directories (${NUMPY_INCLUDE_DIRS} )
11- add_definitions ( -std=c++11 )
17+ add_definitions (-std=c++11)
1218add_definitions (-DUSE_NUMPY)
1319add_definitions (-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION)
1420
1521# set module extensiton. default is .so. Also check ../python/setup.cmake.py
16- execute_process ( COMMAND
22+ execute_process (COMMAND
1723 ${PYTHON_EXECUTABLE} -c
1824"import importlib.machinery
1925print(importlib.machinery.EXTENSION_SUFFIXES[-1])"
2026 OUTPUT_VARIABLE PYTHON_SO_EXTENSION
21- OUTPUT_STRIP_TRAILING_WHITESPACE
22- )
27+ OUTPUT_STRIP_TRAILING_WHITESPACE)
2328if (NOT PYTHON_SO_EXTENSION)
2429 message (STATUS "Python so ext could not be determined. Using default .so" )
2530 set (PYTHON_SO_EXTENSION ".so" )
@@ -44,38 +49,36 @@ set(PYMOOSE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../python/moose")
4449message (STATUS "Python module will be saved to ${PYMOOSE_OUTPUT_DIRECTORY} " )
4550
4651# 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)
6758
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} " )
6863endif ()
6964
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+
7074# Remove prefix lib from python module.
7175if (NOT (PYTHON_SO_EXTENSION STREQUAL "" ))
7276 set_target_properties (_moose PROPERTIES SUFFIX ${PYTHON_SO_EXTENSION} )
7377endif ()
7478set_target_properties (_moose PROPERTIES
7579 LIBRARY_OUTPUT_DIRECTORY ${PYMOOSE_OUTPUT_DIRECTORY}
7680 PREFIX ""
77- SUFFIX ${PYTHON_SO_EXTENSION}
78- )
81+ SUFFIX ${PYTHON_SO_EXTENSION} )
7982
8083# see issue #80
8184if (HDF5_FOUND AND WITH_NSDF)
@@ -85,37 +88,33 @@ endif()
8588if (APPLE )
8689 set (CMAKE_MODULE_LINKER_FLAGS "-undefined dynamic_lookup" )
8790 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
9292 set_target_properties ( _moose PROPERTIES MACOSX_RPATH OFF )
9393endif (APPLE )
9494
9595if (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+ )
104104else (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+
113113add_custom_command (TARGET _moose POST_BUILD
114114 COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan
115115 "MOOSE python extention is successfully built. Now "
116116 " Run 'sudo make install' to install it. "
117117 " "
118118 "NOTE: Run 'pip uninstall moose' to uninstall moose."
119- VERBATIM
120- )
119+ VERBATIM )
121120
0 commit comments