-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
138 lines (113 loc) · 4.95 KB
/
CMakeLists.txt
File metadata and controls
138 lines (113 loc) · 4.95 KB
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
if(PLATFORM_WIN32 OR PLATFORM_LINUX)
cmake_minimum_required (VERSION 3.13)
option(DILIGENT_INSTALL_SAMPLES "Enable installation of samples and tutorials" ON)
elseif(PLATFORM_EMSCRIPTEN)
cmake_minimum_required (VERSION 3.13)
set(CMAKE_EXECUTABLE_SUFFIX ".html")
else()
cmake_minimum_required (VERSION 3.6)
set(DILIGENT_INSTALL_SAMPLES OFF)
endif()
option(DILIGENT_BUILD_SAMPLE_BASE_ONLY "Build only SampleBase project" OFF)
function(add_sample_app APP_NAME IDE_FOLDER SOURCE INCLUDE SHADERS ASSETS)
set_source_files_properties(${SHADERS} PROPERTIES VS_TOOL_OVERRIDE "None")
set(ALL_ASSETS ${ASSETS} ${SHADERS})
add_target_platform_app(${APP_NAME} "${SOURCE}" "${INCLUDE}" "${ALL_ASSETS}")
set_source_files_properties(${ALL_ASSETS} PROPERTIES
VS_DEPLOYMENT_LOCATION "."
MACOSX_PACKAGE_LOCATION "Resources"
)
if(PLATFORM_WIN32)
set_target_properties(${APP_NAME} PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/assets"
)
copy_required_dlls(${APP_NAME})
append_sample_base_win32_source(${APP_NAME})
elseif(PLATFORM_UNIVERSAL_WINDOWS)
append_sample_base_uwp_source(${APP_NAME})
package_required_dlls(${APP_NAME})
endif()
target_include_directories(${APP_NAME}
PRIVATE
src
)
target_link_libraries(${APP_NAME}
PRIVATE
# On Linux we must have Diligent-NativeAppBase go first, otherwise the linker
# will fail to resolve Diligent::CreateApplication() function.
Diligent-NativeAppBase
Diligent-BuildSettings
Diligent-SampleBase
)
set_common_target_properties(${APP_NAME})
if(MSVC)
# Disable MSVC-specific warnings
# - w4201: nonstandard extension used: nameless struct/union
target_compile_options(${APP_NAME} PRIVATE /wd4201)
endif()
set_target_properties(${APP_NAME} PROPERTIES
FOLDER ${IDE_FOLDER}
)
source_group("src" FILES ${SOURCE} ${INCLUDE})
source_group("assets" FILES ${ALL_ASSETS})
target_sources(${APP_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/readme.md")
set_source_files_properties(
"${CMAKE_CURRENT_SOURCE_DIR}/readme.md" PROPERTIES HEADER_FILE_ONLY TRUE
)
if(PLATFORM_WIN32 OR PLATFORM_LINUX)
# Copy assets to target folder
add_custom_command(TARGET ${APP_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_CURRENT_SOURCE_DIR}/assets"
"\"$<TARGET_FILE_DIR:${APP_NAME}>\"")
endif()
if(PLATFORM_MACOS AND VULKAN_LIB_PATH)
# Configure rpath so that executables can find vulkan library
set_target_properties(${APP_NAME} PROPERTIES
BUILD_RPATH "${VULKAN_LIB_PATH}"
)
endif()
if(PLATFORM_EMSCRIPTEN)
set(RESOURCE_PATH "${PROJECT_SOURCE_DIR}/assets/")
target_link_options(${APP_NAME} PRIVATE "SHELL: -s SINGLE_FILE -s ALLOW_MEMORY_GROWTH=1 --preload-file '${RESOURCE_PATH}@'")
append_sample_base_emscripten_source(${APP_NAME})
endif()
if(DILIGENT_INSTALL_SAMPLES)
# Install instructions
file(RELATIVE_PATH TUTORIAL_REL_PATH "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
install(TARGETS ${APP_NAME}
DESTINATION "${CMAKE_INSTALL_BINDIR}/${TUTORIAL_REL_PATH}/$<CONFIG>")
if(PLATFORM_LINUX OR PLATFORM_WIN32)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/assets/"
DESTINATION "${CMAKE_INSTALL_BINDIR}/${TUTORIAL_REL_PATH}/$<CONFIG>")
endif()
if(PLATFORM_WIN32)
get_supported_backends(BACKEND_LIBRARIES)
install(TARGETS ${BACKEND_LIBRARIES}
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/${TUTORIAL_REL_PATH}/$<CONFIG>"
LIBRARY DESTINATION "${CMAKE_INSTALL_BINDIR}/${TUTORIAL_REL_PATH}/$<CONFIG>"
ARCHIVE DESTINATION "${CMAKE_INSTALL_BINDIR}/${TUTORIAL_REL_PATH}/$<CONFIG>")
endif()
if(PLATFORM_LINUX)
set_target_properties(${APP_NAME} PROPERTIES
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${DILIGENT_CORE_DIR}/${CMAKE_BUILD_TYPE}"
)
endif()
endif()
endfunction()
add_subdirectory(ThirdParty)
if(TARGET Diligent-NativeAppBase AND TARGET Diligent-TextureLoader AND TARGET Diligent-Imgui)
add_subdirectory(SampleBase)
endif()
if(NOT ${DILIGENT_BUILD_SAMPLE_BASE_ONLY} AND TARGET Diligent-SampleBase)
add_subdirectory(Samples)
add_subdirectory(Tutorials)
endif()
if(PLATFORM_ANDROID)
add_subdirectory(Android/HelloAR)
endif()
if(NOT PLATFORM_FREEBSD AND NOT ${DILIGENT_BUILD_SAMPLE_BASE_ONLY} AND (D3D11_SUPPORTED OR D3D12_SUPPORTED OR GL_SUPPORTED OR GLES_SUPPORTED))
add_subdirectory(UnityPlugin)
endif()
# Create a custom target to run source code formatting validation command
add_format_validation_target(DiligentSamples "${CMAKE_CURRENT_SOURCE_DIR}" DiligentSamples)