forked from pmp-library/pmp-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
238 lines (195 loc) · 6.53 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
cmake_minimum_required(VERSION 3.16.3)
cmake_policy(SET CMP0048 NEW)
project(
pmp-library
VERSION 2.0.1
DESCRIPTION "The Polygon Mesh Processing Library"
HOMEPAGE_URL "https://www.pmp-library.org")
cmake_policy(SET CMP0072 NEW)
option(PMP_BUILD_EXAMPLES "Build the PMP examples" ON)
option(PMP_BUILD_TESTS "Build the PMP test programs" ON)
option(PMP_BUILD_DOCS "Build the PMP documentation" ON)
option(PMP_BUILD_VIS "Build the PMP visualization tools" ON)
option(PMP_INSTALL "Install the PMP library and headers" ON)
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
# set output paths
set(PROJECT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR})
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
if(PMP_BUILD_VIS)
set(GLFW_SOURCE_DIR "external/glfw")
set(GLEW_SOURCE_DIR "external/glew")
set(IMGUI_SOURCE_DIR "external/imgui")
set(STBI_SOURCE_DIR "external/stb_image")
# setup STB Image (place *before* GLFW since GLFW has an old copy of
# stb_image_write.h)
include_directories(${STBI_SOURCE_DIR})
add_subdirectory(${STBI_SOURCE_DIR})
# Building only the GLFW lib
set(BUILD_SHARED_LIBS
OFF
CACHE BOOL "")
set(GLFW_BUILD_EXAMPLES
OFF
CACHE BOOL "")
set(GLFW_BUILD_TESTS
OFF
CACHE BOOL "")
set(GLFW_BUILD_DOCS
OFF
CACHE BOOL "")
set(GLFW_INSTALL
OFF
CACHE BOOL "")
# setup use of GLFW and GLEW
if(NOT EMSCRIPTEN)
add_subdirectory(${GLFW_SOURCE_DIR} ${GLEW_SOURCE_DIR})
include_directories(${GLFW_SOURCE_DIR}/include ${GLFW_SOURCE_DIR}/deps
${GLEW_SOURCE_DIR}/include)
add_definitions(-DGLEW_STATIC)
add_library(glew STATIC ${GLEW_SOURCE_DIR}/src/glew.c
${GLEW_SOURCE_DIR}/include)
set_property(TARGET glew PROPERTY POSITION_INDEPENDENT_CODE ON)
target_link_libraries(glew ${GLFW_LIBRARIES})
endif()
# setup IMGUI
include_directories(${IMGUI_SOURCE_DIR})
add_subdirectory(${IMGUI_SOURCE_DIR})
endif(PMP_BUILD_VIS)
# setup Eigen
set(EIGEN_SOURCE_DIR "external/eigen")
include_directories(${EIGEN_SOURCE_DIR})
include(AddFileDependencies)
include_directories(${PROJECT_SOURCE_DIR}/src/)
# setup for code coverage testing
if(CMAKE_BUILD_TYPE STREQUAL "Debug"
AND ENABLE_COVERAGE
AND NOT WIN32)
enable_testing()
# set compiler flags
set(CMAKE_CXX_FLAGS "-g -O0 --coverage")
# find required tools
find_program(LCOV lcov REQUIRED)
find_program(GENHTML genhtml REQUIRED)
# add coverage target
add_custom_target(
coverage
# gather data
COMMAND
${LCOV} --directory . --capture --exclude '*/external/*' --exclude
'*/tests/*' --exclude '/usr/*' --exclude '/Applications/*' --exclude
'v1/*' --output-file coverage.info
# generate report
COMMAND ${GENHTML} --demangle-cpp -o coverage coverage.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# set default compiler flags for both gcc and clang
set(COMMON_CXX_FLAGS "-pedantic -Wall -Wextra -Wshadow -Werror")
if((UNIX OR APPLE) AND CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} ${COMMON_CXX_FLAGS} -Wno-deprecated-copy")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "7.0.0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-int-in-bool-context")
endif()
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT EMSCRIPTEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_CXX_FLAGS}")
endif()
if(WIN32)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -D_USE_MATH_DEFINES -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS"
)
endif()
if(MSVC)
add_compile_options(/wd4267) # conversion from size_t
add_compile_options(/wd4244) # conversion from double to float
add_compile_options(/wd4305) # truncation from double to float
endif()
if(EMSCRIPTEN)
add_compile_options(--no-heap-copy)
add_link_options(
"SHELL:-s WASM=1 -s USE_WEBGL2=1 -s USE_GLFW=3 -s ALLOW_MEMORY_GROWTH=1 -s MINIFY_HTML=0 -s DISABLE_EXCEPTION_CATCHING=0"
)
set(CMAKE_EXECUTABLE_SUFFIX ".html")
endif()
# make a release build by default
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type specified. Using 'Release' as default.")
set(CMAKE_BUILD_TYPE
"Release"
CACHE
STRING
"The build type. Possible values: Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")
endif()
# choose size of the scalar type
if(PMP_SCALAR_TYPE EQUAL 64)
message(STATUS "Using 64-bit scalar type")
add_definitions(-DPMP_SCALAR_TYPE_64)
endif()
# choose size of the index type
if(PMP_INDEX_TYPE EQUAL 64)
message(STATUS "Using 64-bit index type")
add_definitions(-DPMP_INDEX_TYPE_64)
endif()
# setup clang-tidy if program found
option(WITH_CLANG_TIDY "Run clang-tidy checks" OFF)
include(clang-tidy)
# which directories to process
if(EMSCRIPTEN)
add_subdirectory(src/pmp)
if(PMP_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
else()
add_subdirectory(src/pmp)
if(PMP_BUILD_DOCS)
add_subdirectory(docs)
endif()
if(PMP_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(PMP_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
endif()
if(NOT EMSCRIPTEN AND PMP_INSTALL)
# Generate package configuration files
include(CMakePackageConfigHelpers)
set(PMP_CONFIG_PATH "lib${LIB_SUFFIX}/cmake/pmp")
configure_package_config_file(
cmake/pmpConfig.cmake.in pmpConfig.cmake
INSTALL_DESTINATION "${PMP_CONFIG_PATH}"
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
install(
EXPORT pmpTargets
FILE pmpTargets.cmake
EXPORT_LINK_INTERFACE_LIBRARIES
DESTINATION "${PMP_CONFIG_PATH}")
export(TARGETS pmp FILE pmpTargets.cmake)
write_basic_package_version_file(
pmpConfigVersion.cmake
VERSION ${PMP_VERSION}
COMPATIBILITY SameMajorVersion)
install(FILES "${PROJECT_BINARY_DIR}/pmpConfig.cmake"
"${PROJECT_BINARY_DIR}/pmpConfigVersion.cmake"
DESTINATION "${PMP_CONFIG_PATH}")
endif()
# add uninstall target if none is defined
if(NOT TARGET uninstall AND PMP_INSTALL)
configure_file("${CMAKE_MODULE_PATH}/cmake_uninstall.cmake.in"
cmake_uninstall.cmake IMMEDIATE @ONLY)
add_custom_target(uninstall "${CMAKE_COMMAND}" -P
"${PROJECT_BINARY_DIR}/cmake_uninstall.cmake")
endif()
# add clang-format target if program is found
include(clang-format)