-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
179 lines (157 loc) · 5.32 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
cmake_minimum_required(VERSION 3.18) # Needed to avoid requiring embedded Python libs too
project(pyforfluids
VERSION 0.0.2
DESCRIPTION "PyForFluids Fortran Modules"
LANGUAGES C Fortran
)
option(SKBUILD "Should be ON of being build by skbuild,
and OFF of being build by regular cmake" OFF)
if (NOT SKBUILD)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/../cmake/")
endif()
# Safety net
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(
FATAL_ERROR
"In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.\n"
)
endif()
# Grab Python, 3.8 or newer
find_package(Python 3.7 REQUIRED
COMPONENTS Interpreter Development.Module NumPy)
find_package(PythonExtensions REQUIRED)
# Grab the variables from a local Python installation
# F2PY headers
execute_process(
COMMAND "${Python_EXECUTABLE}"
-c "import numpy.f2py; print(numpy.f2py.get_include())"
OUTPUT_VARIABLE F2PY_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Print out the discovered paths
include(CMakePrintHelpers)
cmake_print_variables(Python_INCLUDE_DIRS)
cmake_print_variables(F2PY_INCLUDE_DIR)
cmake_print_variables(Python_NumPy_INCLUDE_DIRS)
if (UNIX)
set(F2PY_CMD ${Python_EXECUTABLE} -m "numpy.f2py")
else()
set(F2PY_CMD ${Python_EXECUTABLE} -m "numpy.f2py" --fcompiler=gnu95 --compiler=mingw32)
endif()
# =============================================================================
# fgerg2008 module
# =============================================================================
message(STATUS "Compiling fortran gerg2008...")
set(f2py_module_name "fgerg2008")
set(f2py_module_dir "pyforfluids/fortran")
set(
fortran_src_file
"${CMAKE_SOURCE_DIR}/pyforfluids/fortran/parameters.f90"
"${CMAKE_SOURCE_DIR}/pyforfluids/fortran/gerg.f90"
)
set(
generated_module_file
${CMAKE_CURRENT_BINARY_DIR}/${f2py_module_name}${PYTHON_EXTENSION_MODULE_SUFFIX}
)
add_custom_target(${f2py_module_name} ALL
DEPENDS ${generated_module_file}
)
add_custom_command(
OUTPUT ${generated_module_file}
COMMAND
${F2PY_CMD}
-m ${f2py_module_name}
-c
${fortran_src_file}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${fortran_src_file}
)
if (SKBUILD)
install(FILES ${generated_module_file} DESTINATION ${f2py_module_dir})
else()
install(FILES ${generated_module_file} DESTINATION ${f2py_module_dir})
endif()
# =============================================================================
# =============================================================================
# fthermo_props module
# =============================================================================
message(STATUS "Compiling fortran thermoprops...")
set(f2py_module_name "fthermo_props")
set(f2py_module_dir "pyforfluids/fortran")
set(
fortran_src_file
"${CMAKE_SOURCE_DIR}/pyforfluids/fortran/parameters.f90"
"${CMAKE_SOURCE_DIR}/pyforfluids/fortran/thermoprops.f90"
)
set(
generated_module_file
${CMAKE_CURRENT_BINARY_DIR}/${f2py_module_name}${PYTHON_EXTENSION_MODULE_SUFFIX}
)
add_custom_target(${f2py_module_name} ALL
DEPENDS ${generated_module_file}
)
add_custom_command(
OUTPUT ${generated_module_file}
COMMAND
${F2PY_CMD}
-m ${f2py_module_name}
-c
${fortran_src_file}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${fortran_src_file}
)
if (SKBUILD)
install(FILES ${generated_module_file} DESTINATION ${f2py_module_dir})
else()
install(FILES ${generated_module_file} DESTINATION ${f2py_module_dir})
endif()
# =============================================================================
# =============================================================================
# pyfeos module
# =============================================================================
set(FEOSDIR "pyforfluids/fortran/feos")
set(FORTRAN_DIR "pyforfluids/fortran")
message(STATUS "Compiling fortran feos library...")
add_library(feos STATIC
${CMAKE_SOURCE_DIR}/${FEOSDIR}/src/constants.f90
${CMAKE_SOURCE_DIR}/${FEOSDIR}/src/properties.f90
${CMAKE_SOURCE_DIR}/${FEOSDIR}/src/cubic/base.f90
${CMAKE_SOURCE_DIR}/${FEOSDIR}/src/cubic/cubic_eos.f90
${CMAKE_SOURCE_DIR}/${FEOSDIR}/src/mixing_rules.f90
${CMAKE_SOURCE_DIR}/${FEOSDIR}/src/fluid.f90
${CMAKE_SOURCE_DIR}/${FEOSDIR}/interface.f90
)
set_property(TARGET feos PROPERTY POSITION_INDEPENDENT_CODE ON)
install(
TARGETS feos
LIBRARY DESTINATION ${f2py_module_dir}#${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${f2py_module_dir}#${CMAKE_INSTALL_INCLUDEDIR}
)
message(STATUS "Compiling fortran pyfeos module...")
set(f2py_module_name "pyfeos")
set(f2py_module_dir "${FORTRAN_DIR}")
set(
fortran_src_file
"${CMAKE_SOURCE_DIR}/${FEOSDIR}/pyfeos.f90"
)
set(
generated_module_file
${CMAKE_CURRENT_BINARY_DIR}/${f2py_module_name}${PYTHON_EXTENSION_MODULE_SUFFIX}
)
add_custom_target(
${f2py_module_name}
ALL DEPENDS ${generated_module_file}
)
add_custom_command(
OUTPUT ${generated_module_file}
COMMAND
${F2PY_CMD}
-L${CMAKE_CURRENT_BINARY_DIR} -lfeos
-c -m ${f2py_module_name}
${fortran_src_file}
only: ar
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${fortran_src_file} feos
)
install(FILES ${generated_module_file} DESTINATION ${f2py_module_dir})
# =============================================================================