forked from elalish/manifold
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
304 lines (278 loc) · 8.35 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
# Copyright 2020 The Manifold Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.18)
project(manifold LANGUAGES CXX)
# Use C++17
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_VERBOSE_MAKEFILE ON)
include(GNUInstallDirs)
include(CMakeDependentOption)
# Define Manifold version
set(MANIFOLD_VERSION_MAJOR 3)
set(MANIFOLD_VERSION_MINOR 0)
set(MANIFOLD_VERSION_PATCH 0)
set(
MANIFOLD_VERSION
"${MANIFOLD_VERSION_MAJOR}.${MANIFOLD_VERSION_MINOR}.${MANIFOLD_VERSION_PATCH}"
)
# Primary user facing options
option(MANIFOLD_CROSS_SECTION "Build CrossSection for 2D support" ON)
option(MANIFOLD_DEBUG "Enable debug tracing/timing" OFF)
option(
MANIFOLD_DOWNLOADS
"Allow Manifold build to download missing dependencies"
ON
)
option(MANIFOLD_EXPORT "Build mesh export (via assimp) utility library" OFF)
option(MANIFOLD_PAR "Enable Parallel backend" OFF)
option(
MANIFOLD_OPTIMIZED
"Force optimized build, even with debugging enabled"
OFF
)
option(MANIFOLD_TEST "Enable testing suite" ON)
option(MANIFOLD_PYBIND "Build python bindings" OFF)
# MANIFOLD_CBIND is only available when MANIFOLD_CROSS_SECTION is enabled
cmake_dependent_option(
MANIFOLD_CBIND
"Build C (FFI) bindings"
ON
"MANIFOLD_CROSS_SECTION"
OFF
)
# MANIFOLD_JSBIND is only available when building with Emscripten
cmake_dependent_option(
MANIFOLD_JSBIND
"Build js binding"
ON
"EMSCRIPTEN"
OFF
)
# These three options can force the build to avoid using the system version of
# the dependency
# This will either use the provided source directory via
# FETCHCONTENT_SOURCE_DIR_XXX, or fetch the source from GitHub.
# Note that the dependency will be built as static dependency to avoid dynamic
# library conflict.
# When the system package is unavailable, the option will be automatically set
# to true.
option(MANIFOLD_USE_BUILTIN_TBB "Use builtin tbb" OFF)
option(MANIFOLD_USE_BUILTIN_CLIPPER2 "Use builtin clipper2" OFF)
option(MANIFOLD_USE_BUILTIN_NANOBIND "Use builtin nanobind" OFF)
# default to Release build
option(CMAKE_BUILD_TYPE "Build type" Release)
# default to building shared library
option(BUILD_SHARED_LIBS "Build shared library" ON)
# Set some option values in the CMake cache
set(MANIFOLD_FLAGS "" CACHE STRING "Manifold compiler flags")
# Development options
option(TRACY_ENABLE "Use tracy profiling" OFF)
option(TRACY_MEMORY_USAGE "Track memory allocation with tracy (expensive)" OFF)
option(MANIFOLD_FUZZ "Enable fuzzing tests" OFF)
mark_as_advanced(TRACY_ENABLE)
mark_as_advanced(TRACY_MEMORY_USAGE)
mark_as_advanced(MANIFOLD_FUZZ)
# Always build position independent code for relocatability
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Various Compiler Flags
if(MANIFOLD_FUZZ)
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(FATAL_ERROR "fuzztest only supports clang")
endif()
# we should enable debug checks
set(MANIFOLD_DEBUG ON)
# enable fuzztest fuzzing mode
set(FUZZTEST_FUZZING_MODE ON)
# address sanitizer required
add_compile_options(-fsanitize=address)
endif()
if(TRACY_ENABLE)
option(CMAKE_BUILD_TYPE "Build type" RelWithDebInfo)
endif()
if(EMSCRIPTEN)
message("Building for Emscripten")
add_link_options(-sALLOW_MEMORY_GROWTH=1)
add_link_options(-sMAXIMUM_MEMORY=4294967296)
if(MANIFOLD_PAR)
set(CMAKE_THREAD_LIBS_INIT "-pthread")
add_compile_options(-pthread)
# mimalloc is needed for good performance
add_link_options(-sMALLOC=mimalloc)
# The default stack size apparently causes problem when parallelization is
# enabled.
add_link_options(-sSTACK_SIZE=10MB)
endif()
if(MANIFOLD_DEBUG)
list(APPEND MANIFOLD_FLAGS -fexceptions)
add_link_options(-fexceptions)
add_link_options(-sDISABLE_EXCEPTION_CATCHING=0)
endif()
set(MANIFOLD_PYBIND OFF)
set(BUILD_SHARED_LIBS OFF)
endif()
if(CMAKE_EXPORT_COMPILE_COMMANDS AND NOT EMSCRIPTEN)
# for nixos
set(
CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES
${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}
)
endif()
if(MSVC)
list(APPEND MANIFOLD_FLAGS /DNOMINMAX /bigobj)
else()
list(
APPEND
WARNING_FLAGS
-Wall
-Wno-unknown-warning-option
-Wno-unused
-Wno-shorten-64-to-32
)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
list(APPEND WARNING_FLAGS -Wno-format)
endif()
elseif(PROJECT_IS_TOP_LEVEL)
# only do -Werror if we are the top level project
list(APPEND WARNING_FLAGS -Werror)
endif()
list(APPEND MANIFOLD_FLAGS ${WARNING_FLAGS})
if(
MANIFOLD_OPTIMIZED
OR "${CMAKE_BUILD_TYPE}" STREQUAL "Release"
OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo"
)
list(APPEND MANIFOLD_FLAGS -O3)
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
list(APPEND MANIFOLD_FLAGS -fno-omit-frame-pointer)
endif()
if(CODE_COVERAGE)
list(
APPEND
MANIFOLD_FLAGS
-coverage
-fno-inline-small-functions
-fkeep-inline-functions
-fkeep-static-functions
)
add_link_options(-coverage)
endif()
endif()
# RPath settings
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
list(
FIND
CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
isSystemDir
)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
endif("${isSystemDir}" STREQUAL "-1")
include(${PROJECT_SOURCE_DIR}/cmake/manifoldDeps.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/configHelper.cmake)
add_subdirectory(src)
add_subdirectory(bindings)
if(MANIFOLD_TEST)
add_subdirectory(samples)
add_subdirectory(test)
add_subdirectory(extras)
endif()
include(${PROJECT_SOURCE_DIR}/cmake/info.cmake)
# note that the path ${CMAKE_CURRENT_BINARY_DIR}/include is included when we
# build the manifold target (as ${PROJECT_SOURCE_DIR}/include), so users can
# include manifold/version.h without installing our library.
configure_file(
cmake/version.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/manifold/version.h
@ONLY
)
set_source_files_properties(
${CMAKE_CURRENT_BINARY_DIR}/include/manifold/version.h
PROPERTIES GENERATED TRUE
)
# If it's an EMSCRIPTEN build, we're done
if(EMSCRIPTEN)
return()
endif()
# CMake exports
configure_file(
cmake/manifoldConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/manifoldConfig.cmake
@ONLY
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/cmake/manifoldConfigVersion.cmake
VERSION ${MANIFOLD_VERSION}
COMPATIBILITY SameMajorVersion
)
# Location of inputs for CMake find_package - see:
# https://cmake.org/cmake/help/latest/command/find_package.html
set(EXPORT_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake)
install(
EXPORT manifoldTargets
NAMESPACE manifold::
DESTINATION ${EXPORT_INSTALL_DIR}/manifold
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/cmake/manifoldConfigVersion.cmake
${CMAKE_CURRENT_BINARY_DIR}/manifoldConfig.cmake
DESTINATION ${EXPORT_INSTALL_DIR}/manifold
)
# install public headers
set(
MANIFOLD_PUBLIC_HDRS
common.h
linalg.h
manifold.h
optional_assert.h
polygon.h
vec_view.h
$<$<BOOL:${MANIFOLD_CROSS_SECTION}>:cross_section.h>
$<$<BOOL:${MANIFOLD_EXPORT}>:meshIO.h>
)
list(TRANSFORM MANIFOLD_PUBLIC_HDRS PREPEND include/manifold/)
list(
APPEND
MANIFOLD_PUBLIC_HDRS
${CMAKE_CURRENT_BINARY_DIR}/include/manifold/version.h
)
install(
FILES ${MANIFOLD_PUBLIC_HDRS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/manifold
)
# PkgConfig file
if(MANIFOLD_PAR)
set(TEMPLATE_OPTIONAL_TBB "tbb")
endif()
if(MANIFOLD_CROSS_SECTION)
set(TEMPLATE_OPTIONAL_CLIPPER "Clipper2")
endif()
configure_file(
cmake/manifold.pc.in
${CMAKE_CURRENT_BINARY_DIR}/manifold.pc
@ONLY
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/manifold.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)