-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
72 lines (60 loc) · 2.28 KB
/
Copy pathCMakeLists.txt
File metadata and controls
72 lines (60 loc) · 2.28 KB
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
cmake_minimum_required(VERSION 3.15...3.27)
project(pyhwm2014 LANGUAGES Fortran C)
# Find Python
find_package(Python 3.12 COMPONENTS Interpreter Development REQUIRED)
# Get NumPy location
execute_process(
COMMAND ${Python_EXECUTABLE} -c "import numpy; print(numpy.get_include())"
OUTPUT_VARIABLE NUMPY_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT NUMPY_INCLUDE_DIR)
message(FATAL_ERROR "Could not find NumPy")
endif()
# Set f2py command
set(F2PY_EXECUTABLE ${Python_EXECUTABLE} -m numpy.f2py)
# Source files and interface
set(F90_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/source/hwm14.f90)
set(F2PY_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/source/reference/hwm14.pyf)
set(PACKAGE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/pyhwm2014)
# Get the extension suffix from Python
execute_process(
COMMAND ${Python_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"
OUTPUT_VARIABLE EXTENSION_SUFFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# The extension will be built directly in the pyhwm2014 directory
set(HWM14_EXTENSION ${PACKAGE_DIR}/hwm14${EXTENSION_SUFFIX})
message(STATUS "Python: ${Python_EXECUTABLE}")
message(STATUS "NumPy include: ${NUMPY_INCLUDE_DIR}")
message(STATUS "Extension suffix: ${EXTENSION_SUFFIX}")
message(STATUS "Output location: ${HWM14_EXTENSION}")
# Build the hwm14 extension module using f2py directly in pyhwm2014/
# f2py -c outputs the .so file to the current working directory
add_custom_command(
OUTPUT ${HWM14_EXTENSION}
COMMAND ${F2PY_EXECUTABLE}
-m hwm14
-c
${F2PY_INTERFACE}
${F90_SOURCE}
-I${NUMPY_INCLUDE_DIR}
WORKING_DIRECTORY ${PACKAGE_DIR}
DEPENDS ${F2PY_INTERFACE} ${F90_SOURCE}
COMMENT "Building hwm14 Fortran extension with f2py"
VERBATIM
)
# Create a target that depends on the extension
add_custom_target(hwm14_ext ALL DEPENDS ${HWM14_EXTENSION})
# Install the generated .so file. The previous file(GLOB_RECURSE) ran at
# configure time (before the build produced the .so) and looked in the wrong
# directory (BINARY_DIR vs PACKAGE_DIR), so install(FILES ...) silently
# received an empty list and the OPTIONAL flag swallowed the error.
install(PROGRAMS ${HWM14_EXTENSION} DESTINATION pyhwm2014)
# Install data files
install(FILES
data/dwm07b104i.dat
data/gd2qd.dat
data/hwm123114.bin
DESTINATION pyhwm2014/data
)