-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
220 lines (171 loc) · 6.83 KB
/
CMakeLists.txt
File metadata and controls
220 lines (171 loc) · 6.83 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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
########################################################################
# CMakeLists.txt
#
# Author: Matthias Moller
# Copyright (C) 2021-2025 by the IgaNet authors
#
# This file is part of the IgaNet project
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# CMakeLists.txt accepts the following command line parameters
#
# PYIGANET_COEFF_TYPE
#
########################################################################
cmake_minimum_required (VERSION 3.24)
include(FetchContent)
########################################################################
#
# Project: IgANet-Python
#
########################################################################
project(IgANet-Python)
add_library(iganet_python INTERFACE)
add_library(iganet::python ALIAS iganet_python)
target_include_directories(iganet_python INTERFACE ${PROJECT_BINARY_DIR}/pyiganet/csrc ${PROJECT_SOURCE_DIR}/pyiganet/csrc)
########################################################################
# IgANets (core)
########################################################################
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
FetchContent_Declare(
iganet_core
GIT_REPOSITORY https://github.com/iganets/iganet.git
GIT_TAG main
)
else()
FetchContent_Declare(
iganet_core
URL https://github.com/iganets/iganet/archive/refs/heads/main.zip
)
endif()
FetchContent_MakeAvailable(iganet_core)
FetchContent_GetProperties(iganet_core)
######################################################################
# Set C++ standard
######################################################################
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
######################################################################
# Find libtorch_python library
######################################################################
find_package(Torch)
set(TORCH_LIBRARIES "")
append_torchlib_if_found(torch_python)
target_link_libraries(iganet_python INTERFACE ${TORCH_LIBRARIES})
endif()
########################################################################
# Pybind11
########################################################################
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(pybind11)
########################################################################
# Options
########################################################################
# Set a default coefficient numeric types if not specified
if(NOT PYIGANET_COEFF_TYPE)
set(PYIGANET_COEFF_TYPE double CACHE STRING
"Coefficient type(float, double)" FORCE)
endif()
set_property(CACHE PYIGANET_COEFF_TYPE PROPERTY STRINGS "float" "double")
message("")
message("PyIgANet options:")
message("PYIGANET_COEFF_TYPE................: ${PYIGANET_COEFF_TYPE}")
message("")
########################################################################
# Auto-generate source files
########################################################################
# Clean output directory
file(GLOB_RECURSE FILES_AND_DIRS "${PROJECT_BINARY_DIR}/pyiganet/*")
foreach(ITEM ${FILES_AND_DIRS})
file(REMOVE_RECURSE ${ITEM})
endforeach()
# Config
configure_file(${PROJECT_SOURCE_DIR}/pyiganet/csrc/pyconfig.hpp.in
${PROJECT_BINARY_DIR}/pyiganet/csrc/pyconfig.hpp @ONLY)
# Create list of PyBind11 init subroutines
list(APPEND init_core "init_options")
# Explicit instantiation of templated blocktensor classes
foreach(ROWS RANGE 1 2)
foreach(COLS RANGE 1 2)
set(SUFFIX "_${ROWS}_${COLS}")
list(APPEND init_core "init_BlockTensor${SUFFIX}")
configure_file(${PROJECT_SOURCE_DIR}/pyiganet/csrc/pyblocktensor.cxx.in
${PROJECT_BINARY_DIR}/pyiganet/csrc/pyblocktensor${SUFFIX}.cxx @ONLY)
endforeach()
endforeach()
# Create list of PyBind11 init subroutines
list(APPEND init_splines "init_bspline")
# Explicit instantiation of templated spline classes
foreach(GEODIM RANGE 1 2)
foreach(DEGREES IN ITEMS
"1" "1,1")# "1,1,1" "1,1,1,1")
# "2" "2,2" "2,2,2" "2,2,2,2"
# "3" "3,3" "3,3,3" "3,3,3,3"
# "4" "4,4" "4,4,4" "4,4,4,4"
# "5" "5,5" "5,5,5" "5,5,5,5")
set(SUFFIX "${GEODIM}d_${DEGREES}")
string(REPLACE "," "_" SUFFIX ${SUFFIX})
list(APPEND init_splines "init_UniformBSpline${SUFFIX}")
string(REPLACE "," ";" PARDIM ${DEGREES})
list(LENGTH PARDIM PARDIM)
configure_file(${PROJECT_SOURCE_DIR}/pyiganet/csrc/pybspline.cxx.in
${PROJECT_BINARY_DIR}/pyiganet/csrc/pybspline${SUFFIX}.cxx @ONLY)
endforeach()
endforeach()
# Create main PyIgANet source file
file(WRITE ${PROJECT_BINARY_DIR}/pyiganet/csrc/pyiganet.cxx
"/**
@file pyiganet/pyiganet.cxx
@brief PyIgANet
@author Matthias Moller
@copyright This file is part of the IgANet project
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <pybind11/pybind11.h>
#include <pyconfig.hpp>
namespace py = pybind11;\n\n")
foreach(init IN LISTS init_core init_splines)
file(APPEND ${PROJECT_BINARY_DIR}/pyiganet/csrc/pyiganet.cxx
"void ${init}(py::module_ &);\n")
endforeach()
file(APPEND ${PROJECT_BINARY_DIR}/pyiganet/csrc/pyiganet.cxx
"\n\n/**
@brief Creates IgANet Python module
*/
PYBIND11_MODULE(pyiganet_core, m) {\n
m.attr(\"__name__\") = \"pyiganet_core\";
m.attr(\"__version__\") = \"${IGANET_VERSION}\";
m.doc() = \"IgANet (Physics-informed isogeometric analysis neural network)\";
py::module core = m.def_submodule(\"core\");
core.attr(\"__name__\") = \"pyiganet_core.core\";
core.attr(\"__version__\") = \"${IGANET_VERSION}\";
core.doc() = \"IgANet (Physics-informed isogeometric analysis neural network): Core module\";
")
foreach(init IN LISTS init_core)
file(APPEND ${PROJECT_BINARY_DIR}/pyiganet/csrc/pyiganet.cxx
"${init}(core);\n")
endforeach()
file(APPEND ${PROJECT_BINARY_DIR}/pyiganet/csrc/pyiganet.cxx
"\n
py::module splines = m.def_submodule(\"splines\");
splines.attr(\"__name__\") = \"pyiganet_core.splines\";
splines.attr(\"__version__\") = \"${IGANET_VERSION}\";
splines.doc() = \"IgANet (Physics-informed isogeometric analysis neural network): Spline module\";
")
foreach(init IN LISTS init_splines)
file(APPEND ${PROJECT_BINARY_DIR}/pyiganet/csrc/pyiganet.cxx
"${init}(splines);\n")
endforeach()
file(APPEND ${PROJECT_BINARY_DIR}/pyiganet/csrc/pyiganet.cxx
"}\n")
file(GLOB SRCS ${PROJECT_SOURCE_DIR}/pyiganet/csrc/*.cxx ${PROJECT_BINARY_DIR}/pyiganet/csrc/*.cxx)
pybind11_add_module(pyiganet_core MODULE ${SRCS})
target_link_libraries(pyiganet_core PRIVATE iganet::core)
target_link_libraries(pyiganet_core PRIVATE iganet::python)