-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
252 lines (208 loc) · 10.1 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
cmake_minimum_required(VERSION 3.24)
project(SimpleObjectViewer C CXX)
############################################################################################################
# Compile Options
############################################################################################################
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_POSITION_INDEPENDENT_CODE on)
include(InstallRequiredSystemLibraries)
# Set default build type if not specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
if(MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
elseif(UNIX)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D SIMVIEW_ENABLE_LEAK_CHECK")
# NOTE: In some cases, failed to compile assimp with clang compiler with gcc 12 toolchain.
# Thus, specify your path to the gcc "11" toolchain by the following option.
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/11")
set(SIMVIEW_BUILD_AS_WIN32_APP TRUE CACHE BOOL "Build as WIN32 apps")
if (SIMVIEW_BUILD_AS_WIN32_APP)
message(STATUS "Build as a WIN32 app.")
add_definitions(-DSIMVIEW_BUILD_AS_WIN32_APP)
endif()
############################################################################################################
# Envirionment Variables
############################################################################################################
# #### Set environment variables in project
set(PROJECT_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include")
set(PROJECT_LIB_DIR "${PROJECT_SOURCE_DIR}/external")
set(WIN_RESOURCE_FILE "${PROJECT_SOURCE_DIR}/assets/resource.rc")
set(ORIGINAL_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
string(TOLOWER ${ORIGINAL_SYSTEM_NAME} LOWERCASE_SYSTEM_NAME)
set(ORIGINAL_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR})
string(TOLOWER ${ORIGINAL_SYSTEM_PROCESSOR} LOWERCASE_SYSTEM_PROCESSOR)
set(PROJECT_ARCHITECTURE_NAME "${LOWERCASE_SYSTEM_PROCESSOR}-${LOWERCASE_SYSTEM_NAME}")
############################################################################################################
# External Libraries
############################################################################################################
# #### OpenMP
find_package(OpenMP REQUIRED)
if(OpenMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
# #### GLAD
set(GLAD_INCLUDE_DIR ${PROJECT_LIB_DIR}/glad/include)
# #### GLFW
set(GLFW_INCLUDE_DIR ${PROJECT_LIB_DIR}/glfw/include)
# #### GLM
set(GLM_INCLUDE_DIR ${PROJECT_LIB_DIR}/glm)
# #### picojson
set(PICOJSON_INCLUDE_DIR ${PROJECT_LIB_DIR}/picojson)
# #### stb
set(STB_INCLUDE_DIR ${PROJECT_LIB_DIR}/stb)
# #### tinyobjloader
set(TINYOBJLOADER_INCLUDE_DIR ${PROJECT_LIB_DIR}/tinyobjloader)
# #### freetype
set(FREETYPE_INCLUDE_DIR ${PROJECT_LIB_DIR}/freetype/include)
# #### Dear Imgui
set(IMGUI_INCLUDE_DIR ${PROJECT_LIB_DIR}/imgui)
set(IMGUI_SOURCE_DIR ${PROJECT_LIB_DIR}/imgui)
set(IMGUI_BACKENDS_DIR ${IMGUI_SOURCE_DIR}/backends)
set(
IMGUI_SOURCE_FILES
${IMGUI_SOURCE_DIR}/imgui.cpp
${IMGUI_SOURCE_DIR}/imgui_demo.cpp
${IMGUI_SOURCE_DIR}/imgui_draw.cpp
${IMGUI_SOURCE_DIR}/imgui_tables.cpp
${IMGUI_SOURCE_DIR}/imgui_widgets.cpp
${IMGUI_SOURCE_DIR}/imgui_demo.cpp
${IMGUI_BACKENDS_DIR}/imgui_impl_glfw.cpp
${IMGUI_BACKENDS_DIR}/imgui_impl_opengl3.cpp
${IMGUI_SOURCE_DIR}/misc/freetype/imgui_freetype.cpp
)
# #### nativefiledialog-extended
set(NFD_INCLUDE_DIR ${PROJECT_LIB_DIR}/nativefiledialog-extended/src/include)
# #### spdlog
set(SPD_LOG_INCLUDE_DIR ${PROJECT_LIB_DIR}/spdlog/include)
# #### assimp
set(SIMVIEW_WITH_ASSIMP TRUE CACHE BOOL "Build with Assimp")
if (SIMVIEW_WITH_ASSIMP)
add_definitions(-DSIMVIEW_WITH_ASSIMP)
set(ASSIMP_INCLUDE_DIR ${PROJECT_LIB_DIR}/assimp/include ${CMAKE_CURRENT_BINARY_DIR}/external/assimp/include)
set(SIMVIEW_ASSIMP_LIBS assimp)
endif()
# #### VTK
set(SIMVIEW_WITH_VTK TRUE CACHE BOOL "Build with VTK")
if (SIMVIEW_WITH_VTK)
find_package(VTK QUIET)
if (VTK_FOUND)
message(STATUS "### Found VTK")
add_definitions(-DSIMVIEW_WITH_VTK)
else()
set(SIMVIEW_WITH_VTK FALSE)
endif()
endif()
############################################################################################################
# External libralies
############################################################################################################
set(
EXTERNAL_INCLUDE_DIR
${GLAD_INCLUDE_DIR}
${GLFW_INCLUDE_DIR}
${GLM_INCLUDE_DIR}
${PICOJSON_INCLUDE_DIR}
${STB_INCLUDE_DIR}
${TINYOBJLOADER_INCLUDE_DIR}
${IMGUI_INCLUDE_DIR}
${NFD_INCLUDE_DIR}
${SPD_LOG_INCLUDE_DIR}
${ASSIMP_INCLUDE_DIR}
${FREETYPE_INCLUDE_DIR}
)
set(
EXTERNAL_LIBS
glad
glfw
nfd
freetype
${SIMVIEW_ASSIMP_LIBS}
${VTK_LIBRARIES}
)
############################################################################################################
# For static library usage
############################################################################################################
# This variable is for the library mode
set(
SimpleObjectViewer_INCLUDE_DIR
${PROJECT_INCLUDE_DIR}
${EXTERNAL_INCLUDE_DIR}
CACHE
STRING
"All include directories for Simeple Object Viewer library"
)
set(SIMVIEW_BUILD_STATIC_LIBS TRUE CACHE BOOL "Build as static library")
set(SIMVIEW_BUILD_EXECUTABLES TRUE CACHE BOOL "Build executable files")
############################################################################################################
# Set install include directory
############################################################################################################
set(SIMVIEW_INSTALL TRUE CACHE BOOL "Install SimView library")
if (SIMVIEW_INSTALL)
install(
DIRECTORY "${PROJECT_INCLUDE_DIR}/SimView"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING PATTERN "*.hpp"
)
endif()
# NOTE: Installing lib directory is set in src/CMakeLists.txt
############################################################################################################
# Add subdirectory
############################################################################################################
add_subdirectory(src)
add_subdirectory(external)
############################################################################################################
# Message
############################################################################################################
set(SIMVIEW_SHOW_BUILD_CONF TRUE CACHE BOOL "Show teh build configuration message")
if (${SIMVIEW_SHOW_BUILD_CONF})
message(STATUS "# =======================================================================================================")
message(STATUS "# '${PROJECT_NAME}' build configuration ")
message(STATUS "# =======================================================================================================")
message(STATUS "# [CMake]")
message(STATUS "# CMake version : ${CMAKE_VERSION}")
message(STATUS "# CMake build type : ${CMAKE_BUILD_TYPE}")
message(STATUS "# CMAKE_CXX_FLAGS : ${CMAKE_CXX_FLAGS}")
message(STATUS "# CMAKE_CXX_FLAGS_DEBUG : ${CMAKE_CXX_FLAGS_DEBUG}")
message(STATUS "# CMAKE_CXX_FLAGS_RELEASE : ${CMAKE_CXX_FLAGS_RELEASE}")
message(STATUS "# ")
message(STATUS "# [C/C++]")
message(STATUS "# C Compiler : ${CMAKE_C_COMPILER_ID} | ${CMAKE_C_COMPILER_VERSION} | ${CMAKE_C_COMPILER}")
message(STATUS "# C++ Compiler : ${CMAKE_CXX_COMPILER_ID} | ${CMAKE_CXX_COMPILER_VERSION} | ${CMAKE_CXX_COMPILER}")
message(STATUS "# CXX STANDARD : ${CMAKE_CXX_STANDARD}")
message(STATUS "# ")
message(STATUS "# [OpenMP]")
message(STATUS "# OpenMP_C_FLAGS : ${OpenMP_C_FLAGS}")
message(STATUS "# OpenMP_CXX_FLAGS : ${OpenMP_CXX_FLAGS}")
message(STATUS "# ")
message(STATUS "# [Environment Variables]")
message(STATUS "# PROJECT_INCLUDE_DIR : ${PROJECT_INCLUDE_DIR}")
message(STATUS "# PROJECT_LIB_DIR : ${PROJECT_LIB_DIR}")
message(STATUS "# ")
message(STATUS "# GLAD_INCLUDE_DIR : ${GLAD_INCLUDE_DIR}")
message(STATUS "# GLFW_INCLUDE_DIR : ${GLFW_INCLUDE_DIR}")
message(STATUS "# GLM_INCLUDE_DIR : ${GLM_INCLUDE_DIR}")
message(STATUS "# PICOJSON_INCLUDE_DIR : ${PICOJSON_INCLUDE_DIR}")
message(STATUS "# STB_INCLUDE_DIR : ${STB_INCLUDE_DIR}")
message(STATUS "# TINYOBJLOADER_INCLUDE_DIR : ${TINYOBJLOADER_INCLUDE_DIR}")
message(STATUS "# IMGUI_INCLUDE_DIR : ${IMGUI_INCLUDE_DIR}")
message(STATUS "# IMGUI_SOURCE_DIR : ${IMGUI_SOURCE_DIR}")
message(STATUS "# IMGUI_BACKENDS_DIR : ${IMGUI_BACKENDS_DIR}")
message(STATUS "# NFD_INCLUDE_DIR : ${NFD_INCLUDE_DIR}")
message(STATUS "# SPD_LOG_INCLUDE_DIR : ${SPD_LOG_INCLUDE_DIR}")
message(STATUS "# ASSIMP_INCLUDE_DIR : ${ASSIMP_INCLUDE_DIR}")
message(STATUS "# FREETYPE_INCLUDE_DIR : ${FREETYPE_INCLUDE_DIR}")
message(STATUS "# ")
message(STATUS "# SIMVIEW_BUILD_EXECUTABLES : ${SIMVIEW_BUILD_EXECUTABLES}")
message(STATUS "# SIMVIEW_BUILD_STATIC_LIBS : ${SIMVIEW_BUILD_STATIC_LIBS}")
message(STATUS "# SIMVIEW_BUILD_AS_WIN32_APP : ${SIMVIEW_BUILD_AS_WIN32_APP}")
message(STATUS "# SIMVIEW_WITH_VTK : ${SIMVIEW_WITH_VTK}")
message(STATUS "# =======================================================================================================")
endif()