Guest User

Untitled

a guest
Jun 2nd, 2020
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CMake 15.78 KB | None | 0 0
  1. #
  2. # Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions
  6. # are met:
  7. #  * Redistributions of source code must retain the above copyright
  8. #    notice, this list of conditions and the following disclaimer.
  9. #  * Redistributions in binary form must reproduce the above copyright
  10. #    notice, this list of conditions and the following disclaimer in the
  11. #    documentation and/or other materials provided with the distribution.
  12. #  * Neither the name of NVIDIA CORPORATION nor the names of its
  13. #    contributors may be used to endorse or promote products derived
  14. #    from this software without specific prior written permission.
  15. #
  16. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
  17. # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20. # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23. # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  24. # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. #
  28.  
  29. # Welcome to the OptiX SDK build.  We have chosen CMake, because it can generate multiple
  30. # build systems for multiple architectures from a single script.  There are many resources
  31. # for CMake on-line at http://www.cmake.org and their wiki page,
  32. # http://www.cmake.org/Wiki/CMake, in addition to the documentation that comes with the
  33. # distribution.  There is also a book available if you wish to delve more deeply into
  34. # various topics.
  35.  
  36. # If you wish to create your own project and use the SDK as a template there are a number
  37. # of things you should do.
  38. #
  39. # 1. You should copy the contents of the SDK to a place of your choice.
  40. #
  41. # 2. You can remove any sample's directory you don't wish to build.  Be careful about
  42. #    the following directories.
  43. #
  44. #    a. CMake - contains helper scripts that make this all work.  You should keep this.
  45. #
  46. #    b. sutil and putil
  47. #              - Almost all of the samples make use of this shared code one way or another, so
  48. #               you should probably keep them until you have your own frameowrk for your
  49. #               code.
  50. #
  51. #    d. data  - This directory contains the cow.obj file used as an example for
  52. #               many of the samples.  You can move cow.obj anywhere as long as
  53. #               you fix all the file paths in the samples you wish to use it in.
  54. #
  55. # 3. You should update the list of sub directories that CMake needs to process below (look
  56. #    for the comment "List of samples found in subdirectories.")
  57. #
  58.  
  59. # The basic flow of execution of this file is to do the following.
  60. #
  61. # 1. Setup the project and other global settings.  This involves processing some helper
  62. #    scripts.
  63. #
  64. # 2. Look for external dependencies, CUDA, and OptiX.
  65. #
  66. # 3. Process all the subdirectories' CMakeLists.txt files.  These files create all the
  67. #    executable and library targets that are used to build the SDK.
  68. #
  69. # 4. As a convenience on Windows, copy the OptiX dlls into the build directories, so OptiX
  70. #    doesn't have to be in the path to run the samples.
  71. #
  72. # 5. Set a CMake variable that indicates we have configured for the first time.  This
  73. #    allows us to override and set varibles' defaults while allowing them to be modified
  74. #    later.
  75.  
  76. # If you have any questions, don't feel shy about posting to the OptiX forums:
  77. # https://devtalk.nvidia.com/default/board/90/
  78.  
  79.  
  80. # This sets up the name of our project.  For our purposes the main thing this controls is
  81. # the name of the VS solution file.
  82. project(RayNerPureRage)
  83.  
  84. # This enforces a particular version of CMake that we require to process the script files
  85. # properly.
  86. cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
  87.  
  88. # As of CMake 2.6 policies were introduced in order to provide a mechanism for
  89. # adding backwards compatibility one feature at a time.  We will just specify
  90. # that all policies will use version 2.6 symantics.
  91. cmake_policy(VERSION 2.6)
  92.  
  93. if( POLICY CMP0072 )
  94.   # FindOpenGL prefers GLVND by default when available
  95.   cmake_policy(SET CMP0072 NEW)
  96. endif()
  97.  
  98. if( POLICY CMP0074 )
  99.   # find_package uses <PackageName>_ROOT variables.
  100.   cmake_policy(SET CMP0074 NEW)
  101. endif()
  102.  
  103.  
  104.  
  105. # Add paths to our CMake code to the module path, so they can be found automatically by
  106. # CMake.
  107. set(CMAKE_MODULE_PATH
  108.   "${CMAKE_SOURCE_DIR}/../SDK/CMake"
  109.   ${CMAKE_MODULE_PATH}
  110.   )
  111.  
  112. # Set the default build to Release.  Note this doesn't do anything for the VS
  113. # default build target which defaults to Debug when you first start it.
  114. IF(NOT CMAKE_BUILD_TYPE)
  115.   SET(CMAKE_BUILD_TYPE "Release" CACHE STRING
  116.       "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
  117.       FORCE)
  118. ENDIF(NOT CMAKE_BUILD_TYPE)
  119.  
  120. # Tells CMake to build all the libraries as shared libraries by default.  This can be
  121. # overrided by individual libraries later.
  122. option(BUILD_SHARED_LIBS "Build shared libraries" ON)
  123.  
  124. ##########
  125. # Process our custom setup scripts here.
  126.  
  127. # Enable C++11. Needs to be done before the include of ConfigCompilerFlags.cmake below.
  128. set(GCC_LIBSTDCPP11 ON)
  129.  
  130. # Include all CMake Macros.
  131. include(Macros)
  132. # Determine information about the compiler
  133. include (CompilerInfo)
  134. # Check for specific machine/compiler options.
  135. include (ConfigCompilerFlags)
  136.  
  137.  
  138.  
  139. #this statically links the MSVSRuntime during compilation
  140.  
  141. set(CompilerFlags
  142.         CMAKE_CXX_FLAGS
  143.         CMAKE_CXX_FLAGS_DEBUG
  144.         CMAKE_CXX_FLAGS_RELEASE
  145.         CMAKE_C_FLAGS
  146.         CMAKE_C_FLAGS_DEBUG
  147.         CMAKE_C_FLAGS_RELEASE
  148.         )
  149. foreach(CompilerFlag ${CompilerFlags})
  150.   string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
  151.   string(REPLACE "/MDd" "/MTd" ${CompilerFlag} "${${CompilerFlag}}")
  152. endforeach()
  153.  
  154. # Turn off the warning that NVCC issues when generating PTX from our CUDA samples.  This
  155. # is a custom extension to the FindCUDA code distributed by CMake.
  156. OPTION(CUDA_REMOVE_GLOBAL_MEMORY_SPACE_WARNING "Suppress the \"Advisory: Cannot tell what pointer points to, assuming global memory space\" warning nvcc makes." ON)
  157.  
  158. # For Xcode 5, gcc is actually clang, so we have to tell CUDA to treat the compiler as
  159. # clang, so that it doesn't mistake it for something else.
  160. if(USING_CLANG_C)
  161.   set(CUDA_HOST_COMPILER "clang" CACHE FILEPATH "Host side compiler used by NVCC")
  162. endif()
  163.  
  164. # CUDA 8 is broken for generating dependencies during configure
  165. option(CUDA_GENERATE_DEPENDENCIES_DURING_CONFIGURE "Generate dependencies during configure time instead of only during build time." OFF)
  166.  
  167. # Find at least a 5.0 version of CUDA.
  168. find_package(CUDA 5.0 REQUIRED)
  169.  
  170. # Present the CUDA_64_BIT_DEVICE_CODE on the default set of options.
  171. mark_as_advanced(CLEAR CUDA_64_BIT_DEVICE_CODE)
  172.  
  173.  
  174. # Add some useful default arguments to the NVCC and NVRTC flags.  This is an example of
  175. # how we use PASSED_FIRST_CONFIGURE.  Once you have configured, this variable is TRUE
  176. # and following block of code will not be executed leaving you free to edit the values
  177. # as much as you wish from the GUI or from ccmake.
  178. if(NOT PASSED_FIRST_CONFIGURE)
  179.   list(FIND CUDA_NVCC_FLAGS "-arch" index)
  180.   if(index EQUAL -1)
  181.     list(APPEND CUDA_NVCC_FLAGS -arch sm_30)
  182.     set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} CACHE STRING "Semi-colon delimit multiple arguments." FORCE)
  183.   endif()
  184.   set(flag "--use_fast_math")
  185.   list(FIND CUDA_NVCC_FLAGS ${flag} index)
  186.   if(index EQUAL -1)
  187.     list(APPEND CUDA_NVCC_FLAGS ${flag})
  188.     set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} CACHE STRING "Semi-colon delimit multiple arguments." FORCE)
  189.   endif()
  190.  
  191.   if (CUDA_VERSION VERSION_LESS "3.0")
  192.     set(flag "--keep")
  193.     list(FIND CUDA_NVCC_FLAGS ${flag} index)
  194.     if(index EQUAL -1)
  195.       list(APPEND CUDA_NVCC_FLAGS ${flag})
  196.       set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} CACHE STRING "Semi-colon delimit multiple arguments." FORCE)
  197.     endif()
  198.   endif()
  199.  
  200.   if( APPLE )
  201.     # Undef'ing __BLOCKS__ for OSX builds.  This is due to a name clash between OSX 10.6
  202.     # C headers and CUDA headers
  203.     set(flag "-U__BLOCKS__")
  204.     list(FIND CUDA_NVCC_FLAGS ${flag} index)
  205.     if(index EQUAL -1)
  206.       list(APPEND CUDA_NVCC_FLAGS ${flag})
  207.       set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} CACHE STRING "Semi-colon delimit multiple arguments." FORCE)
  208.     endif()
  209.   endif()
  210.  
  211.   set(CUDA_NVRTC_FLAGS -arch compute_30 -use_fast_math -lineinfo -default-device -rdc true -D__x86_64 CACHE STRING "Semi-colon delimit multiple arguments." FORCE)
  212. endif(NOT PASSED_FIRST_CONFIGURE)
  213.  
  214. mark_as_advanced(CUDA_NVRTC_FLAGS)
  215.  
  216. # This passes a preprocessor definition to cl.exe when processing CUDA code.
  217. if(USING_WINDOWS_CL)
  218.   list(APPEND CUDA_NVCC_FLAGS --compiler-options /D_USE_MATH_DEFINES)
  219. endif()
  220.  
  221. # Put all the runtime stuff in the same directory.  By default, CMake puts each targets'
  222. # output into their own directory.  We want all the targets to be put in the same
  223. # directory, and we can do this by setting these variables.
  224. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  225. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
  226. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
  227.  
  228. # Create a flag for mac which will allow apps to add the local cuda toolkit
  229. # install path to the app's rpath.
  230. if( APPLE )
  231.   set( CUDA_TOOLKIT_RPATH_FLAG "-Wl,-rpath,${CUDA_TOOLKIT_ROOT_DIR}/lib" )
  232. endif()
  233.  
  234. # Locate the NVRT distribution.  Search the SDK first, then look in the system.
  235. set(OptiX_INSTALL_DIR "${CMAKE_SOURCE_DIR}/../" CACHE PATH "Path to OptiX installed location.")
  236.  
  237. # Search for the OptiX libraries and include files.
  238. find_package(OptiX REQUIRED)
  239.  
  240. # Add the path to the OptiX headers to our include paths.
  241. include_directories(
  242.   "${OptiX_INCLUDE}"
  243.   "${CMAKE_CURRENT_SOURCE_DIR}/cuda"
  244.   )
  245.  
  246. # Select whether to use NVRTC or NVCC to generate PTX
  247. set(CUDA_NVRTC_ENABLED OFF CACHE BOOL "Use NVRTC to compile PTX at run-time instead of NVCC at build-time")
  248.  
  249. ##################################################################
  250. # SUtil compilation
  251.  
  252. set(SAMPLES_PTX_DIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE}")
  253. set(SAMPLES_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
  254.  
  255. set(CUDA_GENERATED_OUTPUT_DIR ${SAMPLES_PTX_DIR})
  256.  
  257. if (WIN32)
  258.   string(REPLACE "/" "\\\\" SAMPLES_PTX_DIR ${SAMPLES_PTX_DIR})
  259. else (WIN32)
  260.   if ( USING_GNU_C AND NOT APPLE)
  261.     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DM_PI=3.14159265358979323846" )
  262.   endif()
  263. endif (WIN32)
  264.  
  265. set(SAMPLES_CUDA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cuda")
  266.  
  267. set(SAMPLES_SUPPORT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../SDK/support")
  268.  
  269. # NVRTC include paths relative to the sample path
  270. set(SAMPLES_RELATIVE_INCLUDE_DIRS "\\
  271.  \"cuda\", \\
  272.  \"sutil\", \\
  273.  \".\", ")
  274.  
  275. # NVRTC absolute include paths to the headers used to build the samples
  276. set(SAMPLES_ABSOLUTE_INCLUDE_DIRS "\\
  277.  \"${OPTIX_INCLUDE_DIR}\", \\
  278.  \"${CUDA_INCLUDE_DIRS}\", ")
  279.  
  280. # Build a null-terminated option list for NVRTC
  281. set(CUDA_NVRTC_OPTIONS)
  282. foreach(flag ${CUDA_NVRTC_FLAGS})
  283.   set(CUDA_NVRTC_OPTIONS "${CUDA_NVRTC_OPTIONS} \\\n  \"${flag}\",")
  284. endforeach()
  285. set(CUDA_NVRTC_OPTIONS "${CUDA_NVRTC_OPTIONS}")
  286.  
  287. configure_file(sampleConfig.h.in sampleConfig.h @ONLY)
  288.  
  289. # Path to sutil.h that all the samples need
  290. include_directories( ${CMAKE_CURRENT_SOURCE_DIR}
  291.                      "${CMAKE_BINARY_DIR}/include"
  292.                      ${CMAKE_CURRENT_BINARY_DIR}
  293.                      ${CUDA_INCLUDE_DIRS}
  294.                      )
  295.  
  296. set(SAMPLES_CUDA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cuda)
  297.  
  298. #########################################################
  299. # OPTIX_add_sample_executable
  300. #
  301. # Convience function for adding samples to the code.  You can copy the contents of this
  302. # funtion into your individual project if you wish to customize the behavior.  Note that
  303. # in CMake, functions have their own scope, whereas macros use the scope of the caller.
  304. function(OPTIX_add_sample_executable target_name_base target_name_var)
  305.  
  306.   set( target_name ${target_name_base} )
  307.   set( ${target_name_var} ${target_name} PARENT_SCOPE )
  308.  
  309.   # These calls will group PTX and CUDA files into their own directories in the Visual
  310.   # Studio projects.
  311.   if (NOT CUDA_NVRTC_ENABLED)
  312.     source_group("PTX Files"  REGULAR_EXPRESSION ".+\\.ptx$")
  313.   endif()
  314.   source_group("CUDA Files" REGULAR_EXPRESSION ".+\\.cu$")
  315.  
  316.   # Separate the sources from the CMake and CUDA options fed to the macro.  This code
  317.   # comes from the CUDA_COMPILE_PTX macro found in FindCUDA.cmake.  We are copying the
  318.   # code here, so that we can use our own name for the target.  target_name is used in the
  319.   # creation of the output file names, and we want this to be unique for each target in
  320.   # the SDK.
  321.   CUDA_GET_SOURCES_AND_OPTIONS(source_files cmake_options options ${ARGN})
  322.  
  323.   if (CUDA_NVRTC_ENABLED)
  324.  
  325.     # Isolate OBJ target files. NVCC should only process these files and leave PTX targets for NVRTC
  326.     set(cu_obj_source_files)
  327.     foreach(file ${source_files})
  328.       get_source_file_property(_cuda_source_format ${file} CUDA_SOURCE_PROPERTY_FORMAT)
  329.       if(${_cuda_source_format} MATCHES "OBJ")
  330.         list(APPEND cu_obj_source_files ${file})
  331.       endif()
  332.     endforeach()
  333.  
  334.     # Create the rules to build the OBJ from the CUDA files.
  335.     CUDA_WRAP_SRCS( ${target_name} OBJ generated_files ${cu_obj_source_files} ${cmake_options} OPTIONS ${options} )
  336.   else()
  337.  
  338.     # Create the rules to build the PTX and OBJ from the CUDA files.
  339.     CUDA_WRAP_SRCS( ${target_name} PTX generated_files ${source_files} ${cmake_options} OPTIONS ${options} )
  340.   endif()
  341.  
  342.  
  343.   # Here is where we create the rule to make the executable.  We define a target name and
  344.   # list all the source files used to create the target.  In addition we also pass along
  345.   # the cmake_options parsed out of the arguments.
  346.   add_executable(${target_name}
  347.     ${source_files}
  348.     ${generated_files}
  349.     ${cmake_options}
  350.     )
  351.  
  352.  
  353.   # Most of the samples link against the sutil library and the optix library.  Here is the
  354.   # rule that specifies this linkage.
  355.   target_link_libraries( ${target_name}
  356.     ${GLFW_LIB_NAME}
  357.     imgui
  358.     sutil_7_sdk
  359.     )
  360.  
  361.   set_target_properties( ${target_name} PROPERTIES
  362.     COMPILE_DEFINITIONS OPTIX_SAMPLE_NAME_DEFINE=${target_name}
  363.     MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Release>:Release>")
  364.  
  365.       target_link_libraries( ${target_name}
  366.       )
  367.  
  368.   if( UNIX AND NOT APPLE )
  369.     # Force using RPATH instead of RUNPATH on Debian
  370.     target_link_libraries( ${target_name} "-Wl,--disable-new-dtags" )
  371.   endif()
  372.  
  373.   if(USING_GNU_CXX)
  374.     target_link_libraries( ${target_name} m ) # Explicitly link against math library (C samples don't do that by default)
  375.   endif()
  376. endfunction()
  377.  
  378. #########################################################
  379. #  List of samples found in subdirectories.
  380. #
  381. # If you wish to start your own sample, you can copy one of the sample's directories.
  382. # Just make sure you rename all the occurances of the sample's name in the C code as well
  383. # and the CMakeLists.txt file.
  384. add_subdirectory( RayNer )
  385.  
  386.  
  387. # Our sutil library.  The rules to build it are found in the subdirectory.
  388. add_subdirectory(sutil)
  389. # Third-party support libraries.
  390. add_subdirectory(support)
  391.  
  392. #################################################################
  393.  
  394. # Now that everything is done, indicate that we have finished configuring at least once.
  395. # We use this variable to set certain defaults only on the first pass, so that we don't
  396. # continually set them over and over again.
  397. set(PASSED_FIRST_CONFIGURE ON CACHE INTERNAL "Already Configured once?")
Advertisement
Add Comment
Please, Sign In to add comment