-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathCMakeLists.txt
264 lines (223 loc) · 9.03 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
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
IF(APPLE)
include(ConfigureHomebrew)
ENDIF()
IF(NOT MR_EMSCRIPTEN AND NOT APPLE AND EXISTS /usr/bin/time)
# print compile time of each translation unit in the CSV format (user time, system time, command)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "/usr/bin/time -f \",%U,%S,%C\" -a -o compile_timings.txt")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "/usr/bin/time -f \",%U,%S,%C\" -a -o link_timings.txt")
ENDIF()
project(MeshLib CXX)
add_compile_definitions(MR_PROJECT_NAME=\"MeshLib\")
add_compile_definitions(MR_FRAMEWORK)
add_compile_definitions(IMGUI_USER_CONFIG=\"imgui/MRCustomImGuiConfig.h\")
include(CompilerOptions)
# all binaries will be located in ./build/Release/bin
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
option(MESHLIB_PYTHON_SUPPORT "Python support" ON)
option(MESHLIB_BUILD_MRVIEWER "Build MRViewer library and application" ON)
option(MESHLIB_BUILD_PYTHON_MODULES "Build Python modules" ON)
option(MESHLIB_BUILD_MRMESH_PY_LEGACY "Build legacy Python bindings for MRMesh" OFF)
option(MESHLIB_BUILD_MESHCONV "Build meshconv utility" ON)
option(MESHLIB_BUILD_MRCUDA "Build MRCuda library" ON)
option(MESHLIB_EXPERIMENTAL_BUILD_C_BINDING "(experimental) Build C binding library" ON)
option(MESHLIB_BUILD_SYMBOLMESH "Build symbol-to-mesh library" ON)
option(MESHLIB_BUILD_VOXELS "Build voxels library" ON)
option(MESHLIB_BUILD_EXTRA_IO_FORMATS "Build extra IO format support library" ON)
IF(MR_EMSCRIPTEN OR APPLE)
set(MESHLIB_BUILD_MRCUDA OFF)
ENDIF()
IF(MR_EMSCRIPTEN)
set(MESHLIB_PYTHON_SUPPORT OFF)
set(MESHLIB_BUILD_PYTHON_MODULES OFF)
set(MESHLIB_BUILD_MRMESH_PY_LEGACY OFF)
set(MESHLIB_BUILD_MESHCONV OFF)
ENDIF()
option(MESHLIB_KEEP_CTEST_TARGETS "Keep default CTest targets (Continuous*, Experimental*, Nightly*, etc.)" OFF)
IF(NOT MESHLIB_KEEP_CTEST_TARGETS)
set_property(GLOBAL PROPERTY
CTEST_TARGETS_ADDED 1
)
ENDIF()
include(CTest)
set(MESHLIB_THIRDPARTY_DIR "${PROJECT_SOURCE_DIR}/thirdparty")
set(MESHLIB_THIRDPARTY_ROOT_DIR "${PROJECT_SOURCE_DIR}" CACHE PATH "Thirdparty library location")
IF(NOT EXISTS "${MESHLIB_THIRDPARTY_ROOT_DIR}/include" OR NOT EXISTS "${MESHLIB_THIRDPARTY_ROOT_DIR}/lib")
message("thirdparty build directory not found! You can build thirdparty with ./scripts/build_thirdparty.sh")
ENDIF()
IF(EXISTS "${MESHLIB_THIRDPARTY_ROOT_DIR}/include")
include_directories(${MESHLIB_THIRDPARTY_ROOT_DIR}/include)
ENDIF()
IF(EXISTS "${MESHLIB_THIRDPARTY_ROOT_DIR}/lib")
link_directories(${MESHLIB_THIRDPARTY_ROOT_DIR}/lib)
ENDIF()
IF(APPLE)
# need to hardcode some path to fix wheel (no option to pass path)
# TODO: revise
set(CMAKE_INSTALL_RPATH "@loader_path;@loader_path/..;@loader_path/../lib;@loader_path/../lib/lib;@loader_path/meshlib;${MESHLIB_THIRDPARTY_ROOT_DIR}/lib;${CMAKE_BINARY_DIR}/bin")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
IF(BUILD_TESTING)
set(GTest_DIR ${MESHLIB_THIRDPARTY_ROOT_DIR}/lib/cmake/GTest)
find_package(GTest REQUIRED CONFIG)
include_directories(${GTEST_INCLUDE_DIRS})
ENDIF()
ENDIF()
include(DetectPlatform)
IF(MESHLIB_PYTHON_SUPPORT AND NOT MR_EMSCRIPTEN)
# TODO: drop Python version hard-coding; set -DMESHLIB_PYTHON_VERSION explicitly in the CI config if needed
IF(APPLE)
set(MESHLIB_PYTHON_VERSION "3.10")
ELSEIF(DEFINED MR_LINUX_DISTRO)
IF(${MR_LINUX_DISTRO} STREQUAL "Ubuntu")
set(MESHLIB_PYTHON_VERSION "3.8")
IF(${MR_PLATFORM} STREQUAL "Ubuntu_22")
set(MESHLIB_PYTHON_VERSION "3.10")
ELSEIF(${MR_PLATFORM} STREQUAL "Ubuntu_24")
set(MESHLIB_PYTHON_VERSION "3.12")
ENDIF()
ELSEIF(${MR_LINUX_DISTRO} STREQUAL "Fedora")
set(MESHLIB_PYTHON_VERSION "3.11")
IF(${MR_PLATFORM} STREQUAL "Fedora_39")
set(MESHLIB_PYTHON_VERSION "3.12")
ENDIF()
ENDIF()
ENDIF()
IF($ENV{MESHLIB_PYTHON_VERSION})
set(MESHLIB_PYTHON_VERSION $ENV{MESHLIB_PYTHON_VERSION})
ENDIF()
IF(DEFINED MESHLIB_PYTHON_VERSION)
find_package(Python ${MESHLIB_PYTHON_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development)
ELSE()
find_package(Python REQUIRED COMPONENTS Interpreter Development)
ENDIF()
IF(APPLE)
# TODO: revise
link_directories(${HOMEBREW_PREFIX}/opt/python@${MESHLIB_PYTHON_VERSION}/Frameworks/Python.framework/Versions/${MESHLIB_PYTHON_VERSION}/lib/)
find_package(pybind11 REQUIRED)
ENDIF()
ENDIF()
set(PROJECT_SOURCE_DIR ./source)
include_directories(${PROJECT_SOURCE_DIR})
IF(NOT MR_EMSCRIPTEN)
find_package(PkgConfig REQUIRED)
pkg_check_modules(JSONCPP jsoncpp)
include_directories(${JSONCPP_INCLUDE_DIRS})
find_package(fmt)
find_package(spdlog REQUIRED)
IF(spdlog_VERSION VERSION_GREATER_EQUAL "1.7" AND fmt_VERSION VERSION_GREATER_EQUAL "7.0")
add_compile_definitions(SPDLOG_FMT_EXTERNAL)
ENDIF()
add_compile_definitions(SPDLOG_COMPILED_LIB SPDLOG_SHARED_LIB)
ENDIF() # NOT MR_EMSCRIPTEN
IF(NOT $ENV{MR_VERSION} STREQUAL "")
set(MESHLIB_VERSION $ENV{MR_VERSION})
ELSE()
set(MESHLIB_VERSION 0.0.0)
ENDIF()
message("version: ${MESHLIB_VERSION}")
IF(NOT APPLE)
include(GNUInstallDirs)
set(MR_BIN_DIR "${CMAKE_INSTALL_BINDIR}")
set(MR_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}")
set(MR_MAIN_LIB_DIR "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}")
set(MR_PY_LIB_DIR "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/meshlib")
set(MR_RESOURCES_DIR "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}")
set(MR_FONTS_DIR "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/fonts")
set(MR_CONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
ELSE()
# TODO: https://cmake.org/cmake/help/latest/prop_tgt/RESOURCE.html
set(MR_ROOT "./Library/Frameworks/MeshLib.framework/Versions/${MESHLIB_VERSION}")
set(MR_BIN_DIR "${MR_ROOT}/bin")
set(MR_INCLUDE_DIR "${MR_ROOT}/include")
set(MR_MAIN_LIB_DIR "${MR_ROOT}/lib")
set(MR_PY_LIB_DIR "${MR_MAIN_LIB_DIR}/meshlib")
set(MR_RESOURCES_DIR "${MR_ROOT}/Resources")
set(MR_FONTS_DIR "${MR_ROOT}/Resources/fonts")
set(MR_CONFIG_DIR "${MR_ROOT}/Resources/cmake")
ENDIF()
IF(MESHLIB_BUILD_MRVIEWER)
set(IMGUI_DIR ${MESHLIB_THIRDPARTY_ROOT_DIR}/include/imgui)
include_directories(${IMGUI_DIR})
ENDIF()
# MRMesh library is always built
add_subdirectory(${PROJECT_SOURCE_DIR}/MRPch ./MRPch)
add_subdirectory(${PROJECT_SOURCE_DIR}/MRMesh ./MRMesh)
IF(MESHLIB_BUILD_EXTRA_IO_FORMATS)
add_subdirectory(${PROJECT_SOURCE_DIR}/MRIOExtras ./MRIOExtras)
ENDIF()
IF(MESHLIB_BUILD_SYMBOLMESH)
add_subdirectory(${PROJECT_SOURCE_DIR}/MRSymbolMesh ./MRSymbolMesh)
ENDIF()
IF(MESHLIB_BUILD_VOXELS)
add_subdirectory(${PROJECT_SOURCE_DIR}/MRVoxels ./MRVoxels)
ENDIF()
IF(MESHLIB_BUILD_MRVIEWER)
IF(NOT MR_EMSCRIPTEN)
find_package(glfw3 CONFIG REQUIRED)
ENDIF()
IF(MR_EMSCRIPTEN)
include(EmscriptenHelpers)
mr_emscripten_pack_directory("${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets" "/")
IF(NOT MR_DISABLE_EMSCRIPTEN_ASYNCIFY)
mr_emscripten_set_async_func_list("${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/wasm_async_func_list.txt")
ENDIF()
ENDIF()
add_subdirectory(${PROJECT_SOURCE_DIR}/MRViewer ./MRViewer)
add_subdirectory(${PROJECT_SOURCE_DIR}/MRCommonPlugins ./MRCommonPlugins)
add_subdirectory(${PROJECT_SOURCE_DIR}/MRViewerApp ./MRViewerApp)
ENDIF()
IF(NOT MR_EMSCRIPTEN)
IF(MESHLIB_PYTHON_SUPPORT)
add_subdirectory(${PROJECT_SOURCE_DIR}/MRPython ./MRPython)
IF(MESHLIB_BUILD_PYTHON_MODULES)
add_subdirectory(${PROJECT_SOURCE_DIR}/mrviewerpy ./mrviewerpy)
add_subdirectory(${PROJECT_SOURCE_DIR}/mrmeshnumpy ./mrmeshnumpy)
IF(MESHLIB_BUILD_MRMESH_PY_LEGACY)
add_subdirectory(${PROJECT_SOURCE_DIR}/mrmeshpy ./mrmeshpy)
ENDIF()
ENDIF()
ENDIF()
ENDIF()
IF(NOT MR_EMSCRIPTEN)
IF(MESHLIB_BUILD_MESHCONV)
add_subdirectory(${PROJECT_SOURCE_DIR}/meshconv ./meshconv)
ENDIF()
ENDIF()
IF(NOT MR_EMSCRIPTEN AND NOT APPLE)
IF(MESHLIB_BUILD_MRCUDA)
add_subdirectory(${PROJECT_SOURCE_DIR}/MRCuda ./MRCuda)
ELSE()
message(STATUS "MESHLIB_BUILD_MRCUDA is ${MESHLIB_BUILD_MRCUDA}")
ENDIF()
ENDIF()
IF(MESHLIB_EXPERIMENTAL_BUILD_C_BINDING)
add_subdirectory(${PROJECT_SOURCE_DIR}/MRMeshC ./MRMeshC)
ENDIF()
IF(BUILD_TESTING)
enable_testing()
add_subdirectory(${PROJECT_SOURCE_DIR}/MRTest ./MRTest)
IF(MESHLIB_EXPERIMENTAL_BUILD_C_BINDING)
add_subdirectory(${PROJECT_SOURCE_DIR}/MRTestC ./MRTestC)
ENDIF()
ENDIF()
include(CMakePackageConfigHelpers)
configure_package_config_file(meshlib-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/meshlib-config.cmake
INSTALL_DESTINATION ${MR_CONFIG_DIR}
PATH_VARS MR_INCLUDE_DIR MR_MAIN_LIB_DIR
)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/meshlib-config-version.cmake
VERSION ${MESHLIB_VERSION}
COMPATIBILITY ExactVersion
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/meshlib-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/meshlib-config-version.cmake
DESTINATION ${MR_CONFIG_DIR}
)
set(CPACK_GENERATOR "DRAGNDROP")
include(CPack)
# vim: ts=2:sw=2