forked from trelau/pyOCCT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
324 lines (269 loc) · 11.1 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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# This file is part of pyOCCT which provides Python bindings to the OpenCASCADE
# geometry kernel.
#
# Copyright (C) 2016-2018 Laughlin Research, LLC ([email protected])
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cmake_minimum_required(VERSION 3.0)
project(pyOCCT VERSION 7.2.0.1 LANGUAGES CXX)
# --------------------------------------------------------------------------- #
# OPTIONS
# --------------------------------------------------------------------------- #
option(ENABLE_SMESH "Enable SMESH" OFF)
option(ENABLE_NETGEN "Enable Netgen" OFF)
option(ENABLE_BLSURF "Enable BLSURF" OFF)
option(ENABLE_FORCE "Force build even if unresolved externals are found" OFF)
option(ENABLE_WARNINGS "Disable warning output." OFF)
option(TEST_BUILD "Build a subset of modules for testing." OFF)
# --------------------------------------------------------------------------- #
# SETTINGS
# --------------------------------------------------------------------------- #
set(pyOCCT_MAJOR_VERSION 7)
set(pyOCCT_MINOR_VERSION 2)
set(pyOCCT_PATCH_VERSION 0)
set(pyOCCT_TWEAK_VERSION 1)
if(WIN32)
set(EXTENSION ".pyd")
else(WIN32)
set(EXTENSION ".so")
endif(WIN32)
# Use /FORCE to ignore unresolved externals (known issue)
if(ENABLE_FORCE)
message(STATUS "Using /FORCE linker option.")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /FORCE")
endif(ENABLE_FORCE)
# Use Link Time Optimization per pybind11 documentation
if(MSVC)
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /LTCG")
endif(MSVC)
# Known warnings
if(NOT ENABLE_WARNINGS)
if(WIN32)
set(WARNINGS "/wd4996 /wd4800 /wd4267 /wd4275 /wd4251 /wd4805 /wd4290 /wd4005 /wd4180 /wd4244 /wd4146 /wd4172")
else(WIN32)
set(WARNINGS "-Wall -Wno-deprecated-declarations -Wno-strict-aliasing")
endif(WIN32)
else(NOT ENABLE_WARNINGS)
set(WARNINGS)
endif(NOT ENABLE_WARNINGS)
# --------------------------------------------------------------------------- #
# OpenCASCADE
# --------------------------------------------------------------------------- #
# Include cmake list of modules
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/OCCT_Mods.cmake)
if(NOT DEFINED OpenCASCADE_INCLUDE_DIR OR NOT DEFINED OpenCASCADE_LIBRARY_DIR)
message(STATUS "Searching for OpenCASCADE...")
find_package(OpenCASCADE 7.2.0 REQUIRED)
endif()
if(NOT EXISTS ${OpenCASCADE_INCLUDE_DIR})
message(FATAL_ERROR "Failed to find OpenCASCADE include directory.")
endif()
if(NOT EXISTS ${OpenCASCADE_LIBRARY_DIR})
message(FATAL_ERROR "Failed to find OpenCASCADE library directory.")
endif()
message(STATUS "OpenCASCADE include directory: ${OpenCASCADE_INCLUDE_DIR}")
message(STATUS "OpenCASCADE library directory: ${OpenCASCADE_LIBRARY_DIR}")
include_directories(${OpenCASCADE_INCLUDE_DIR})
link_directories(${OpenCASCADE_LIBRARY_DIR})
# --------------------------------------------------------------------------- #
# NETGEN
# --------------------------------------------------------------------------- #
if(ENABLE_NETGEN AND ENABLE_SMESH)
if(NOT DEFINED NETGEN_INCLUDE_DIR)
message(STATUS "Searching for Netgen...")
find_package(Netgen REQUIRED)
endif()
if(NOT EXISTS ${NETGEN_INCLUDE_DIR})
message(FATAL_ERROR "Failed to find Netgen include directory.")
endif()
message(STATUS "Netgen include directory: ${NETGEN_INCLUDE_DIR}")
include_directories(${NETGEN_INCLUDE_DIR})
endif()
# --------------------------------------------------------------------------- #
# SMESH
# --------------------------------------------------------------------------- #
# Include cmake list of modules
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SMESH_Mods.cmake)
set(SMESH_ABS_LIBS)
if(ENABLE_SMESH)
if(NOT DEFINED SMESH_INCLUDE_PATH OR NOT DEFINED SMESH_LIB_PATH)
message(STATUS "Searching for SMESH...")
find_package(SMESH REQUIRED)
endif()
if(NOT EXISTS ${SMESH_INCLUDE_PATH})
message(FATAL_ERROR "Failed to find SMESH include directory.")
endif()
if(NOT EXISTS ${SMESH_LIB_PATH})
message(FATAL_ERROR "Failed to find SMESH library directory.")
endif()
if(NOT DEFINED SMESH_LIBRARIES)
message(FATAL_ERROR "SMESH libraries were not found.")
else()
message(STATUS "SMESH libraries: ${SMESH_LIBRARIES}")
endif()
message(STATUS "SMESH include directory: ${SMESH_INCLUDE_PATH}")
message(STATUS "SMESH library directory: ${SMESH_LIB_PATH}")
include_directories(${SMESH_INCLUDE_PATH})
link_directories(${SMESH_LIB_PATH})
# Build full library paths since they have the same name as the Python
# libraries
foreach(LIB ${SMESH_LIBRARIES})
set(FOUND_LIB "FOUND_LIB-NOTFOUND")
find_library(FOUND_LIB ${LIB} PATHS ${SMESH_LIB_PATH})
list(APPEND SMESH_ABS_LIBS ${FOUND_LIB})
endforeach(LIB)
unset(FOUND_LIB CACHE)
endif()
# --------------------------------------------------------------------------- #
# VTK
# --------------------------------------------------------------------------- #
if(NOT DEFINED VTK_INCLUDE_DIRS)
message(STATUS "Searching for VTK...")
find_package(VTK REQUIRED)
endif()
message(STATUS "VTK include directory: ${VTK_INCLUDE_DIRS}")
include_directories(${VTK_INCLUDE_DIRS})
# --------------------------------------------------------------------------- #
# BOOST
# --------------------------------------------------------------------------- #
if(NOT DEFINED Boost_INCLUDE_DIR)
message(STATUS "Searching for Boost...")
find_package(Boost REQUIRED)
endif()
if(NOT EXISTS ${Boost_INCLUDE_DIR})
message(FATAL_ERROR "Failed to find Boost include directory.")
endif()
message(STATUS "Boost include directory: ${Boost_INCLUDE_DIR}")
include_directories(${Boost_INCLUDE_DIR})
# --------------------------------------------------------------------------- #
# PTHREAD
# --------------------------------------------------------------------------- #
if(ENABLE_SMESH)
set(PTHREAD_INCLUDE_DIRS "" CACHE PATH "pthread include directory.")
if(NOT EXISTS ${PTHREAD_INCLUDE_DIRS})
message(FATAL_ERROR "pthread include directory is required.")
endif()
message(STATUS "pthread include directory: ${PTHREAD_INCLUDE_DIRS}")
include_directories(${PTHREAD_INCLUDE_DIRS})
endif()
# --------------------------------------------------------------------------- #
# BLSURF
# --------------------------------------------------------------------------- #
if(ENABLE_BLSURF AND ENABLE_SMESH)
set(MESHGEMS_INCLUDE "" CACHE PATH "MeshGems include directory.")
if(NOT EXISTS ${MESHGEMS_INCLUDE})
message(FATAL_ERROR "MeshGems include directory is required.")
endif()
message(STATUS "MeshGems include directory: ${MESHGEMS_INCLUDE}")
include_directories(${MESHGEMS_INCLUDE})
endif()
# --------------------------------------------------------------------------- #
# PYBIND11
# --------------------------------------------------------------------------- #
IF(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/pybind11")
message(STATUS "Adding pybind11 subdirectory.")
add_subdirectory(pybind11)
ELSE()
message(STATUS "Searching for pybind11...")
find_package(pybind11 REQUIRED)
ENDIF()
# --------------------------------------------------------------------------- #
# pyOCCT
# --------------------------------------------------------------------------- #
include_directories(inc)
set(OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_PATH}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_PATH}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_PATH}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_PATH}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_PATH}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_PATH}")
# Subset of modules to build when TEST_BUILD is ON
set(TEST_MODULES AIS;
Aspect;
BRep;
BRepBuilderAPI;
BRepTools;
Geom;
gp;
Graphic3d;
IGESControl;
MeshVS;
OpenGl;
Quantity;
SMESH;
STEPControl;
TopoDS;
V3d;
XwWindow)
# Issue warning if TEST_BUILD is ON
if(TEST_BUILD)
message(WARNING "WARNING: TEST_BUILD mode. Not all modules will be generated.")
endif()
# OCCT modules
set(MAKE_LIB BOOL ON)
foreach(MOD ${OCCT_MODULES})
# Check for test modules
list(FIND TEST_MODULES ${MOD} _INDEX)
if(TEST_BUILD AND NOT ${_INDEX} GREATER -1)
set(MAKE_LIB OFF)
endif()
# Check for platform-specific modules
if((WIN32 AND (${MOD} STREQUAL "XwWindow"))
OR ((NOT WIN32) AND (${MOD} STREQUAL "WNT")))
message(STATUS "Skipping platform-specific module ${MOD}")
set(MAKE_LIB OFF)
endif()
if(MAKE_LIB)
file(GLOB SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/${MOD}.* ${CMAKE_CURRENT_SOURCE_DIR}/src/${MOD}_*)
pybind11_add_module(${MOD} ${SRCS})
target_link_libraries(${MOD} PUBLIC ${OpenCASCADE_LIBRARIES})
set_target_properties(${MOD} PROPERTIES SUFFIX ${EXTENSION} COMPILE_FLAGS ${WARNINGS})
install(FILES ${OUTPUT_PATH}/${MOD}${EXTENSION}
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/OCCT)
endif()
set(MAKE_LIB ON)
endforeach()
# SMESH modules
if(ENABLE_SMESH)
set(MAKE_LIB BOOL ON)
foreach(MOD ${SMESH_MODULES})
# Check for test modules
list(FIND TEST_MODULES ${MOD} _INDEX)
if(TEST_BUILD AND NOT ${_INDEX} GREATER -1)
set(MAKE_LIB OFF)
endif()
# Check Netgen
if(NOT ENABLE_NETGEN AND ${MOD} STREQUAL "NETGENPlugin" AND MAKE_LIB)
message(STATUS "Skipping ${MOD}")
set(MAKE_LIB OFF)
endif()
# Check BLSURF
if(NOT ENABLE_BLSURF AND ${MOD} STREQUAL "BLSURFPlugin" AND MAKE_LIB)
message(STATUS "Skipping ${MOD}")
set(MAKE_LIB OFF)
endif()
if(MAKE_LIB)
file(GLOB SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/${MOD}.* ${CMAKE_CURRENT_SOURCE_DIR}/src/${MOD}_*)
pybind11_add_module(${MOD} ${SRCS})
target_link_libraries(${MOD} PUBLIC ${OpenCASCADE_LIBRARIES}
${SMESH_ABS_LIBS})
set_target_properties(${MOD} PROPERTIES SUFFIX ${EXTENSION} COMPILE_FLAGS ${WARNINGS})
install(FILES ${OUTPUT_PATH}/${MOD}${EXTENSION}
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/OCCT)
endif()
set(MAKE_LIB ON)
endforeach()
endif()