Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/CMakeLists.txt
1558 views
1
# Copyright 2020 The Shaderc Authors. All rights reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
# http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14
15
cmake_minimum_required(VERSION 3.17.2)
16
17
project(shaderc)
18
enable_testing()
19
20
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
21
message(STATUS "No build type selected, default to Debug")
22
set(CMAKE_BUILD_TYPE "Debug")
23
endif()
24
25
message(STATUS "Shaderc: build type is \"${CMAKE_BUILD_TYPE}\".")
26
27
option(SHADERC_ENABLE_WGSL_OUTPUT "Enable WGSL output" OFF)
28
29
option(SHADERC_SKIP_INSTALL "Skip installation" ${SHADERC_SKIP_INSTALL})
30
if(NOT ${SHADERC_SKIP_INSTALL})
31
set(SHADERC_ENABLE_INSTALL ON)
32
endif()
33
34
option(SHADERC_SKIP_TESTS "Skip building tests" ${SHADERC_SKIP_TESTS})
35
if(NOT ${SHADERC_SKIP_TESTS})
36
set(SHADERC_ENABLE_TESTS ON)
37
endif()
38
if(${SHADERC_ENABLE_TESTS})
39
message(STATUS "Configuring Shaderc to build tests.")
40
else()
41
message(STATUS "Configuring Shaderc to avoid building tests.")
42
endif()
43
44
option(SHADERC_SKIP_EXAMPLES "Skip building examples" ${SHADERC_SKIP_EXAMPLES})
45
if(NOT ${SHADERC_SKIP_EXAMPLES})
46
set(SHADERC_ENABLE_EXAMPLES ON)
47
endif()
48
if(${SHADERC_ENABLE_EXAMPLES})
49
message(STATUS "Configuring Shaderc to build examples.")
50
else()
51
message(STATUS "Configuring Shaderc to avoid building examples.")
52
endif()
53
54
option(SHADERC_SKIP_COPYRIGHT_CHECK "Skip copyright check" ${SHADERC_SKIP_COPYRIGHT_CHECK})
55
if(NOT ${SHADERC_SKIP_COPYRIGHT_CHECK})
56
set(SHADERC_ENABLE_COPYRIGHT_CHECK ON)
57
endif()
58
if(${SHADERC_ENABLE_COPYRIGHT_CHECK})
59
message(STATUS "Configuring Shaderc to check copyrights.")
60
else()
61
message(STATUS "Configuring Shaderc to avoid checking copyrights.")
62
endif()
63
64
option(SHADERC_ENABLE_WERROR_COMPILE "Enable passing -Werror to compiler, if available" ON)
65
66
set (CMAKE_CXX_STANDARD 17)
67
68
include(GNUInstallDirs)
69
include(cmake/setup_build.cmake)
70
include(cmake/utils.cmake)
71
include(CheckCXXCompilerFlag)
72
73
set(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS ${DISABLE_EXCEPTIONS} CACHE BOOL "Coupling SPIRV-Cross exception conversion to DISABLE_EXCEPTIONS" FORCE)
74
if(DISABLE_EXCEPTIONS)
75
# Need to set additional values here, since some of the wrapped code occurs in
76
# .h/.hpp files, so maybe included outside of the library.
77
add_definitions(-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
78
endif()
79
80
# These flags are not supported on Windows and some older version of GCC
81
# that our bots use.
82
# Warning about implicit fallthrough in switch blocks
83
check_cxx_compiler_flag(-Wimplicit-fallthrough COMPILER_SUPPORTS_FALLTHROUGH_WARNING)
84
if (COMPILER_SUPPORTS_FALLTHROUGH_WARNING)
85
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wimplicit-fallthrough")
86
endif()
87
88
# Warning about extra semi-colons
89
check_cxx_compiler_flag(-Wextra-semi COMPILER_SUPPORTS_EXTRA_SEMI_WARNING)
90
if (COMPILER_SUPPORTS_EXTRA_SEMI_WARNING)
91
add_compile_options("-Wextra-semi")
92
endif()
93
94
if(${CMAKE_VERSION} VERSION_LESS_EQUAL "3.12")
95
find_package(PythonInterp 3 REQUIRED)
96
else ()
97
find_package(Python COMPONENTS Interpreter REQUIRED)
98
endif ()
99
100
if (SHADERC_ENABLE_COPYRIGHT_CHECK)
101
add_custom_target(check-copyright ALL
102
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/utils/add_copyright.py
103
--check
104
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
105
COMMENT "Check copyright")
106
endif()
107
108
add_custom_target(add-copyright
109
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/utils/add_copyright.py
110
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
111
COMMENT "Add copyright")
112
113
if(MSVC)
114
option(SHADERC_ENABLE_SHARED_CRT
115
"Use the shared CRT instead of the static CRT"
116
OFF)
117
if (SHADERC_ENABLE_SHARED_CRT)
118
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
119
else()
120
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
121
endif()
122
endif(MSVC)
123
124
125
# Configure subdirectories.
126
# We depend on these for later projects, so they should come first.
127
add_subdirectory(third_party)
128
129
add_subdirectory(libshaderc_util)
130
add_subdirectory(libshaderc)
131
add_subdirectory(glslc)
132
if(${SHADERC_ENABLE_EXAMPLES})
133
add_subdirectory(examples)
134
endif()
135
136
add_custom_target(build-version
137
${PYTHON_EXECUTABLE}
138
${CMAKE_CURRENT_SOURCE_DIR}/utils/update_build_version.py
139
${shaderc_SOURCE_DIR} ${spirv-tools_SOURCE_DIR} ${glslang_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/build-version.inc
140
COMMENT "Update build-version.inc in the Shaderc build directory (if necessary).")
141
142
function(define_pkg_config_file NAME LIBS)
143
add_custom_target(${NAME}-pkg-config ALL
144
COMMAND ${CMAKE_COMMAND}
145
-DCHANGES_FILE=${CMAKE_CURRENT_SOURCE_DIR}/CHANGES
146
-DTEMPLATE_FILE=${CMAKE_CURRENT_SOURCE_DIR}/cmake/${NAME}.pc.in
147
-DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/${NAME}.pc
148
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
149
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
150
-DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}
151
-DLIBS=${LIBS}
152
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/write_pkg_config.cmake
153
DEPENDS "CHANGES" "cmake/${NAME}.pc.in" "cmake/write_pkg_config.cmake")
154
155
if (SHADERC_ENABLE_INSTALL)
156
install(
157
FILES
158
${CMAKE_CURRENT_BINARY_DIR}/${NAME}.pc
159
DESTINATION
160
${CMAKE_INSTALL_LIBDIR}/pkgconfig)
161
endif()
162
endfunction()
163
164
define_pkg_config_file(shaderc -lshaderc_shared)
165
define_pkg_config_file(shaderc_static "-lshaderc ${EXTRA_STATIC_PKGCONFIG_LIBS} -lshaderc_util")
166
define_pkg_config_file(shaderc_combined -lshaderc_combined)
167
168