-
Notifications
You must be signed in to change notification settings - Fork 12
/
CMakeLists.txt
226 lines (176 loc) · 6.84 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
cmake_minimum_required(VERSION 2.8)
project(ClothSim)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
#-------------------------------------------------------------------------------
# Build options
#-------------------------------------------------------------------------------
option(BUILD_LIBCGL "Build with libCGL" ON)
option(BUILD_DEBUG "Build with debug settings" OFF)
option(BUILD_DOCS "Build documentation" OFF)
if (BUILD_DEBUG)
set(CMAKE_BUILD_TYPE Debug)
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(BUILD_DEBUG ON CACHE BOOL "Build with debug settings" FORCE)
endif()
#-------------------------------------------------------------------------------
# Platform-specific settings
#-------------------------------------------------------------------------------
###################
# Building on OSX #
###################
if(APPLE)
# OSX Framework dependencies
if(NOT BUILD_LIBCGL)
include_directories( "/System/Library/Frameworks" )
find_library (COCOA_LIBRARIES Cocoa)
find_library (IOKIT_LIBRARIES IOkit)
find_library (COREVIDEO_LIBRARIES CoreVideo)
endif()
# Clang configuration
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CLANG_CXX_FLAGS "-std=c++11 -m64")
if(BUILD_DEBUG)
set(CMAKE_BUILD_TYPE Debug)
set(CLANG_CXX_FLAGS "${CLANG_CXX_FLAGS} -g")
else(BUILD_DEBUG)
set(CLANG_CXX_FLAGS "${CLANG_CXX_FLAGS} -O3")
set(CLANG_CXX_FLAGS "${CLANG_CXX_FLAGS} -funroll-loops")
set(CLANG_CXX_FLAGS "${CLANG_CXX_FLAGS} -Wno-narrowing")
set(CLANG_CXX_FLAGS "${CLANG_CXX_FLAGS} -Wno-deprecated-register")
endif(BUILD_DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CLANG_CXX_FLAGS}")
endif()
# GCC configuration
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(GCC_CXX_FLAGS "-std=gnu++11 -m64")
if(BUILD_DEBUG)
set(CMAKE_BUILD_TYPE Debug)
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -g")
else(BUILD_DEBUG)
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -O3")
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -fopenmp")
endif(BUILD_DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_CXX_FLAGS}")
endif()
endif(APPLE)
##################
# Build on Linux #
##################
if(UNIX AND NOT APPLE)
# GCC only
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(GCC_CXX_FLAGS "-std=gnu++11 -m64")
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -Wno-deprecated-declarations")
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -Wno-misleading-indentation")
# X11 Dependencies
if(NOT BUILD_LIBCGL)
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -lXi")
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -lXxf86vm")
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -lXinerama")
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -lXcursor")
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -lXfixes")
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -lXrandr")
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -lXext")
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -lXrender")
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -lX11")
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -lpthread")
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -lxcb")
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -lXau")
endif()
# Debug configuration
if(BUILD_DEBUG)
set(CMAKE_BUILD_TYPE Debug)
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -g")
else(BUILD_DEBUG)
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -O3")
set(GCC_CXX_FLAGS "${GCC_CXX_FLAGS} -fopenmp")
endif(BUILD_DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_CXX_FLAGS}")
endif()
endif()
####################
# Build on Windows #
####################
if(WIN32)
# EIGEN fix:
# See "Cause 4" here:
# https://eigen.tuxfamily.org/dox/group__TopicUnalignedArrayAssert.html
# NOTE: future maintainers, you may want to use add_compile_definitions instead.
# this was added because too many students are using old CMake (<3.12) versions.
add_definitions(/DEIGEN_DONT_ALIGN)
if(MSVC)
set(MSVC_CXX_FLAGS "-std=gnu++11")
if(BUILD_DEBUG)
set(CMAKE_BUILD_TYPE Debug)
else(BUILD_DEBUG)
set(CMAKE_BUILD_TYPE Release)
endif(BUILD_DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSVC_CXX_FLAGS}")
endif(MSVC)
if(MINGW)
set(MSVC_CXX_FLAGS "-std=gnu++11")
if(BUILD_DEBUG)
set(CMAKE_BUILD_TYPE Debug)
else(BUILD_DEBUG)
set(CMAKE_BUILD_TYPE Release)
endif(BUILD_DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSVC_CXX_FLAGS}")
endif(MINGW)
endif(WIN32)
#-------------------------------------------------------------------------------
# nanogui configuration and compilation
#-------------------------------------------------------------------------------
# Disable building extras we won't need (pure C++ project)
set(NANOGUI_BUILD_EXAMPLE OFF CACHE BOOL " " FORCE)
set(NANOGUI_BUILD_PYTHON OFF CACHE BOOL " " FORCE)
set(NANOGUI_INSTALL OFF CACHE BOOL " " FORCE)
set(NANOGUI_USE_GLAD ON CACHE BOOL " " FORCE)
# Add the configurations from nanogui
add_subdirectory(ext/nanogui)
include_directories(ext/nanogui/include)
# For reliability of parallel build, make the NanoGUI targets dependencies
set_property(TARGET glfw glfw_objects nanogui PROPERTY FOLDER "dependencies")
# For Windows, set the library output directory to put the DLL's next
# to the binary. I tried to use add_custom_command to just do a copy as a
# POST_BUILD setting, but for some reason no matter what the command does,
# Visual Studio will complain about its solution file being modified?
# In the interest of avoiding the flood of Piazza posts inquiring about this,
# we take the more robust route.
if(WIN32)
# Also worth mentioning is that since NANOGUI produces a DLL on windows,
# it is considered a "RUNTIME" and not a "LIBRARY" target according to CMake.
# See https://cmake.org/cmake/help/v3.0/prop_tgt/RUNTIME_OUTPUT_DIRECTORY.html
# > For DLL platforms the DLL part of a shared library is treated as a runtime target
set_target_properties(nanogui PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
endif(WIN32)
#-------------------------------------------------------------------------------
# Find dependencies
#-------------------------------------------------------------------------------
# Required packages
find_package(OpenGL REQUIRED)
find_package(Threads REQUIRED)
if(NOT WIN32)
find_package(Freetype REQUIRED)
endif()
# CGL
if(BUILD_LIBCGL)
add_subdirectory(CGL)
include_directories(CGL/include)
else(BUILD_LIBCGL)
find_package(CGL REQUIRED)
endif(BUILD_LIBCGL)
#-------------------------------------------------------------------------------
# Add subdirectories
#-------------------------------------------------------------------------------
add_subdirectory(src)
# build documentation
if(BUILD_DOCS)
find_package(DOXYGEN)
if(DOXYGEN_FOUND AND BUILD_DOCS)
add_subdirectory(docs)
endif()
endif()
# Install settings
set(CMAKE_INSTALL_PREFIX "${ClothSim_SOURCE_DIR}/")