-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeConfig.txt
211 lines (174 loc) · 8.04 KB
/
CMakeConfig.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
# =======================================================================
# WARNING WARNING WARNING WARNING WARNING WARNING
# =======================================================================
# Remember to put on SAFETY GOGGLES before looking at this file. You
# are most certainly not expected to read or understand any of it.
# =======================================================================
#
# This CMake file is responsible for compiling dependency libraries and
# setting up suitable compiler flags for various platforms. You do not
# need to read or change anything in this file; see CMakeLists.txt instead.
include(CMakeParseArguments)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/ext/cmake)
# -- Set a defaults
# Use build configuration Release as default
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_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
include(ExternalProject)
set(CMAKE_EXTERNAL_ARGUMENTS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_GENERATOR=${CMAKE_GENERATOR} -Wno-dev
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/ext_build/dist)
# -- Setup platform specifics and GUI/window manager libraries
if(MSVC)
# Windows-specific build flags
# Don't advertise awkward and non-standard "secure" C++ functions
add_definitions(/D "_CRT_SECURE_NO_WARNINGS")
include_directories(ext/glew/include)
set(gui_libs opengl32)
# set(gui_libs ${gui_libs} zlibstatic)
# Statically link against the C++ runtime library, also apply these settings to nested projects
set(CompilerFlags
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
string(REPLACE "/MDd" "/MTd" ${CompilerFlag} "${${CompilerFlag}}")
set(CMAKE_EXTERNAL_ARGUMENTS ${CMAKE_EXTERNAL_ARGUMENTS} -D${CompilerFlag}:INTERNAL=${${CompilerFlag}})
endforeach()
elseif(APPLE)
# OSX-specific build flags
# Find standard libraries needed for OpenGL/GLFW
find_library(cocoa_library Cocoa)
find_library(opengl_library OpenGL)
find_library(corevideo_library CoreVideo)
find_library(iokit_library IOKit)
set(gui_libs ${cocoa_library} ${opengl_library} ${corevideo_library} ${iokit_library} z)
# Compile in C++11 mode
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
# Try to auto-detect a suitable OSX SDK
# execute_process(COMMAND bash -c "xcodebuild -version -sdk | grep MacOSX | grep Path | head -n 1 | cut -f 2 -d ' '" OUTPUT_VARIABLE CMAKE_OSX_SYSROOT)
execute_process(COMMAND bash -c "xcodebuild -version -sdk | grep MacOSX | grep \"MacOSX10.1\\d.sdk\" | grep Path | head -n 1 | cut -f 2 -d ' '" OUTPUT_VARIABLE CMAKE_OSX_SYSROOT)
string(REGEX REPLACE "(\r?\n)+$" "" CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT}")
string(REGEX REPLACE "^.*X([0-9.]*).sdk$" "\\1" CMAKE_OSX_DEPLOYMENT_TARGET "${CMAKE_OSX_SYSROOT}")
# Also use the same SDK in nested projects
set(CMAKE_EXTERNAL_ARGUMENTS ${CMAKE_EXTERNAL_ARGUMENTS} -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT})
elseif("${CMAKE_SYSTEM}" MATCHES "Linux")
# Linux-specific build flags
set(gui_libs GL Xxf86vm Xrandr Xinerama Xcursor Xi X11 pthread dl)
# Compile in C++11 mode
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
# -- Build package manager libraries
if(NORI_USE_VDB)
# Find installed openvdb
find_package(OpenVDB REQUIRED)
include_directories(${OpenVDB_INCLUDE_DIRS})
link_directories(${OpenVDB_LIBRARY_DIRS})
message(STATUS "OpenVDB libs: ${OpenVDB_LIBRARIES}")
if(CMAKE_BUILD_TYPE MATCHES Debug AND WIN32)
# Workaround for cmake not copying OpenVDB dependencies to the binary folder in debug mode
configure_file(${CMAKE_SOURCE_DIR}/ext/vcpkg/installed/x64-windows/bin/Half-2_5.dll ${CMAKE_BINARY_DIR}/Half-2_5.dll COPYONLY)
endif()
# Optionally find Blosc for nanoVDB compression, (openVDB already finds this by itself)
find_package(Blosc)
if(Blosc_FOUND)
add_definitions(-DNANOVDB_USE_BLOSC)
include_directories(${Blosc_INCLUDE_DIRS})
endif(Blosc_FOUND)
endif()
include_directories(ext/nanovdb)
find_package(TBB REQUIRED COMPONENTS tbb)
include_directories(${Tbb_INCLUDE_DIRS})
link_directories(${Tbb_LIBRARY_DIRS})
message(STATUS "TBB: ${Tbb_LIBRARIES} ${Tbb_INCLUDE_DIRS} ${Tbb_LIBRARY_DIRS}")
find_package(OpenEXR REQUIRED)
include_directories(${OpenEXR_INCLUDE_DIRS})
link_directories(${OpenEXR_LIBRARY_DIRS})
message(STATUS "OpenEXR libs: ${OpenEXR_LIBRARIES}")
# Node: find IlmBase after openvdb! else variables are overwritten and not all libraries found
find_package(IlmBase REQUIRED)
include_directories(${IlmBase_INCLUDE_DIRS})
link_directories(${IlmBase_LIBRARY_DIRS})
message(STATUS "IlmBase libs: ${IlmBase_LIBRARIES}")
set(Eigen3_DIR ${CMAKE_SOURCE_DIR}/ext/eigen)
include_directories(${Eigen3_DIR})
# -- Build external in-project libraries
# Pass external arguments to nested build processes
string(REGEX REPLACE ";" "$" CMAKE_EXTERNAL_ARGUMENTS_STR "${CMAKE_EXTERNAL_ARGUMENTS}")
list(APPEND CMAKE_EXTERNAL_ARGUMENTS -D CMAKE_EXTERNAL_ARGUMENTS:STRING=${CMAKE_EXTERNAL_ARGUMENTS_STR})
# Build gui libs: nanogui, imgui, glfw, glew
if(NORI_USE_GUI)
# -- Dear Gui (imgui) libs
# GLAD for imgui
add_subdirectory(ext/glad)
# GLFW window manager
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "GLFW lib only")
set(GLFW_BUILD_TESTS OFF CACHE BOOL "GLFW lib only")
set(GLFW_BUILD_DOCS OFF CACHE BOOL "GLFW lib only")
set(GLFW_INSTALL OFF CACHE BOOL "GLFW lib only")
# Important: on windows glfw will be shared by default which causes linker errors
set(BUILD_SHARED_LIBS OFF)
set(GLFW_DIR ${CMAKE_SOURCE_DIR}/ext/GLFW)
add_subdirectory(${GLFW_DIR})
if(NORI_USE_IMGUI)
add_subdirectory(ext/imgui) # uses glad and glfw
endif()
# -- Legacy GUI libs: nanogui and GLEW, still compile for warptest
set(GLEW_DIR ${CMAKE_SOURCE_DIR}/ext/glew)
# add_definitions(-DGLEW_STATIC) # required when using with imgui
add_subdirectory(${GLEW_DIR})
include_directories(${GLEW_DIR}/include)
add_subdirectory(ext/nanogui)
endif(NORI_USE_GUI)
# Build lodepng
add_subdirectory(ext/lodepng)
add_library(pugixml STATIC ext/pugixml/src/pugixml.cpp)
set_target_properties(pugixml PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/ext_build/dist/lib")
# -- Compile Nori with compiler warnings turned on
if(MSVC)
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -Wno-deprecated-declarations")
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-anonymous-struct -Wno-c99-extensions -Wno-nested-anon-types -Wno-deprecated-register -Wno-missing-braces")
endif()
endif()
# -- Include and 'link' libraries
# Compile against & link to previously compiled external projects
link_directories(${CMAKE_BINARY_DIR}/ext_build/dist/lib)
include_directories(
${CMAKE_BINARY_DIR}/ext_build/dist/include
ext/pcg32
ext/tinyformat
ext/pugixml/src
ext/hypothesis
ext/filesystem
ext/lodepng
include
)
# Link to several dependency libraries
set(extra_libs pugixml lodepng ${Tbb_LIBRARIES} ${IlmBase_LIBRARIES} ${OpenEXR_LIBRARIES} ${OpenVDB_LIBRARIES} ${Blosc_LIBRARIES} ${extra_libs})
if(NORI_USE_GUI)
if(NORI_USE_IMGUI)
list(APPEND extra_libs imgui glfw ${GLFW_LIBRARIES} ${gui_libs})
else()
list(APPEND extra_libs nanogui glew ${gui_libs})
endif()
else()
if(NOT WIN32)
list(APPEND extra_libs pthread)
endif()
endif()
message(STATUS "extra_libs: ${extra_libs}")
# vim: set et ts=2 sw=2 ft=cmake nospell: