Skip to content

Commit 6633a51

Browse files
CMake: updated build/install instructions for external third-party libs
1 parent c090a57 commit 6633a51

File tree

2 files changed

+69
-76
lines changed

2 files changed

+69
-76
lines changed

Graphics/GraphicsEngineVulkan/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ elseif(PLATFORM_IOS OR PLATFORM_TVOS)
254254
find_library(METAL_LIBRARY Metal)
255255
find_library(QUARTZ_CORE QuartzCore)
256256
find_library(UI_KIT UIKit)
257+
# Note that volk may be defined by external CMake, but we don't use it on iOS/tvOS
257258
list(APPEND PRIVATE_DEPENDENCIES ${MOLTENVK_LIBRARY} ${CORE_GRAPHICS} ${METAL_LIBRARY} ${QUARTZ_CORE} ${UI_KIT})
258259
elseif(PLATFORM_LINUX)
259260
list(APPEND PRIVATE_DEPENDENCIES volk::volk_headers)

ThirdParty/CMakeLists.txt

Lines changed: 68 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ cmake_minimum_required (VERSION 3.6)
66
# instead:
77
set(CMAKE_POLICY_DEFAULT_CMP0063 NEW)
88

9-
if (GL_SUPPORTED AND (PLATFORM_WIN32 OR PLATFORM_LINUX OR PLATFORM_MACOS))
10-
if (NOT TARGET GLEW::glew)
11-
add_subdirectory(glew)
12-
if (DILIGENT_INSTALL_CORE)
13-
install(TARGETS glew-static
14-
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/${DILIGENT_CORE_DIR}/$<CONFIG>"
15-
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/${DILIGENT_CORE_DIR}/$<CONFIG>"
16-
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/${DILIGENT_CORE_DIR}/$<CONFIG>"
17-
)
18-
endif()
19-
install(FILES glew/LICENSE.txt DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}" RENAME GLEW-License.txt)
9+
if (GL_SUPPORTED AND (PLATFORM_WIN32 OR PLATFORM_LINUX OR PLATFORM_MACOS) AND (NOT TARGET GLEW::glew))
10+
add_subdirectory(glew)
11+
if (DILIGENT_INSTALL_CORE)
12+
install(TARGETS glew-static
13+
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/${DILIGENT_CORE_DIR}/$<CONFIG>"
14+
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/${DILIGENT_CORE_DIR}/$<CONFIG>"
15+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/${DILIGENT_CORE_DIR}/$<CONFIG>"
16+
)
2017
endif()
18+
install(FILES glew/LICENSE.txt DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}" RENAME GLEW-License.txt)
2119
endif()
2220

2321
if (VULKAN_SUPPORTED OR METAL_SUPPORTED)
@@ -28,8 +26,8 @@ if (VULKAN_SUPPORTED OR METAL_SUPPORTED)
2826
# Note that SPIRV-Headers_SOURCE_DIR variable is normally created by project(SPIRV-Headers)
2927
set(SPIRV-Headers_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/SPIRV-Headers")
3028
target_include_directories(SPIRV-Headers INTERFACE "${SPIRV-Headers_SOURCE_DIR}/include")
29+
install(FILES "${SPIRV-Headers_SOURCE_DIR}/LICENSE" DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}" RENAME SPIRV-Headers-License.txt)
3130
endif()
32-
install(FILES "${SPIRV-Headers_SOURCE_DIR}/LICENSE" DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}" RENAME SPIRV-Headers-License.txt)
3331

3432
if (NOT TARGET Vulkan::Headers)
3533
# Manually add the Vulkan-Headers target as this is all we need and the
@@ -39,48 +37,45 @@ if (VULKAN_SUPPORTED OR METAL_SUPPORTED)
3937
set(Vulkan-Headers_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Headers")
4038
add_library(Vulkan::Headers ALIAS Vulkan-Headers)
4139
target_include_directories(Vulkan-Headers INTERFACE "${Vulkan-Headers_SOURCE_DIR}/include")
40+
install(FILES "${Vulkan-Headers_SOURCE_DIR}/LICENSE.txt" DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}" RENAME Vulkan-Headers-License.txt)
4241
endif()
43-
install(FILES "${Vulkan-Headers_SOURCE_DIR}/LICENSE.txt" DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}" RENAME Vulkan-Headers-License.txt)
4442

4543
option(DILIGENT_NO_GLSLANG "Do NOT build glslang compiler" OFF)
4644
option(DILIGENT_IMPROVE_SPIRV_TOOLS_DEBUG_PERF "Enable some optimizations for SPIRV-Tools, glslang, SPIRV-Cross and related projects in debug build to improve performance" ON)
4745

48-
if (NOT (${DILIGENT_NO_GLSLANG} AND ${DILIGENT_NO_HLSL}))
49-
if (NOT TARGET SPIRV-Tools-static)
50-
set(SPIRV_SKIP_TESTS ON CACHE BOOL "Skip SPIRV tests")
51-
set(SPIRV_BUILD_COMPRESSION OFF CACHE BOOL "Do not build SPIRV compressing codec")
52-
set(SPIRV_SKIP_EXECUTABLES ON CACHE BOOL "Skip building SPIRV executable and tests along with the library")
53-
set(SKIP_SPIRV_TOOLS_INSTALL ON CACHE BOOL "Skip SPIRV tools installation")
54-
set(SPIRV_WERROR OFF CACHE BOOL "Do not enable error on warning")
55-
if (${DILIGENT_IMPROVE_SPIRV_TOOLS_DEBUG_PERF})
56-
set(SPIRV_CHECK_CONTEXT OFF CACHE BOOL "Do not check if the IR context is in a valid state")
57-
endif()
58-
set(CMAKE_MACOSX_RPATH TRUE)
59-
add_subdirectory(SPIRV-Tools)
60-
set_directory_root_folder("SPIRV-Tools" "DiligentCore/ThirdParty/SPIRV-Tools")
61-
# We only need SPIRV-Tools-opt for glslang that also depends on SPIRV-Tools-static.
62-
# Exclude all other targets from the build to save build time
63-
set(SPIRV_TOOLS_EXCLUDE_TARGETS SPIRV-Tools-link SPIRV-Tools-lint SPIRV-Tools-reduce SPIRV-Tools-shared)
64-
set_target_properties(${SPIRV_TOOLS_EXCLUDE_TARGETS} PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)
46+
if (NOT (${DILIGENT_NO_GLSLANG} AND ${DILIGENT_NO_HLSL}) AND (NOT TARGET SPIRV-Tools-static))
47+
set(SPIRV_SKIP_TESTS ON CACHE BOOL "Skip SPIRV tests")
48+
set(SPIRV_BUILD_COMPRESSION OFF CACHE BOOL "Do not build SPIRV compressing codec")
49+
set(SPIRV_SKIP_EXECUTABLES ON CACHE BOOL "Skip building SPIRV executable and tests along with the library")
50+
set(SKIP_SPIRV_TOOLS_INSTALL ON CACHE BOOL "Skip SPIRV tools installation")
51+
set(SPIRV_WERROR OFF CACHE BOOL "Do not enable error on warning")
52+
if (${DILIGENT_IMPROVE_SPIRV_TOOLS_DEBUG_PERF})
53+
set(SPIRV_CHECK_CONTEXT OFF CACHE BOOL "Do not check if the IR context is in a valid state")
6554
endif()
55+
set(CMAKE_MACOSX_RPATH TRUE)
56+
add_subdirectory(SPIRV-Tools)
57+
set_directory_root_folder("SPIRV-Tools" "DiligentCore/ThirdParty/SPIRV-Tools")
58+
# We only need SPIRV-Tools-opt for glslang that also depends on SPIRV-Tools-static.
59+
# Exclude all other targets from the build to save build time
60+
set(SPIRV_TOOLS_EXCLUDE_TARGETS SPIRV-Tools-link SPIRV-Tools-lint SPIRV-Tools-reduce SPIRV-Tools-shared)
61+
set_target_properties(${SPIRV_TOOLS_EXCLUDE_TARGETS} PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)
62+
6663
set(THIRD_PARTY_LIBS SPIRV-Tools-static SPIRV-Tools-opt)
6764
install(FILES "${spirv-tools_SOURCE_DIR}/LICENSE" DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}" RENAME SPIRV-Tools-License.txt)
6865
endif()
6966

70-
if (NOT ${DILIGENT_NO_GLSLANG})
71-
if (NOT TARGET glslang)
72-
set(ENABLE_GLSLANG_BINARIES OFF CACHE BOOL "Do not build glslang binaries")
73-
set(ENABLE_SPVREMAPPER OFF CACHE BOOL "Do not build SPIRV remapper")
74-
set(SKIP_GLSLANG_INSTALL ON CACHE BOOL "Skip glslang installation")
75-
set(ENABLE_CTEST OFF CACHE BOOL "Disable testing")
76-
add_subdirectory(glslang)
77-
set_directory_root_folder("glslang" "DiligentCore/ThirdParty/glslang")
78-
79-
# glslang "kindly" sets global CMAKE_DEBUG_POSTFIX to "d", which we have to unset now
80-
unset(CMAKE_DEBUG_POSTFIX CACHE)
81-
endif()
67+
if (NOT ${DILIGENT_NO_GLSLANG} AND (NOT TARGET glslang))
68+
set(ENABLE_GLSLANG_BINARIES OFF CACHE BOOL "Do not build glslang binaries")
69+
set(ENABLE_SPVREMAPPER OFF CACHE BOOL "Do not build SPIRV remapper")
70+
set(SKIP_GLSLANG_INSTALL ON CACHE BOOL "Skip glslang installation")
71+
set(ENABLE_CTEST OFF CACHE BOOL "Disable testing")
72+
add_subdirectory(glslang)
73+
set_directory_root_folder("glslang" "DiligentCore/ThirdParty/glslang")
74+
75+
# glslang "kindly" sets global CMAKE_DEBUG_POSTFIX to "d", which we have to unset now
76+
unset(CMAKE_DEBUG_POSTFIX CACHE)
77+
8278
list(APPEND THIRD_PARTY_LIBS GenericCodeGen glslang OGLCompiler OSDependent SPIRV HLSL MachineIndependent)
83-
get_target_property(GLSLANG_SOURCE_DIR glslang SOURCE_DIR)
8479
install(FILES "${glslang_SOURCE_DIR}/LICENSE.txt" DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}" RENAME GLSLang-License.txt)
8580
endif()
8681

@@ -100,14 +95,14 @@ if (VULKAN_SUPPORTED OR METAL_SUPPORTED)
10095
set(SPIRV_CROSS_NAMESPACE_OVERRIDE diligent_spirv_cross CACHE STRING "Override the namespace used in the C++ API.")
10196
add_subdirectory(SPIRV-Cross)
10297
set_directory_root_folder("SPIRV-Cross" "DiligentCore/ThirdParty/SPIRV-Cross")
103-
endif()
10498

105-
list(APPEND THIRD_PARTY_LIBS spirv-cross-core)
106-
if (METAL_SUPPORTED)
107-
list(APPEND THIRD_PARTY_LIBS spirv-cross-msl spirv-cross-glsl)
108-
endif()
99+
list(APPEND THIRD_PARTY_LIBS spirv-cross-core)
100+
if (METAL_SUPPORTED)
101+
list(APPEND THIRD_PARTY_LIBS spirv-cross-msl spirv-cross-glsl)
102+
endif()
109103

110-
install(FILES "${SPIRV-Cross_SOURCE_DIR}/LICENSE" DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}" RENAME SPIRV-Cross-License.txt)
104+
install(FILES "${SPIRV-Cross_SOURCE_DIR}/LICENSE" DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}" RENAME SPIRV-Cross-License.txt)
105+
endif()
111106

112107
if (DILIGENT_INSTALL_CORE)
113108
install(TARGETS ${THIRD_PARTY_LIBS}
@@ -133,36 +128,33 @@ if (VULKAN_SUPPORTED OR METAL_SUPPORTED)
133128
)
134129
endif()
135130

136-
if (VULKAN_SUPPORTED AND (PLATFORM_WIN32 OR PLATFORM_LINUX OR PLATFORM_MACOS OR PLATFORM_ANDROID))
137-
if (NOT TARGET volk::volk)
138-
set(VOLK_PULL_IN_VULKAN OFF)
139-
set(VOLK_INSTALL OFF)
140-
add_subdirectory(volk)
141-
set_target_properties(volk
142-
PROPERTIES
143-
EXCLUDE_FROM_ALL 1
144-
EXCLUDE_FROM_DEFAULT_BUILD 1
145-
FOLDER "DiligentCore/ThirdParty/volk"
146-
)
147-
endif()
131+
if (VULKAN_SUPPORTED AND (PLATFORM_WIN32 OR PLATFORM_LINUX OR PLATFORM_MACOS OR PLATFORM_ANDROID) AND (NOT TARGET volk::volk))
132+
set(VOLK_PULL_IN_VULKAN OFF)
133+
set(VOLK_INSTALL OFF)
134+
add_subdirectory(volk)
135+
set_target_properties(volk
136+
PROPERTIES
137+
EXCLUDE_FROM_ALL 1
138+
EXCLUDE_FROM_DEFAULT_BUILD 1
139+
FOLDER "DiligentCore/ThirdParty/volk"
140+
)
148141
install(FILES "${volk_SOURCE_DIR}/LICENSE.md" DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}" RENAME Volk-License.md)
149142
endif()
150143

151-
if (${DILIGENT_BUILD_GOOGLE_TEST})
152-
if (NOT TARGET gtest)
153-
set(INSTALL_GTEST OFF CACHE BOOL "Do not install googletest")
154-
set(BUILD_GMOCK OFF CACHE BOOL "Do not build gmock")
155-
set(gtest_force_shared_crt ON CACHE BOOL "Use shared (DLL) run-time lib even when Google Test is built as static lib.")
156-
add_subdirectory(googletest)
157-
set_directory_root_folder("googletest" "DiligentCore/ThirdParty/googletest")
158-
set_target_properties(gtest gtest_main PROPERTIES
159-
CXX_VISIBILITY_PRESET hidden # -fvisibility=hidden
160-
C_VISIBILITY_PRESET hidden # -fvisibility=hidden
161-
VISIBILITY_INLINES_HIDDEN TRUE
162-
)
163-
endif()
144+
if ((${DILIGENT_BUILD_GOOGLE_TEST}) AND (NOT TARGET gtest))
145+
set(INSTALL_GTEST OFF CACHE BOOL "Do not install googletest")
146+
set(BUILD_GMOCK OFF CACHE BOOL "Do not build gmock")
147+
set(gtest_force_shared_crt ON CACHE BOOL "Use shared (DLL) run-time lib even when Google Test is built as static lib.")
148+
add_subdirectory(googletest)
149+
set_directory_root_folder("googletest" "DiligentCore/ThirdParty/googletest")
150+
set_target_properties(gtest gtest_main PROPERTIES
151+
CXX_VISIBILITY_PRESET hidden # -fvisibility=hidden
152+
C_VISIBILITY_PRESET hidden # -fvisibility=hidden
153+
VISIBILITY_INLINES_HIDDEN TRUE
154+
)
155+
164156
get_target_property(GTEST_SOURCE_DIR gtest SOURCE_DIR)
165-
install(FILES "${GTEST_SOURCE_DIR}/../LICENSE" DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}" RENAME googletest-License.txt)
157+
install(FILES "googletest/LICENSE" DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}" RENAME googletest-License.txt)
166158
endif()
167159

168160
if (NOT TARGET xxHash::xxhash)
@@ -171,8 +163,8 @@ if (NOT TARGET xxHash::xxhash)
171163
set(XXHASH_BUILD_ENABLE_INLINE_API OFF)
172164
add_subdirectory(xxHash/cmake_unofficial)
173165
set_directory_root_folder("xxHash/cmake_unofficial" "DiligentCore/ThirdParty/xxHash")
166+
install(FILES "${xxHash_SOURCE_DIR}/../LICENSE" DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}" RENAME xxHash-License.txt)
174167
endif()
175-
install(FILES "${xxHash_SOURCE_DIR}/../LICENSE" DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}" RENAME xxHash-License.txt)
176168

177169
install(FILES stb/stb_image_write_license.txt DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}")
178170
install(FILES DirectXShaderCompiler/LICENSE.TXT DESTINATION "Licenses/ThirdParty/${DILIGENT_CORE_DIR}" RENAME DXC-License.txt)

0 commit comments

Comments
 (0)