-
Notifications
You must be signed in to change notification settings - Fork 93
/
CMakeLists.txt
231 lines (205 loc) · 10.8 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
cmake_minimum_required(VERSION 3.18) # For FindPython.cmake Development.Module
project(CGAL-bindings)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/SWIG_CGAL_Macros.cmake)
find_package(CGAL REQUIRED OPTIONAL_COMPONENTS ImageIO)
find_package(SWIG REQUIRED)
option( BUILD_PYTHON "Build Python bindings" ON )
option( BUILD_JAVA "Build Java bindings" ON )
#set it to OFF by default while it is not fully tested and thus officially supported
option( BUILD_RUBY "Build Ruby bindings" OFF )
enable_testing ()
add_custom_target (tests)
if(APPLE)
set(CMAKE_INSTALL_RPATH "@loader_path;@loader_path/../lib;@loader_path/../../..")
else()
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif()
if ( CGAL_FOUND AND ${CGAL_MAJOR_VERSION} GREATER 4 )
find_package( TBB )
if(TBB_FOUND)
if(NOT TARGET Threads::Threads)
find_package(Threads REQUIRED)
endif()
include_directories(${TBB_INCLUDE_DIRS})
add_definitions( -DNOMINMAX -DCGAL_LINKED_WITH_TBB )
else()
message( STATUS "NOTICE: Intel TBB was not found. Parallelism will be disabled." )
endif()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
if(CMAKE_COMPILER_IS_GNUCXX)
message (STATUS "Release mode with g++: using -fno-strict-aliasing flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
endif()
endif()
if (SWIG_FOUND)
SET (UseSWIG ON)
INCLUDE(${SWIG_USE_FILE})
SET(CMAKE_SWIG_FLAGS "-I${CMAKE_CURRENT_SOURCE_DIR}")
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
if (${BUILD_RUBY})
find_package(Ruby)
if (NOT RUBY_FOUND)
message(WARNING "Ruby has not been found, CGAL-bindings for Ruby will not be generated.")
SET(BUILD_RUBY OFF)
endif()
else()
message(STATUS "BUILD_RUBY is set to OFF: no CGAL-bindings for Ruby will be generated.")
endif()
if (${BUILD_PYTHON})
find_package(Python COMPONENTS Interpreter Development.Module)
if (NOT Python_FOUND)
SET(BUILD_PYTHON OFF)
message(WARNING "Python has not been found, CGAL-bindings for Python will not be generated.")
endif()
else()
message(STATUS "BUILD_PYTHON is set to OFF: no CGAL-bindings for Python will be generated.")
endif()
if (${BUILD_JAVA})
find_package(JNI)
if (NOT JAVA_INCLUDE_PATH)
message(WARNING "JNI has not been found, CGAL-bindings for Java will not be generated.")
SET(BUILD_JAVA OFF)
endif()
else()
message(STATUS "BUILD_JAVA is set to OFF: no CGAL-bindings for Java will be generated.")
endif()
SET (COMMON_LIBRARIES_PATH "${CMAKE_CURRENT_BINARY_DIR}/lib" CACHE PATH "Path where libraries common to all target languages are created.")
if (RUBY_FOUND)
SET (RUBY_OUTDIR_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/build-ruby" CACHE PATH "RUBY specific files output directory prefix: the CGAL directory will contain Ruby generated files and libraries.")
LINK_DIRECTORIES("${RUBY_OUTDIR_PREFIX}/CGAL")
message(STATUS "Found Ruby libs.")
message(STATUS "CGAL-SWIG Ruby files and libraries will be written in ${RUBY_OUTDIR_PREFIX}/CGAL.")
endif()
if (BUILD_PYTHON)
set (PYTHON_OUTDIR_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/build-python" CACHE PATH "PYTHON specific files output directory prefix: the CGAL directory will contain Python generated files and libraries.")
configure_file (SWIG_CGAL/files/__init__.py "${PYTHON_OUTDIR_PREFIX}/CGAL/__init__.py" @ONLY)
if (Python_EXECUTABLE)
file (GLOB python_files "${CMAKE_SOURCE_DIR}/examples/python/*.py")
# exclude blocking matplotlib plotting example
list (REMOVE_ITEM python_files ${CMAKE_SOURCE_DIR}/examples/python/polygonal_triangulation.py)
# exclude Intel TBB dependent example
list (REMOVE_ITEM python_files ${CMAKE_SOURCE_DIR}/examples/python/Classification_example.py)
foreach (TESTNAME_SRC ${python_files})
get_filename_component (TESTNAME ${TESTNAME_SRC} NAME_WE)
add_test (NAME pythontest_${TESTNAME} COMMAND ${Python_EXECUTABLE} ${TESTNAME_SRC})
set_tests_properties (pythontest_${TESTNAME} PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_OUTDIR_PREFIX};DATADIR=${CMAKE_CURRENT_SOURCE_DIR}/examples/data")
endforeach ()
endif()
if (NOT DEFINED PYTHON_MODULE_PATH)
if(Python_VERSION VERSION_LESS 3.12)
execute_process (COMMAND ${Python_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(plat_specific=True, prefix='${CMAKE_INSTALL_PREFIX}'))"
OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH
RESULT_VARIABLE _exit_code
OUTPUT_STRIP_TRAILING_WHITESPACE )
if (NOT ${_exit_code})
get_filename_component (_ABS_PYTHON_MODULE_PATH ${_ABS_PYTHON_MODULE_PATH} ABSOLUTE)
file (RELATIVE_PATH _REL_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH})
set (PYTHON_MODULE_PATH ${_REL_PYTHON_MODULE_PATH})
endif()
else()
execute_process (COMMAND ${Python_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_path('platlib').removeprefix('/usr/local').removeprefix(sysconfig.get_config_var('base')).removeprefix(sysconfig.get_config_var('platbase')).removeprefix(sysconfig.get_config_var('installed_base')).removeprefix('/'))"
OUTPUT_VARIABLE PYTHON_MODULE_PATH
RESULT_VARIABLE _exit_code
OUTPUT_STRIP_TRAILING_WHITESPACE )
endif()
message(NOTICE "Python module path is ${PYTHON_MODULE_PATH}")
if(_exit_code)
message (SEND_ERROR "Could not run ${Python_EXECUTABLE}")
endif ()
endif()
#if not, libs will be installed in python/lib64/python/CGAL instead of python/CGAL
if(${INSTALL_FROM_SETUP})
set (PYTHON_MODULE_PATH ".")
endif()
#TEMP : this part is kept in case the windows installation is broken.
# if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# set(PYTHON_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/python_install" CACHE PATH "Path to modules after installation")
# else()
# set(PYTHON_MODULE_PATH "${Python_SITEARCH}" CACHE PATH "Path to modules after installation")
#endif()
install (FILES ${PYTHON_OUTDIR_PREFIX}/CGAL/__init__.py DESTINATION ${PYTHON_MODULE_PATH}/CGAL)
LINK_DIRECTORIES("${PYTHON_OUTDIR_PREFIX}/CGAL")
message(STATUS "Found Python libs.")
message(STATUS "CGAL-SWIG Python files and libraries will be written in ${PYTHON_OUTDIR_PREFIX}/CGAL.")
endif()
if (BUILD_JAVA)
SET (JAVA_OUTDIR_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/build-java/" CACHE PATH "Java specific files output directory prefix: Java files in CGAL directory, libraries in lib directory.")
SET (JAVALIBPATH "${JAVA_OUTDIR_PREFIX}/lib")
message(STATUS "Found JNI: JNI include dirs ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2}.")
message(STATUS "CGAL-SWIG Java libraries and files will be respectively written in ${JAVALIBPATH} and ${JAVA_OUTDIR_PREFIX}/CGAL.")
find_package (Java)
if (JAVA_FOUND)
file (GLOB java_files "${CMAKE_CURRENT_SOURCE_DIR}/examples/java/*.java")
set (dependencies Mesh2Criteria Mesh3FacetCriteria Mesh3CellCriteria)
set (dependencies_files)
foreach (TESTNAME ${dependencies})
list (APPEND dependencies_files ${CMAKE_CURRENT_SOURCE_DIR}/examples/java/${TESTNAME}.java)
endforeach ()
foreach (TESTNAME ${dependencies})
list (REMOVE_ITEM java_files ${CMAKE_CURRENT_SOURCE_DIR}/examples/java/${TESTNAME}.java)
endforeach ()
foreach (TESTNAME_SRC ${java_files})
get_filename_component(TESTNAME ${TESTNAME_SRC} NAME_WE)
if(CGAL_ImageIO_FOUND OR NOT "${TESTNAME}" STREQUAL "test_surface_mesher")
add_custom_target (javatest_${TESTNAME}
COMMAND ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=${JAVALIBPATH}" "DYLD_LIBRARY_PATH=${JAVALIBPATH}" ${Java_JAVAC_EXECUTABLE} ${TESTNAME_SRC} ${dependencies_files} -d ${JAVA_OUTDIR_PREFIX}
WORKING_DIRECTORY ${JAVA_OUTDIR_PREFIX})
add_dependencies (tests javatest_${TESTNAME})
add_test (NAME javatest_${TESTNAME} COMMAND ${Java_JAVA_EXECUTABLE} ${TESTNAME} WORKING_DIRECTORY ${JAVA_OUTDIR_PREFIX})
set_tests_properties (javatest_${TESTNAME} PROPERTIES
ENVIRONMENT "LD_LIBRARY_PATH=${JAVALIBPATH};DYLD_LIBRARY_PATH=${JAVALIBPATH}")
endif()
endforeach ()
# tests load files from source dir, eg: ../data/oni.xyz
file (COPY examples/data DESTINATION ${JAVA_OUTDIR_PREFIX}/..)
endif ()
endif()
MESSAGE(STATUS "Now adding packages")
add_subdirectory(SWIG_CGAL/Kernel)
add_subdirectory(SWIG_CGAL/Java)
add_subdirectory(SWIG_CGAL/Triangulation_3)
add_subdirectory(SWIG_CGAL/Triangulation_2)
add_subdirectory(SWIG_CGAL/Polyhedron_3)
add_subdirectory(SWIG_CGAL/Alpha_shape_2)
add_subdirectory(SWIG_CGAL/Alpha_wrap_3)
add_subdirectory(SWIG_CGAL/Spatial_searching)
add_subdirectory(SWIG_CGAL/AABB_tree)
if (CGAL_ImageIO_FOUND)
add_subdirectory(SWIG_CGAL/Surface_mesher)
else()
message(STATUS "NOTICE: CGAL imageIO has not be found, few bindings will not be compiled")
endif()
add_subdirectory(SWIG_CGAL/Mesh_3)
add_subdirectory(SWIG_CGAL/Mesh_2)
add_subdirectory(SWIG_CGAL/Interpolation)
add_subdirectory(SWIG_CGAL/Convex_hull_2)
add_subdirectory(SWIG_CGAL/Convex_hull_3)
add_subdirectory(SWIG_CGAL/Voronoi_diagram_2)
add_subdirectory(SWIG_CGAL/HalfedgeDS)
add_subdirectory(SWIG_CGAL/Point_set_3)
add_subdirectory(SWIG_CGAL/Point_set_processing_3)
add_subdirectory(SWIG_CGAL/Shape_detection)
add_subdirectory(SWIG_CGAL/Classification)
add_subdirectory(SWIG_CGAL/Box_intersection_d)
add_subdirectory(SWIG_CGAL/Advancing_front_surface_reconstruction)
find_package(Eigen3 3.2.0) #(requires 3.2.0 or greater)
if (EIGEN3_FOUND)
include(CGAL_Eigen3_support)
add_subdirectory(SWIG_CGAL/Polygon_mesh_processing)
else()
message(STATUS "Eigen 3.2 or later was not found, Polygon_mesh_processing bindings will not be available")
endif(EIGEN3_FOUND)
if(CGAL_VERSION VERSION_GREATER_EQUAL 6.0 AND CMAKE_CXX_COMPILER_ID STREQUAL AppleClang)
target_compile_options(CGAL_Kernel_cpp PUBLIC -mmacosx-version-min=10.13)
endif()
add_subdirectory(SWIG_CGAL/Polyline_simplification_2)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/SWIG_CGAL/User_packages/CMakeLists.txt")
message(STATUS "Found SWIG_CGAL/User_packages/CMakeLists.txt, user packages will be built.")
add_subdirectory(SWIG_CGAL/User_packages)
endif()
else()
message(STATUS "NOTICE: CGAL-bindings requires the SWIG include files and binary program, and will not be compiled.")
endif()
else()
message(STATUS "NOTICE: CGAL-bindings requires the CGAL library 5.0 or later, and will not be compiled.")
endif()