-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
275 lines (224 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# This sets up the name of our project. For our purposes the main thing this controls is
# the name of the VS solution file.
project(PistonOptiX)
# This enforces a particular version of CMake that we require to process the script files
# properly.
cmake_minimum_required(VERSION 3.1.1 FATAL_ERROR)
cmake_policy(SET CMP0074 NEW)
# Add paths to our CMake code to the module path, so they can be found automatically by
# CMake.
set(CMAKE_MODULE_PATH
"${CMAKE_SOURCE_DIR}/CMake"
${CMAKE_MODULE_PATH}
)
# Set the default build to Release. Note this doesn't do anything for the VS
# default build target which defaults to Debug when you first start it.
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
FORCE)
ENDIF(NOT CMAKE_BUILD_TYPE)
# Tells CMake to build all the libraries as shared libraries by default. This can be
# overrided by individual libraries later.
set(BUILD_SHARED_LIBS ON)
##########
# Process our custom setup scripts here.
# Include all CMake Macros.
include(Macros)
# Determine information about the compiler
include (CompilerInfo)
# Check for specific machine/compiler options.
include (ConfigCompilerFlags)
# Turn off the warning that NVCC issues when generating PTX from our CUDA samples. This
# is a custom extension to the FindCUDA code distributed by CMake.
OPTION(CUDA_REMOVE_GLOBAL_MEMORY_SPACE_WARNING "Suppress the \"Advisory: Cannot tell what pointer points to, assuming global memory space\" warning nvcc makes." ON)
# For Xcode 5, gcc is actually clang, so we have to tell CUDA to treat the compiler as
# clang, so that it doesn't mistake it for something else.
if(USING_CLANG_C)
set(CUDA_HOST_COMPILER "clang" CACHE FILEPATH "Host side compiler used by NVCC")
endif()
find_package(CUDA 9.0 REQUIRED)
find_package(OpenGL REQUIRED)
# Optional: When IL_FOUND is false after this call, require for texture handling
find_package(DevIL)
if ( OPENGL_FOUND AND OPENGL_INCLUDE_DIR )
include_directories( ${OPENGL_INCLUDE_DIR} )
endif()
# Present the CUDA_64_BIT_DEVICE_CODE on the default set of options.
mark_as_advanced(CLEAR CUDA_64_BIT_DEVICE_CODE)
# Add some useful default arguments to the nvcc flags. This is an example of how we use
# PASSED_FIRST_CONFIGURE. Once you have configured, this variable is TRUE and following
# block of code will not be executed leaving you free to edit the values as much as you
# wish from the GUI or from ccmake.
if(NOT PASSED_FIRST_CONFIGURE)
list(APPEND default_nvcc_flags "--use_fast_math" "-arch sm_30" "-lineinfo")
if (CUDA_VERSION VERSION_LESS "3.0")
list(APPEND default_nvcc_flags "--keep")
endif()
if( APPLE )
# Undef'ing __BLOCKS__ for OSX builds. This is due to a name clash between OSX 10.6
# C headers and CUDA headers
list(APPEND default_nvcc_flags "-U__BLOCKS__")
endif()
# Append to nvcc flags
foreach(flag IN LISTS default_nvcc_flags)
list(FIND CUDA_NVCC_FLAGS ${flag} index)
if(index EQUAL -1)
list(APPEND CUDA_NVCC_FLAGS ${flag})
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} CACHE LIST "Semi-colon delimit multiple arguments." FORCE)
endif()
endforeach(flag)
endif(NOT PASSED_FIRST_CONFIGURE)
# Add required nvcc flag for callable programs under CUDA 8
if (CUDA_VERSION VERSION_GREATER "7.5")
set(flag "--keep-device-functions")
list(FIND CUDA_NVCC_FLAGS ${flag} index)
if(index EQUAL -1)
list(APPEND CUDA_NVCC_FLAGS ${flag})
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} CACHE LIST "Semi-colon delimit multiple arguments." FORCE)
endif()
endif()
# This passes a preprocessor definition to cl.exe when processing CUDA code.
if(USING_WINDOWS_CL)
list(APPEND CUDA_NVCC_FLAGS --compiler-options /D_USE_MATH_DEFINES)
endif()
# Put all the runtime stuff in the same directory. By default, CMake puts each targets'
# output into their own directory. We want all the targets to be put in the same
# directory, and we can do this by setting these variables.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
# Create a flag for mac which will allow apps to add the local cuda toolkit
# install path to the app's rpath.
if( APPLE )
set( CUDA_TOOLKIT_RPATH_FLAG "-Wl,-rpath,${CUDA_TOOLKIT_ROOT_DIR}/lib" )
endif()
#set(OptiX_INSTALL_DIR "C:\\ProgramData\\NVIDIA Corporation\\OptiX SDK 5.1.1")
# Search for the OptiX libraries and include files.
find_package(OptiX REQUIRED)
# Add the path to the OptiX headers to our include paths.
include_directories(
"${OptiX_INCLUDE}"
)
##################################################################
# SUtil compilation
set(SAMPLES_PTX_DIR "${CMAKE_BINARY_DIR}/lib/ptx")
set(SAMPLES_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(CUDA_GENERATED_OUTPUT_DIR ${SAMPLES_PTX_DIR})
if (WIN32)
string(REPLACE "/" "\\\\" SAMPLES_PTX_DIR ${SAMPLES_PTX_DIR})
else (WIN32)
if ( USING_GNU_C AND NOT APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DM_PI=3.14159265358979323846" )
endif()
endif (WIN32)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/sampleConfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/sampleConfig.h @ONLY)
# Path to sutil.h that all the samples need
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/sutil
${CMAKE_CURRENT_SOURCE_DIR}
${OptiX_INCLUDE}/optixu
${CMAKE_CURRENT_BINARY_DIR}
${CUDA_INCLUDE_DIRS} )
set(SAMPLES_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/device_include)
##################################################################
# IMGUI compilation
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/support )
add_subdirectory( support/imgui )
##################################################################
# GLFW compilation
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory( support/glfw )
#########################################################
# OPTIX_add_sample_executable
#
# Convience function for adding samples to the code. You can copy the contents of this
# funtion into your individual project if you wish to customize the behavior. Note that
# in CMake, functions have their own scope, whereas macros use the scope of the caller.
function(OPTIX_add_sample_executable target_name)
# These calls will group PTX and CUDA files into their own directories in the Visual
# Studio projects.
source_group("PTX Files" REGULAR_EXPRESSION ".+\\.ptx$")
source_group("CUDA Files" REGULAR_EXPRESSION ".+\\.cu$")
# Separate the sources from the CMake and CUDA options fed to the macro. This code
# comes from the CUDA_COMPILE_PTX macro found in FindCUDA.cmake. We are copying the
# code here, so that we can use our own name for the target. target_name is used in the
# creation of the output file names, and we want this to be unique for each target in
# the SDK.
CUDA_GET_SOURCES_AND_OPTIONS(source_files cmake_options options ${ARGN})
# Create the rules to build the PTX from the CUDA files.
CUDA_WRAP_SRCS( ${target_name} PTX generated_files ${source_files} ${cmake_options}
OPTIONS ${options} )
# Here is where we create the rule to make the executable. We define a target name and
# list all the source files used to create the target. In addition we also pass along
# the cmake_options parsed out of the arguments.
add_executable(${target_name}
${source_files}
${generated_files}
${cmake_options}
)
# Most of the samples link against sutil, optix, and glfw. Here is the
# rule that specifies this linkage.
target_link_libraries( ${target_name}
sutil_sdk
optix
glfw
imgui
${OPENGL_gl_LIBRARY}
${optix_rpath}
)
if(USING_GNU_CXX)
target_link_libraries( ${target_name} m ) # Explicitly link against math library (C samples don't do that by default)
endif()
endfunction()
#########################################################
# List of samples found in subdirectories.
#
# If you wish to start your own sample, you can copy one of the sample's directories.
# Just make sure you rename all the occurances of the sample's name in the C code as well
# and the CMakeLists.txt file.
add_subdirectory(PistonOptix)
# Our sutil library. The rules to build it are found in the subdirectory.
add_subdirectory(sutil)
# This copies out dlls into the build directories, so that users no longer need to copy
# them over in order to run the samples.
if(WIN32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT APPLE)
set(bit_dest "64")
else()
set(bit_dest "")
endif()
foreach(config ${CMAKE_CONFIGURATION_TYPES})
cmake_policy(SET CMP0026 OLD) # disable warning about LOCATION property
get_target_property(loc PistonOptix ${config}_LOCATION)
message(${loc})
if(loc)
# A little helper function
function(copy_dll lib)
get_filename_component(path ${loc} PATH)
get_filename_component(name ${lib} NAME)
#message("${CMAKE_COMMAND} -E copy_if_different ${lib} ${path}/${name}")
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${lib} ${path}/${name})
endfunction()
# Copy OptiX and optional DevIL dlls from their binary directories into the build
get_filename_component( path_to_optix_dll ${optix_DLL} PATH )
file(GLOB dlls "${path_to_optix_dll}/*.dll")
if (IL_FOUND)
get_filename_component( path_to_devil_dll ${IL_LIBRARIES} PATH )
file(GLOB devil_dlls "${path_to_devil_dll}/*.dll")
list(APPEND dlls ${devil_dlls})
endif()
foreach(file ${dlls})
copy_dll("${file}")
endforeach()
else()
message(WARNING "Unable to find location to copy DLLs into the build")
endif()
endforeach()
endif(WIN32)
#################################################################
# Now that everything is done, indicate that we have finished configuring at least once.
# We use this variable to set certain defaults only on the first pass, so that we don't
# continually set them over and over again.
set(PASSED_FIRST_CONFIGURE ON CACHE INTERNAL "Already Configured once?")