-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
175 lines (146 loc) · 6.36 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
cmake_minimum_required(VERSION 3.6...3.31)
get_filename_component(PROJNAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
Project(${PROJNAME})
Message(STATUS "-------------------------------")
Message(STATUS "Processing Project ${PROJNAME}:")
#####################################################################################
# look for nvpro_core 1) as a sub-folder 2) at some other locations
# this cannot be put anywhere else since we still didn't find setup.cmake yet
# which nvprocore tag or branch to download if repo not found
set(NVPRO_GIT_TAG main)
# Where to decompress nvprocore source code if repo not found
set(NVPRO_TGT_SRC_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/_deps)
if(NOT BASE_DIRECTORY)
find_path(BASE_DIRECTORY
NAMES nvpro_core/cmake/setup.cmake
PATHS ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../.. ${CMAKE_CURRENT_SOURCE_DIR}/external
DOC "Directory containing nvpro_core"
)
endif()
if(EXISTS ${BASE_DIRECTORY}/nvpro_core/cmake/setup.cmake)
set(OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin_x64)
include(${BASE_DIRECTORY}/nvpro_core/cmake/setup.cmake)
else()
# nvpro_core not found, will try to download.
# first find where the current sample comes from
execute_process(
COMMAND git config --get remote.origin.url
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_REPO_URL OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Check if "github.com" is in URL
string(FIND "${GIT_REPO_URL}" "github.com" FOUND_INDEX)
if (FOUND_INDEX GREATER -1)
# Use regex to extract everything up to and including "github.com"
string(REGEX MATCH ".*github\\.com" GIT_BASE_URL "${GIT_REPO_URL}")
# construct URL
string(FIND "${GIT_REPO_URL}" "git@" SSH_FOUND_INDEX)
if (SSH_FOUND_INDEX GREATER -1) # ssh
set(NVPRO_GIT_URL ${GIT_BASE_URL}:nvpro-samples/nvpro_core.git)
else() # https
set(NVPRO_GIT_URL ${GIT_BASE_URL}/nvpro-samples/nvpro_core.git)
endif()
if("${NVPRO_GIT_TAG}" STREQUAL "main" )
set(NVPRO_GIT_TAG master)
endif()
message("Sample comes from github , nvprocore is at " ${NVPRO_GIT_URL} )
else ()
# reconstruct the path to nvpro_core, preserving the protocol
string(REGEX MATCH "^[^/]+//[^/]+/" GIT_BASE_URL "${GIT_REPO_URL}")
# construct URL
set(NVPRO_GIT_URL ${GIT_BASE_URL}devtechproviz/nvpro-samples/nvpro_core.git)
# message("Sample comes from prod server, nvprocore is at " ${NVPRO_GIT_URL})
endif()
# let's clone the commit we need, depth to 1 so that we do not download the full history
execute_process(
COMMAND git clone --depth 1 --branch ${NVPRO_GIT_TAG} ${NVPRO_GIT_URL} ${CMAKE_CURRENT_BINARY_DIR}/_deps/nvpro_core
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
# do the search again with downloaded version, use find to be sure everyting runs ok
find_path(BASE_DIRECTORY
NAMES nvpro_core
PATHS ${CMAKE_CURRENT_BINARY_DIR}/_deps
REQUIRED
DOC "Directory containing nvpro_core"
)
# invoke the setup
if(EXISTS ${BASE_DIRECTORY}/nvpro_core/cmake/setup.cmake)
set(OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin_x64)
include(${BASE_DIRECTORY}/nvpro_core/cmake/setup.cmake)
else()
message(FATAL_ERROR "could not find base directory or download nvpro_core, please set BASE_DIRECTORY to folder containing nvpro_core")
endif()
endif()
set(NVPRO_CORE_DIR ${BASE_DIRECTORY}/nvpro_core)
_add_project_definitions(${PROJNAME})
# Download the default scene
download_files(FILENAMES bunny_v2.zip EXTRACT)
#####################################################################################
# additions from packages needed for this sample
# add refs in LIBRARIES_OPTIMIZED
# add refs in LIBRARIES_DEBUG
# add files in PACKAGE_SOURCE_FILES
_add_package_VulkanSDK()
_add_package_ShaderC()
_add_package_IMGUI()
#_add_package_NVML()
#####################################################################################
# process the rest of some cmake code that needs to be done *after* the packages add
_add_nvpro_core_lib()
if(NOT TARGET nv_cluster_builder)
add_subdirectory(external/nv_cluster_builder)
endif()
if(NOT TARGET meshoptimizer)
add_subdirectory(external/meshoptimizer)
endif()
#####################################################################################
# Source files for this project
#
file(GLOB SOURCE_FILES src/*.*)
file(GLOB SHADER_FILES shaders/*.glsl shaders/*.h)
list(APPEND SHADER_FILES ${NVPRO_CORE_DIR}/nvvkhl/shaders/dh_sky.h)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/shaders)
include_directories(${NVPRO_CORE_DIR}/nvvkhl/shaders)
#####################################################################################
# Executable
#
if(WIN32 AND NOT GLUT_FOUND)
add_definitions(/wd4996) #remove printf warning
add_definitions(/wd4244) #remove double to float conversion warning
add_definitions(/wd4305) #remove double to float truncation warning
else()
add_definitions(-fpermissive)
endif()
add_executable(${PROJNAME} ${SOURCE_FILES} ${COMMON_SOURCE_FILES} ${PACKAGE_SOURCE_FILES} ${SHADER_FILES})
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJNAME})
target_compile_definitions(${PROJNAME} PRIVATE NVPRO_CORE_DIR="${NVPRO_CORE_DIR}")
#####################################################################################
# common source code needed for this sample
#
source_group(common FILES
${COMMON_SOURCE_FILES}
${PACKAGE_SOURCE_FILES}
)
source_group("Shader Files" FILES ${SHADER_FILES})
source_group("Source Files" FILES ${SOURCE_FILES})
if(UNIX)
set(UNIXLINKLIBS dl pthread)
else()
set(UNIXLINKLIBS)
endif()
#####################################################################################
# Linkage
#
target_link_libraries(${PROJNAME} ${PLATFORM_LIBRARIES} nvpro_core nv_cluster_builder meshoptimizer)
foreach(DEBUGLIB ${LIBRARIES_DEBUG})
target_link_libraries(${PROJNAME} debug ${DEBUGLIB})
endforeach(DEBUGLIB)
foreach(RELEASELIB ${LIBRARIES_OPTIMIZED})
target_link_libraries(${PROJNAME} optimized ${RELEASELIB})
endforeach(RELEASELIB)
#####################################################################################
# copies binaries that need to be put next to the exe files (ZLib, etc.)
#
_finalize_target( ${PROJNAME} )
install(FILES ${SHADER_FILES} CONFIGURATIONS Release DESTINATION "bin_${ARCH}/GLSL_${PROJNAME}")
install(FILES ${SHADER_FILES} CONFIGURATIONS Debug DESTINATION "bin_${ARCH}_debug/GLSL_${PROJNAME}")