forked from sxyu/smplxpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·277 lines (242 loc) · 9.82 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
cmake_minimum_required( VERSION 3.11 )
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to Release")
set(CMAKE_BUILD_TYPE Release)
endif()
if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif (POLICY CMP0048)
if (POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
endif (POLICY CMP0069)
if (POLICY CMP0072)
cmake_policy(SET CMP0072 NEW)
endif (POLICY CMP0072)
project( smplxpp )
option( SMPLX_USE_FFAST_MATH "Enable ffast-math compiler flag, may cause numerical problems" ON )
option( SMPLX_BUILD_VIEWER "Build OpenGL-based viewers (smplx-viewer, smplx-amass, smplx-sdf)" ON )
option( SMPLX_BUILD_PYTHON "Build Python bindings" OFF )
option( SMPLX_USE_SYSTEM_EIGEN "Use system Eigen rather than the included Eigen submodule if available" OFF )
option( SMPLX_USE_CUDA "Use cuda if available" ON )
set( INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include" )
set( SRC_DIR "${PROJECT_SOURCE_DIR}/src" )
set( VENDOR_DIR "${PROJECT_SOURCE_DIR}/3rdparty" )
set( MESHVIEW_DIR "${VENDOR_DIR}/meshview" )
set( CNPY_DIR "${VENDOR_DIR}/cnpy" )
set( ZLIB_DIR "${VENDOR_DIR}/zlib" )
set( EIGEN_DIR "${VENDOR_DIR}/eigen" )
set( CMAKE_CXX_STACK_SIZE "10000000" )
set( CMAKE_CXX_STANDARD 17 )
set( CMAKE_CXX_STANDARD_REQUIRED ON)
set( CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake_modules" )
if (SMPLX_USE_CUDA)
include(CheckLanguage)
check_language(CUDA)
endif()
if (SMPLX_USE_CUDA AND CMAKE_CUDA_COMPILER)
set(SMPLX_CUDA_ENABLED ON)
set(_SMPLX_CUDA_ENABLED_ "")
enable_language(CUDA)
message(STATUS "CUDA enabled")
set( CMAKE_CUDA_STANDARD 14 )
set( CMAKE_CUDA_STANDARD_REQUIRED ON)
set( CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -g -Xcudafe \"--display_error_number --diag_suppress=3057 --diag_suppress=3058 --diag_suppress=3059 --diag_suppress=3060\" -lineinfo")
else()
message(STATUS "CUDA disabled")
set(SMPLX_CUDA_ENABLED OFF)
set(_SMPLX_CUDA_ENABLED_ "//")
endif()
set( PROJ_NAME "smplxpp" )
if ( CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang") )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wno-deprecated-declarations -O3 -funroll-loops -g" )
if( ${SMPLX_USE_FFAST_MATH} )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math" )
endif()
elseif( MSVC )
if( ${SMPLX_USE_FFAST_MATH} )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast" )
endif()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT /GLT /Ox")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT /GLT")
if (SMPLX_USE_CUDA)
set( CMAKE_CUDA_FLAGS_RELEASE "${CMAKE_CUDA_FLAGS_RELEASE} -Xcompiler=\"/MT\"" )
endif()
# Silence deprecation warning coming from Eigen; silence secure warning
add_definitions(-D_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING -D_CRT_SECURE_NO_WARNINGS)
endif ( )
# Git submodule auto update
# https://cliutils.gitlab.io/modern-cmake/chapters/projects/submodule.html
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Running update --init --recursive")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
message(STATUS "Submodule update done")
endif()
endif()
if(NOT EXISTS "${MESHVIEW_DIR}/CMakeLists.txt")
message(FATAL_ERROR "A submodule as not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()
file(GLOB_RECURSE SOURCES ${SRC_DIR}/*.cpp)
file(GLOB_RECURSE HEADERS ${INCLUDE_DIR}/smplx/*.hpp)
file(GLOB IMGUI_SOURCES ${IMGUI_DIR}/*.cpp)
set( VENDOR_SOURCES ${CNPY_DIR}/cnpy.cpp)
if ( SMPLX_CUDA_ENABLED )
file(GLOB_RECURSE SOURCES_CUDA ${SRC_DIR}/cuda/*.cu)
set (SOURCES ${SOURCES} ${SOURCES_CUDA})
endif ( SMPLX_CUDA_ENABLED )
# ensure M_PI, etc available
add_definitions( -DGLEW_STATIC -D_USE_MATH_DEFINES )
set( DEPENDENCIES )
#OpenMP
# find_package(OpenMP QUIET)
# if (OPENMP_FOUND)
# message(STATUS "Using OpenMP for parallelization")
# set( DEPENDENCIES ${DEPENDENCIES} OpenMP::OpenMP_CXX )
# set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp" )
# else()
# message(STATUS "OpenMP not found, CPU performance may suffer")
# endif()
include_directories(
${VENDOR_DIR}/misc
${CNPY_DIR}
${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
)
if (SMPLX_BUILD_VIEWER)
include_directories(
${STB_DIR}
${IMGUI_DIR}
)
endif(SMPLX_BUILD_VIEWER)
# Eigen
if ( SMPLX_USE_SYSTEM_EIGEN )
find_package(Eigen3 3.3.90 QUIET NO_MODULE)
if (TARGET Eigen3::Eigen)
message(STATUS "Using system Eigen")
set (DEPENDENCIES ${DEPENDENCIES} Eigen3::Eigen)
else()
message(STATUS "System Eigen > 3.3.90 not found, using vendor Eigen")
include_directories(${EIGEN_DIR})
endif()
else()
message(STATUS "Using vendor Eigen")
include_directories(${EIGEN_DIR})
endif()
# Zlib
find_package(ZLIB QUIET)
if (ZLIB_FOUND)
message( STATUS "Using system zlib" )
set( DEPENDENCIES ${DEPENDENCIES} ZLIB::ZLIB )
else()
message( STATUS "Using included zlib." )
add_subdirectory(${ZLIB_DIR})
include_directories(${ZLIB_DIR})
set( DEPENDENCIES ${DEPENDENCIES} zlibstatic )
endif()
if ( SMPLX_BUILD_VIEWER )
SET(MESHVIEW_BUILD_EXAMPLE OFF CACHE BOOL "meshview example" FORCE)
SET(MESHVIEW_USE_SYSTEM_EIGEN OFF CACHE BOOL "system eigen" FORCE)
SET(EIGEN_INCLUDE_DIR '${EIGEN_DIR}' CACHE BOOL "eigen directory" FORCE)
add_subdirectory(${MESHVIEW_DIR})
endif()
# Optional sxyu/sdf
find_package(sdf QUIET)
# Optional pybind11
find_package( pybind11 )
if (NOT pybind11_FOUND)
message( WARNING "pybind11 not found, Python binding is disabled. Install from https://github.com/pybind/pybind11" )
endif()
#Link cuda libraries (not used now)
# if (SMPLX_USE_CUDA)
# set( DEPENDENCIES ${DEPENDENCIES} cublas cusparse )
# endif()
add_library( ${PROJ_NAME} STATIC ${SOURCES} ${VENDOR_SOURCES} )
set_target_properties( ${PROJ_NAME} PROPERTIES OUTPUT_NAME "smplx" )
target_include_directories(${PROJ_NAME} PUBLIC
$<BUILD_INTERFACE:${INCLUDE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries( ${PROJ_NAME} ${DEPENDENCIES} )
install(TARGETS ${PROJ_NAME} DESTINATION lib)
if (SMPLX_USE_CUDA)
set_target_properties( ${PROJ_NAME} PROPERTIES CUDA_SEPERABLE_COMPILATION ON)
endif()
add_executable( example main_example.cpp )
target_link_libraries( example ${PROJ_NAME} )
set_target_properties( example PROPERTIES OUTPUT_NAME "smplx-example" )
install(TARGETS example DESTINATION bin)
if ( SMPLX_BUILD_VIEWER )
add_executable( viewer main_viewer.cpp )
target_link_libraries( viewer meshview ${PROJ_NAME} )
set_target_properties( viewer PROPERTIES OUTPUT_NAME "smplx-viewer" )
install(TARGETS viewer DESTINATION bin)
add_executable( amass main_amass.cpp )
target_link_libraries( amass meshview ${PROJ_NAME} )
set_target_properties( amass PROPERTIES OUTPUT_NAME "smplx-amass" )
install(TARGETS amass DESTINATION bin)
if (sdf_FOUND)
message(STATUS "Building SDF demo (experimental)")
add_executable( sdfview main_sdf.cpp )
target_link_libraries( sdfview meshview sdf::sdf ${PROJ_NAME} )
set_target_properties( sdfview PROPERTIES OUTPUT_NAME "smplx-sdf" )
install(TARGETS sdfview DESTINATION bin)
endif()
endif( SMPLX_BUILD_VIEWER )
if (${pybind11_FOUND} AND ${SMPLX_BUILD_PYTHON})
message(STATUS "Building Python bindings")
pybind11_add_module(pysmplxpp SHARED ${SOURCES} ${VENDOR_SOURCES} pybind.cpp)
set_target_properties(pysmplxpp PROPERTIES OUTPUT_NAME smplxpp)
target_include_directories(
pysmplxpp PUBLIC
$<BUILD_INTERFACE:${INCLUDE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(pysmplxpp PRIVATE ${DEPENDENCIES})
if (SMPLX_USE_CUDA)
set_target_properties( pysmplxpp PROPERTIES CUDA_SEPERABLE_COMPILATION ON)
endif()
endif ()
if ( MSVC )
if ( SMPLX_BUILD_VIEWER )
set_property(TARGET viewer APPEND PROPERTY LINK_FLAGS "/DEBUG /LTCG" )
set_property(TARGET amass APPEND PROPERTY LINK_FLAGS "/DEBUG /LTCG" )
if (sdf_FOUND)
set_property(TARGET sdfview APPEND PROPERTY LINK_FLAGS "/DEBUG /LTCG" )
endif()
endif()
set_property(TARGET example APPEND PROPERTY LINK_FLAGS "/DEBUG /LTCG" )
endif ( MSVC )
if(WIN32)
# string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
# string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
# string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
# string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
add_definitions(-DNOMINMAX)
elseif(CYGWIN)
elseif(APPLE)
elseif(UNIX)
target_link_libraries( ${PROJ_NAME} -pthread )
target_link_libraries( example -pthread )
if (SMPLX_BUILD_VIEWER)
target_link_libraries( viewer -pthread )
endif()
add_definitions(-DUNIX)
add_compile_options(-Wno-deprecated-declarations)
add_compile_options(-Wno-unused-result)
endif(WIN32)
# create version.hpp
configure_file( version.hpp.in "${PROJECT_BINARY_DIR}/include/smplx/version.hpp" )
source_group( "Header Files" FILES ${HEADERS} )
source_group( "Source Files" FILES ${SOURCES} )
source_group( "Vendor Source Files" FILES ${VENDOR_SOURCES} )