| 1 |
# Copyright 2016-2020 Google Inc. |
| 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 2.8) |
| 16 |
set(CMAKE_CXX_STANDARD 11) |
| 17 |
|
| 18 |
# Avoid a warning if parent project sets VERSION in project(). |
| 19 |
if (${CMAKE_VERSION} VERSION_GREATER "3.0.1") |
| 20 |
cmake_policy(SET CMP0048 NEW) |
| 21 |
endif() |
| 22 |
|
| 23 |
project(SPIRV-Cross LANGUAGES CXX C) |
| 24 |
enable_testing() |
| 25 |
|
| 26 |
include(GNUInstallDirs) |
| 27 |
|
| 28 |
option(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS "Instead of throwing exceptions assert" OFF) |
| 29 |
option(SPIRV_CROSS_SHARED "Build the C API as a single shared library." OFF) |
| 30 |
option(SPIRV_CROSS_STATIC "Build the C and C++ API as static libraries." ON) |
| 31 |
option(SPIRV_CROSS_CLI "Build the CLI binary. Requires SPIRV_CROSS_STATIC." ON) |
| 32 |
option(SPIRV_CROSS_ENABLE_TESTS "Enable SPIRV-Cross tests." ON) |
| 33 |
|
| 34 |
option(SPIRV_CROSS_ENABLE_GLSL "Enable GLSL support." ON) |
| 35 |
option(SPIRV_CROSS_ENABLE_HLSL "Enable HLSL target support." ON) |
| 36 |
option(SPIRV_CROSS_ENABLE_MSL "Enable MSL target support." ON) |
| 37 |
option(SPIRV_CROSS_ENABLE_CPP "Enable C++ target support." ON) |
| 38 |
option(SPIRV_CROSS_ENABLE_REFLECT "Enable JSON reflection target support." ON) |
| 39 |
option(SPIRV_CROSS_ENABLE_C_API "Enable C API wrapper support in static library." ON) |
| 40 |
option(SPIRV_CROSS_ENABLE_UTIL "Enable util module support." ON) |
| 41 |
|
| 42 |
option(SPIRV_CROSS_SANITIZE_ADDRESS "Sanitize address" OFF) |
| 43 |
option(SPIRV_CROSS_SANITIZE_MEMORY "Sanitize memory" OFF) |
| 44 |
option(SPIRV_CROSS_SANITIZE_THREADS "Sanitize threads" OFF) |
| 45 |
option(SPIRV_CROSS_SANITIZE_UNDEFINED "Sanitize undefined" OFF) |
| 46 |
|
| 47 |
option(SPIRV_CROSS_NAMESPACE_OVERRIDE "" "Override the namespace used in the C++ API.") |
| 48 |
option(SPIRV_CROSS_FORCE_STL_TYPES "Force use of STL types instead of STL replacements in certain places. Might reduce performance." OFF) |
| 49 |
|
| 50 |
option(SPIRV_CROSS_SKIP_INSTALL "Skips installation targets." OFF) |
| 51 |
|
| 52 |
option(SPIRV_CROSS_WERROR "Fail build on warnings." OFF) |
| 53 |
option(SPIRV_CROSS_MISC_WARNINGS "Misc warnings useful for Travis runs." OFF) |
| 54 |
|
| 55 |
option(SPIRV_CROSS_FORCE_PIC "Force position-independent code for all targets." OFF) |
| 56 |
|
| 57 |
if(${CMAKE_GENERATOR} MATCHES "Makefile") |
| 58 |
if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR}) |
| 59 |
message(FATAL_ERROR "Build out of tree to avoid overwriting Makefile") |
| 60 |
endif() |
| 61 |
endif() |
| 62 |
|
| 63 |
set(spirv-compiler-options "") |
| 64 |
set(spirv-compiler-defines "") |
| 65 |
set(spirv-cross-link-flags "") |
| 66 |
|
| 67 |
message(STATUS "SPIRV-Cross: Finding Git version for SPIRV-Cross.") |
| 68 |
set(spirv-cross-build-version "unknown") |
| 69 |
find_package(Git) |
| 70 |
if (GIT_FOUND) |
| 71 |
execute_process( |
| 72 |
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD |
| 73 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 74 |
OUTPUT_VARIABLE spirv-cross-build-version |
| 75 |
ERROR_QUIET |
| 76 |
OUTPUT_STRIP_TRAILING_WHITESPACE |
| 77 |
) |
| 78 |
message(STATUS "SPIRV-Cross: Git hash: ${spirv-cross-build-version}") |
| 79 |
else() |
| 80 |
message(STATUS "SPIRV-Cross: Git not found, using unknown build version.") |
| 81 |
endif() |
| 82 |
|
| 83 |
string(TIMESTAMP spirv-cross-timestamp) |
| 84 |
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/gitversion.in.h ${CMAKE_CURRENT_BINARY_DIR}/gitversion.h @ONLY) |
| 85 |
|
| 86 |
if (SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS) |
| 87 |
set(spirv-compiler-defines ${spirv-compiler-defines} SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS) |
| 88 |
if (NOT MSVC) |
| 89 |
set(spirv-compiler-options ${spirv-compiler-options} -fno-exceptions) |
| 90 |
endif() |
| 91 |
endif() |
| 92 |
|
| 93 |
if (SPIRV_CROSS_FORCE_STL_TYPES) |
| 94 |
set(spirv-compiler-defines ${spirv-compiler-defines} SPIRV_CROSS_FORCE_STL_TYPES) |
| 95 |
endif() |
| 96 |
|
| 97 |
if (WIN32) |
| 98 |
set(CMAKE_DEBUG_POSTFIX "d") |
| 99 |
endif() |
| 100 |
|
| 101 |
if (CMAKE_COMPILER_IS_GNUCXX OR ((${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") AND NOT MSVC)) |
| 102 |
set(spirv-compiler-options ${spirv-compiler-options} -Wall -Wextra -Wshadow -Wno-deprecated-declarations) |
| 103 |
if (SPIRV_CROSS_MISC_WARNINGS) |
| 104 |
if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") |
| 105 |
set(spirv-compiler-options ${spirv-compiler-options} -Wshorten-64-to-32) |
| 106 |
endif() |
| 107 |
endif() |
| 108 |
if (SPIRV_CROSS_WERROR) |
| 109 |
set(spirv-compiler-options ${spirv-compiler-options} -Werror) |
| 110 |
endif() |
| 111 |
|
| 112 |
if (SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS) |
| 113 |
set(spirv-compiler-options ${spirv-compiler-options} -fno-exceptions) |
| 114 |
endif() |
| 115 |
|
| 116 |
if (SPIRV_CROSS_SANITIZE_ADDRESS) |
| 117 |
set(spirv-compiler-options ${spirv-compiler-options} -fsanitize=address) |
| 118 |
set(spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=address") |
| 119 |
endif() |
| 120 |
|
| 121 |
if (SPIRV_CROSS_SANITIZE_UNDEFINED) |
| 122 |
set(spirv-compiler-options ${spirv-compiler-options} -fsanitize=undefined) |
| 123 |
set(spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=undefined") |
| 124 |
endif() |
| 125 |
|
| 126 |
if (SPIRV_CROSS_SANITIZE_MEMORY) |
| 127 |
set(spirv-compiler-options ${spirv-compiler-options} -fsanitize=memory) |
| 128 |
set(spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=memory") |
| 129 |
endif() |
| 130 |
|
| 131 |
if (SPIRV_CROSS_SANITIZE_THREADS) |
| 132 |
set(spirv-compiler-options ${spirv-compiler-options} -fsanitize=thread) |
| 133 |
set(spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=thread") |
| 134 |
endif() |
| 135 |
elseif (MSVC) |
| 136 |
set(spirv-compiler-options ${spirv-compiler-options} /wd4267 /wd4996) |
| 137 |
endif() |
| 138 |
|
| 139 |
macro(extract_headers out_abs file_list) |
| 140 |
set(${out_abs}) # absolute paths |
| 141 |
foreach(_a ${file_list}) |
| 142 |
# get_filename_component only returns the longest extension, so use a regex |
| 143 |
string(REGEX REPLACE ".*\\.(h|hpp)" "\\1" ext ${_a}) |
| 144 |
|
| 145 |
# For shared library, we are only interested in the C header. |
| 146 |
if (SPIRV_CROSS_STATIC) |
| 147 |
if(("${ext}" STREQUAL "h") OR ("${ext}" STREQUAL "hpp")) |
| 148 |
list(APPEND ${out_abs} "${_a}") |
| 149 |
endif() |
| 150 |
else() |
| 151 |
if("${ext}" STREQUAL "h") |
| 152 |
list(APPEND ${out_abs} "${_a}") |
| 153 |
endif() |
| 154 |
endif() |
| 155 |
endforeach() |
| 156 |
endmacro() |
| 157 |
|
| 158 |
macro(spirv_cross_add_library name config_name library_type) |
| 159 |
add_library(${name} ${library_type} ${ARGN}) |
| 160 |
extract_headers(hdrs "${ARGN}") |
| 161 |
target_include_directories(${name} PUBLIC |
| 162 |
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> |
| 163 |
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/spirv_cross>) |
| 164 |
set_target_properties(${name} PROPERTIES |
| 165 |
PUBLIC_HEADERS "${hdrs}") |
| 166 |
if (SPIRV_CROSS_FORCE_PIC) |
| 167 |
set_target_properties(${name} PROPERTIES POSITION_INDEPENDENT_CODE ON) |
| 168 |
endif() |
| 169 |
target_compile_options(${name} PRIVATE ${spirv-compiler-options}) |
| 170 |
target_compile_definitions(${name} PRIVATE ${spirv-compiler-defines}) |
| 171 |
if (SPIRV_CROSS_NAMESPACE_OVERRIDE) |
| 172 |
if (${library_type} MATCHES "STATIC") |
| 173 |
target_compile_definitions(${name} PUBLIC SPIRV_CROSS_NAMESPACE_OVERRIDE=${SPIRV_CROSS_NAMESPACE_OVERRIDE}) |
| 174 |
else() |
| 175 |
target_compile_definitions(${name} PRIVATE SPIRV_CROSS_NAMESPACE_OVERRIDE=${SPIRV_CROSS_NAMESPACE_OVERRIDE}) |
| 176 |
endif() |
| 177 |
endif() |
| 178 |
|
| 179 |
if (NOT SPIRV_CROSS_SKIP_INSTALL) |
| 180 |
install(TARGETS ${name} |
| 181 |
EXPORT ${config_name}Config |
| 182 |
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 183 |
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 184 |
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 185 |
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spirv_cross) |
| 186 |
install(FILES ${hdrs} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spirv_cross) |
| 187 |
install(EXPORT ${config_name}Config DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${config_name}/cmake) |
| 188 |
export(TARGETS ${name} FILE ${config_name}Config.cmake) |
| 189 |
endif() |
| 190 |
endmacro() |
| 191 |
|
| 192 |
set(spirv-cross-core-sources |
| 193 |
${CMAKE_CURRENT_SOURCE_DIR}/GLSL.std.450.h |
| 194 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_common.hpp |
| 195 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_containers.hpp |
| 196 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_error_handling.hpp |
| 197 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv.hpp |
| 198 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross.hpp |
| 199 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross.cpp |
| 200 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_parser.hpp |
| 201 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_parser.cpp |
| 202 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_parsed_ir.hpp |
| 203 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_parsed_ir.cpp |
| 204 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cfg.hpp |
| 205 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cfg.cpp) |
| 206 |
|
| 207 |
set(spirv-cross-c-sources |
| 208 |
spirv.h |
| 209 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_c.cpp |
| 210 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_c.h) |
| 211 |
|
| 212 |
set(spirv-cross-glsl-sources |
| 213 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_glsl.cpp |
| 214 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_glsl.hpp) |
| 215 |
|
| 216 |
set(spirv-cross-cpp-sources |
| 217 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cpp.cpp |
| 218 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cpp.hpp) |
| 219 |
|
| 220 |
set(spirv-cross-msl-sources |
| 221 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_msl.cpp |
| 222 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_msl.hpp) |
| 223 |
|
| 224 |
set(spirv-cross-hlsl-sources |
| 225 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_hlsl.cpp |
| 226 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_hlsl.hpp) |
| 227 |
|
| 228 |
set(spirv-cross-reflect-sources |
| 229 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.cpp |
| 230 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.hpp) |
| 231 |
|
| 232 |
set(spirv-cross-util-sources |
| 233 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_util.cpp |
| 234 |
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_util.hpp) |
| 235 |
|
| 236 |
if (SPIRV_CROSS_STATIC) |
| 237 |
spirv_cross_add_library(spirv-cross-core spirv_cross_core STATIC |
| 238 |
${spirv-cross-core-sources}) |
| 239 |
|
| 240 |
if (SPIRV_CROSS_ENABLE_GLSL) |
| 241 |
spirv_cross_add_library(spirv-cross-glsl spirv_cross_glsl STATIC |
| 242 |
${spirv-cross-glsl-sources}) |
| 243 |
target_link_libraries(spirv-cross-glsl PRIVATE spirv-cross-core) |
| 244 |
endif() |
| 245 |
|
| 246 |
if (SPIRV_CROSS_ENABLE_CPP) |
| 247 |
spirv_cross_add_library(spirv-cross-cpp spirv_cross_cpp STATIC |
| 248 |
${spirv-cross-cpp-sources}) |
| 249 |
|
| 250 |
if (SPIRV_CROSS_ENABLE_GLSL) |
| 251 |
target_link_libraries(spirv-cross-cpp PRIVATE spirv-cross-glsl) |
| 252 |
else() |
| 253 |
message(FATAL_ERROR "Must enable GLSL support to enable C++ support.") |
| 254 |
endif() |
| 255 |
endif() |
| 256 |
|
| 257 |
if (SPIRV_CROSS_ENABLE_REFLECT) |
| 258 |
if (SPIRV_CROSS_ENABLE_GLSL) |
| 259 |
spirv_cross_add_library(spirv-cross-reflect spirv_cross_reflect STATIC |
| 260 |
${spirv-cross-reflect-sources}) |
| 261 |
else() |
| 262 |
message(FATAL_ERROR "Must enable GLSL support to enable JSON reflection support.") |
| 263 |
endif() |
| 264 |
endif() |
| 265 |
|
| 266 |
if (SPIRV_CROSS_ENABLE_MSL) |
| 267 |
spirv_cross_add_library(spirv-cross-msl spirv_cross_msl STATIC |
| 268 |
${spirv-cross-msl-sources}) |
| 269 |
if (SPIRV_CROSS_ENABLE_GLSL) |
| 270 |
target_link_libraries(spirv-cross-msl PRIVATE spirv-cross-glsl) |
| 271 |
else() |
| 272 |
message(FATAL_ERROR "Must enable GLSL support to enable MSL support.") |
| 273 |
endif() |
| 274 |
endif() |
| 275 |
|
| 276 |
if (SPIRV_CROSS_ENABLE_HLSL) |
| 277 |
spirv_cross_add_library(spirv-cross-hlsl spirv_cross_hlsl STATIC |
| 278 |
${spirv-cross-hlsl-sources}) |
| 279 |
if (SPIRV_CROSS_ENABLE_GLSL) |
| 280 |
target_link_libraries(spirv-cross-hlsl PRIVATE spirv-cross-glsl) |
| 281 |
else() |
| 282 |
message(FATAL_ERROR "Must enable GLSL support to enable HLSL support.") |
| 283 |
endif() |
| 284 |
endif() |
| 285 |
|
| 286 |
if (SPIRV_CROSS_ENABLE_UTIL) |
| 287 |
spirv_cross_add_library(spirv-cross-util spirv_cross_util STATIC |
| 288 |
${spirv-cross-util-sources}) |
| 289 |
target_link_libraries(spirv-cross-util PRIVATE spirv-cross-core) |
| 290 |
endif() |
| 291 |
|
| 292 |
if (SPIRV_CROSS_ENABLE_C_API) |
| 293 |
spirv_cross_add_library(spirv-cross-c spirv_cross_c STATIC |
| 294 |
${spirv-cross-c-sources}) |
| 295 |
target_include_directories(spirv-cross-c PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
| 296 |
target_compile_definitions(spirv-cross-c PRIVATE HAVE_SPIRV_CROSS_GIT_VERSION) |
| 297 |
|
| 298 |
if (SPIRV_CROSS_ENABLE_GLSL) |
| 299 |
target_link_libraries(spirv-cross-c PRIVATE spirv-cross-glsl) |
| 300 |
target_compile_definitions(spirv-cross-c PRIVATE SPIRV_CROSS_C_API_GLSL=1) |
| 301 |
endif() |
| 302 |
|
| 303 |
if (SPIRV_CROSS_ENABLE_HLSL) |
| 304 |
target_link_libraries(spirv-cross-c PRIVATE spirv-cross-hlsl) |
| 305 |
target_compile_definitions(spirv-cross-c PRIVATE SPIRV_CROSS_C_API_HLSL=1) |
| 306 |
endif() |
| 307 |
|
| 308 |
if (SPIRV_CROSS_ENABLE_MSL) |
| 309 |
target_link_libraries(spirv-cross-c PRIVATE spirv-cross-msl) |
| 310 |
target_compile_definitions(spirv-cross-c PRIVATE SPIRV_CROSS_C_API_MSL=1) |
| 311 |
endif() |
| 312 |
|
| 313 |
if (SPIRV_CROSS_ENABLE_CPP) |
| 314 |
target_link_libraries(spirv-cross-c PRIVATE spirv-cross-cpp) |
| 315 |
target_compile_definitions(spirv-cross-c PRIVATE SPIRV_CROSS_C_API_CPP=1) |
| 316 |
endif() |
| 317 |
|
| 318 |
if (SPIRV_CROSS_ENABLE_REFLECT) |
| 319 |
target_link_libraries(spirv-cross-c PRIVATE spirv-cross-reflect) |
| 320 |
target_compile_definitions(spirv-cross-c PRIVATE SPIRV_CROSS_C_API_REFLECT=1) |
| 321 |
endif() |
| 322 |
endif() |
| 323 |
endif() |
| 324 |
|
| 325 |
set(spirv-cross-abi-major 0) |
| 326 |
set(spirv-cross-abi-minor 42) |
| 327 |
set(spirv-cross-abi-patch 0) |
| 328 |
|
| 329 |
if (SPIRV_CROSS_SHARED) |
| 330 |
set(SPIRV_CROSS_VERSION ${spirv-cross-abi-major}.${spirv-cross-abi-minor}.${spirv-cross-abi-patch}) |
| 331 |
|
| 332 |
if (NOT SPIRV_CROSS_SKIP_INSTALL) |
| 333 |
configure_file( |
| 334 |
${CMAKE_CURRENT_SOURCE_DIR}/pkg-config/spirv-cross-c-shared.pc.in |
| 335 |
${CMAKE_CURRENT_BINARY_DIR}/spirv-cross-c-shared.pc @ONLY) |
| 336 |
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/spirv-cross-c-shared.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) |
| 337 |
endif() |
| 338 |
|
| 339 |
spirv_cross_add_library(spirv-cross-c-shared spirv_cross_c_shared SHARED |
| 340 |
${spirv-cross-core-sources} |
| 341 |
${spirv-cross-c-sources}) |
| 342 |
|
| 343 |
target_include_directories(spirv-cross-c-shared PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
| 344 |
target_compile_definitions(spirv-cross-c-shared PRIVATE HAVE_SPIRV_CROSS_GIT_VERSION) |
| 345 |
|
| 346 |
if (SPIRV_CROSS_ENABLE_GLSL) |
| 347 |
target_sources(spirv-cross-c-shared PRIVATE ${spirv-cross-glsl-sources}) |
| 348 |
target_compile_definitions(spirv-cross-c-shared PRIVATE SPIRV_CROSS_C_API_GLSL=1) |
| 349 |
endif() |
| 350 |
|
| 351 |
if (SPIRV_CROSS_ENABLE_HLSL) |
| 352 |
if (SPIRV_CROSS_ENABLE_GLSL) |
| 353 |
target_sources(spirv-cross-c-shared PRIVATE ${spirv-cross-hlsl-sources}) |
| 354 |
else() |
| 355 |
message(FATAL_ERROR "Must enable GLSL support to enable HLSL support.") |
| 356 |
endif() |
| 357 |
target_compile_definitions(spirv-cross-c-shared PRIVATE SPIRV_CROSS_C_API_HLSL=1) |
| 358 |
endif() |
| 359 |
|
| 360 |
if (SPIRV_CROSS_ENABLE_MSL) |
| 361 |
if (SPIRV_CROSS_ENABLE_GLSL) |
| 362 |
target_sources(spirv-cross-c-shared PRIVATE ${spirv-cross-msl-sources}) |
| 363 |
else() |
| 364 |
message(FATAL_ERROR "Must enable GLSL support to enable MSL support.") |
| 365 |
endif() |
| 366 |
target_compile_definitions(spirv-cross-c-shared PRIVATE SPIRV_CROSS_C_API_MSL=1) |
| 367 |
endif() |
| 368 |
|
| 369 |
if (SPIRV_CROSS_ENABLE_CPP) |
| 370 |
if (SPIRV_CROSS_ENABLE_GLSL) |
| 371 |
target_sources(spirv-cross-c-shared PRIVATE ${spirv-cross-cpp-sources}) |
| 372 |
else() |
| 373 |
message(FATAL_ERROR "Must enable GLSL support to enable C++ support.") |
| 374 |
endif() |
| 375 |
target_compile_definitions(spirv-cross-c-shared PRIVATE SPIRV_CROSS_C_API_CPP=1) |
| 376 |
endif() |
| 377 |
|
| 378 |
if (SPIRV_CROSS_ENABLE_REFLECT) |
| 379 |
if (SPIRV_CROSS_ENABLE_GLSL) |
| 380 |
target_sources(spirv-cross-c-shared PRIVATE ${spirv-cross-reflect-sources}) |
| 381 |
else() |
| 382 |
message(FATAL_ERROR "Must enable GLSL support to enable JSON reflection support.") |
| 383 |
endif() |
| 384 |
target_compile_definitions(spirv-cross-c-shared PRIVATE SPIRV_CROSS_C_API_REFLECT=1) |
| 385 |
endif() |
| 386 |
|
| 387 |
if (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")) |
| 388 |
# Only export the C API. |
| 389 |
target_compile_options(spirv-cross-c-shared PRIVATE -fvisibility=hidden) |
| 390 |
if (NOT APPLE) |
| 391 |
set_target_properties(spirv-cross-c-shared PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}") |
| 392 |
endif() |
| 393 |
endif() |
| 394 |
|
| 395 |
target_compile_definitions(spirv-cross-c-shared PRIVATE SPVC_EXPORT_SYMBOLS) |
| 396 |
|
| 397 |
set_target_properties(spirv-cross-c-shared PROPERTIES |
| 398 |
VERSION ${SPIRV_CROSS_VERSION} |
| 399 |
SOVERSION ${spirv-cross-abi-major}) |
| 400 |
endif() |
| 401 |
|
| 402 |
if (SPIRV_CROSS_CLI) |
| 403 |
if (NOT SPIRV_CROSS_ENABLE_GLSL) |
| 404 |
message(FATAL_ERROR "Must enable GLSL if building CLI.") |
| 405 |
endif() |
| 406 |
|
| 407 |
if (NOT SPIRV_CROSS_ENABLE_HLSL) |
| 408 |
message(FATAL_ERROR "Must enable HLSL if building CLI.") |
| 409 |
endif() |
| 410 |
|
| 411 |
if (NOT SPIRV_CROSS_ENABLE_MSL) |
| 412 |
message(FATAL_ERROR "Must enable MSL if building CLI.") |
| 413 |
endif() |
| 414 |
|
| 415 |
if (NOT SPIRV_CROSS_ENABLE_CPP) |
| 416 |
message(FATAL_ERROR "Must enable C++ if building CLI.") |
| 417 |
endif() |
| 418 |
|
| 419 |
if (NOT SPIRV_CROSS_ENABLE_REFLECT) |
| 420 |
message(FATAL_ERROR "Must enable reflection if building CLI.") |
| 421 |
endif() |
| 422 |
|
| 423 |
if (NOT SPIRV_CROSS_ENABLE_UTIL) |
| 424 |
message(FATAL_ERROR "Must enable utils if building CLI.") |
| 425 |
endif() |
| 426 |
|
| 427 |
if (NOT SPIRV_CROSS_STATIC) |
| 428 |
message(FATAL_ERROR "Must build static libraries if building CLI.") |
| 429 |
endif() |
| 430 |
add_executable(spirv-cross main.cpp) |
| 431 |
target_compile_options(spirv-cross PRIVATE ${spirv-compiler-options}) |
| 432 |
target_include_directories(spirv-cross PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
| 433 |
target_compile_definitions(spirv-cross PRIVATE ${spirv-compiler-defines} HAVE_SPIRV_CROSS_GIT_VERSION) |
| 434 |
set_target_properties(spirv-cross PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}") |
| 435 |
if (NOT SPIRV_CROSS_SKIP_INSTALL) |
| 436 |
install(TARGETS spirv-cross RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 437 |
endif() |
| 438 |
target_link_libraries(spirv-cross PRIVATE |
| 439 |
spirv-cross-glsl |
| 440 |
spirv-cross-hlsl |
| 441 |
spirv-cross-cpp |
| 442 |
spirv-cross-reflect |
| 443 |
spirv-cross-msl |
| 444 |
spirv-cross-util |
| 445 |
spirv-cross-core) |
| 446 |
|
| 447 |
if (SPIRV_CROSS_ENABLE_TESTS) |
| 448 |
# Set up tests, using only the simplest modes of the test_shaders |
| 449 |
# script. You have to invoke the script manually to: |
| 450 |
# - Update the reference files |
| 451 |
# - Get cycle counts from malisc |
| 452 |
# - Keep failing outputs |
| 453 |
find_package(PythonInterp) |
| 454 |
find_program(spirv-cross-glslang NAMES glslangValidator |
| 455 |
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/glslang-build/output/bin |
| 456 |
NO_DEFAULT_PATH) |
| 457 |
find_program(spirv-cross-spirv-as NAMES spirv-as |
| 458 |
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/spirv-tools-build/output/bin |
| 459 |
NO_DEFAULT_PATH) |
| 460 |
find_program(spirv-cross-spirv-val NAMES spirv-val |
| 461 |
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/spirv-tools-build/output/bin |
| 462 |
NO_DEFAULT_PATH) |
| 463 |
find_program(spirv-cross-spirv-opt NAMES spirv-opt |
| 464 |
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/spirv-tools-build/output/bin |
| 465 |
NO_DEFAULT_PATH) |
| 466 |
|
| 467 |
if ((${spirv-cross-glslang} MATCHES "NOTFOUND") OR (${spirv-cross-spirv-as} MATCHES "NOTFOUND") OR (${spirv-cross-spirv-val} MATCHES "NOTFOUND") OR (${spirv-cross-spirv-opt} MATCHES "NOTFOUND")) |
| 468 |
set(SPIRV_CROSS_ENABLE_TESTS OFF) |
| 469 |
message("SPIRV-Cross: Testing will be disabled for SPIRV-Cross. Could not find glslang or SPIRV-Tools build under external/. To enable testing, run ./checkout_glslang_spirv_tools.sh and ./build_glslang_spirv_tools.sh first.") |
| 470 |
else() |
| 471 |
set(SPIRV_CROSS_ENABLE_TESTS ON) |
| 472 |
message("SPIRV-Cross: Found glslang and SPIRV-Tools. Enabling test suite.") |
| 473 |
message("SPIRV-Cross: Found glslangValidator in: ${spirv-cross-glslang}.") |
| 474 |
message("SPIRV-Cross: Found spirv-as in: ${spirv-cross-spirv-as}.") |
| 475 |
message("SPIRV-Cross: Found spirv-val in: ${spirv-cross-spirv-val}.") |
| 476 |
message("SPIRV-Cross: Found spirv-opt in: ${spirv-cross-spirv-opt}.") |
| 477 |
endif() |
| 478 |
|
| 479 |
set(spirv-cross-externals |
| 480 |
--glslang "${spirv-cross-glslang}" |
| 481 |
--spirv-as "${spirv-cross-spirv-as}" |
| 482 |
--spirv-opt "${spirv-cross-spirv-opt}" |
| 483 |
--spirv-val "${spirv-cross-spirv-val}") |
| 484 |
|
| 485 |
if (${PYTHONINTERP_FOUND} AND SPIRV_CROSS_ENABLE_TESTS) |
| 486 |
if (${PYTHON_VERSION_MAJOR} GREATER 2) |
| 487 |
add_executable(spirv-cross-c-api-test tests-other/c_api_test.c) |
| 488 |
target_link_libraries(spirv-cross-c-api-test spirv-cross-c) |
| 489 |
set_target_properties(spirv-cross-c-api-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}") |
| 490 |
|
| 491 |
add_executable(spirv-cross-small-vector-test tests-other/small_vector.cpp) |
| 492 |
target_link_libraries(spirv-cross-small-vector-test spirv-cross-core) |
| 493 |
set_target_properties(spirv-cross-small-vector-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}") |
| 494 |
|
| 495 |
add_executable(spirv-cross-msl-constexpr-test tests-other/msl_constexpr_test.cpp) |
| 496 |
target_link_libraries(spirv-cross-msl-constexpr-test spirv-cross-c) |
| 497 |
set_target_properties(spirv-cross-msl-constexpr-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}") |
| 498 |
|
| 499 |
add_executable(spirv-cross-msl-resource-binding-test tests-other/msl_resource_bindings.cpp) |
| 500 |
target_link_libraries(spirv-cross-msl-resource-binding-test spirv-cross-c) |
| 501 |
set_target_properties(spirv-cross-msl-resource-binding-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}") |
| 502 |
|
| 503 |
add_executable(spirv-cross-hlsl-resource-binding-test tests-other/hlsl_resource_bindings.cpp) |
| 504 |
target_link_libraries(spirv-cross-hlsl-resource-binding-test spirv-cross-c) |
| 505 |
set_target_properties(spirv-cross-hlsl-resource-binding-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}") |
| 506 |
|
| 507 |
add_executable(spirv-cross-msl-ycbcr-conversion-test tests-other/msl_ycbcr_conversion_test.cpp) |
| 508 |
target_link_libraries(spirv-cross-msl-ycbcr-conversion-test spirv-cross-c) |
| 509 |
set_target_properties(spirv-cross-msl-ycbcr-conversion-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}") |
| 510 |
|
| 511 |
add_executable(spirv-cross-typed-id-test tests-other/typed_id_test.cpp) |
| 512 |
target_link_libraries(spirv-cross-typed-id-test spirv-cross-core) |
| 513 |
set_target_properties(spirv-cross-typed-id-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}") |
| 514 |
|
| 515 |
if (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")) |
| 516 |
target_compile_options(spirv-cross-c-api-test PRIVATE -std=c89 -Wall -Wextra) |
| 517 |
endif() |
| 518 |
add_test(NAME spirv-cross-c-api-test |
| 519 |
COMMAND $<TARGET_FILE:spirv-cross-c-api-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/c_api_test.spv |
| 520 |
${spirv-cross-abi-major} |
| 521 |
${spirv-cross-abi-minor} |
| 522 |
${spirv-cross-abi-patch}) |
| 523 |
add_test(NAME spirv-cross-small-vector-test |
| 524 |
COMMAND $<TARGET_FILE:spirv-cross-small-vector-test>) |
| 525 |
add_test(NAME spirv-cross-msl-constexpr-test |
| 526 |
COMMAND $<TARGET_FILE:spirv-cross-msl-constexpr-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/msl_constexpr_test.spv) |
| 527 |
add_test(NAME spirv-cross-msl-resource-binding-test |
| 528 |
COMMAND $<TARGET_FILE:spirv-cross-msl-resource-binding-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/msl_resource_binding.spv) |
| 529 |
add_test(NAME spirv-cross-hlsl-resource-binding-test |
| 530 |
COMMAND $<TARGET_FILE:spirv-cross-hlsl-resource-binding-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/hlsl_resource_binding.spv) |
| 531 |
add_test(NAME spirv-cross-msl-ycbcr-conversion-test |
| 532 |
COMMAND $<TARGET_FILE:spirv-cross-msl-ycbcr-conversion-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/msl_ycbcr_conversion_test.spv) |
| 533 |
add_test(NAME spirv-cross-msl-ycbcr-conversion-test-2 |
| 534 |
COMMAND $<TARGET_FILE:spirv-cross-msl-ycbcr-conversion-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/msl_ycbcr_conversion_test_2.spv) |
| 535 |
add_test(NAME spirv-cross-typed-id-test |
| 536 |
COMMAND $<TARGET_FILE:spirv-cross-typed-id-test>) |
| 537 |
add_test(NAME spirv-cross-test |
| 538 |
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --parallel |
| 539 |
${spirv-cross-externals} |
| 540 |
${CMAKE_CURRENT_SOURCE_DIR}/shaders |
| 541 |
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>) |
| 542 |
add_test(NAME spirv-cross-test-no-opt |
| 543 |
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --parallel |
| 544 |
${spirv-cross-externals} |
| 545 |
${CMAKE_CURRENT_SOURCE_DIR}/shaders-no-opt |
| 546 |
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>) |
| 547 |
add_test(NAME spirv-cross-test-metal |
| 548 |
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --metal --parallel |
| 549 |
${spirv-cross-externals} |
| 550 |
${CMAKE_CURRENT_SOURCE_DIR}/shaders-msl |
| 551 |
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>) |
| 552 |
add_test(NAME spirv-cross-test-metal-no-opt |
| 553 |
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --metal --parallel |
| 554 |
${spirv-cross-externals} |
| 555 |
${CMAKE_CURRENT_SOURCE_DIR}/shaders-msl-no-opt |
| 556 |
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>) |
| 557 |
add_test(NAME spirv-cross-test-hlsl |
| 558 |
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --hlsl --parallel |
| 559 |
${spirv-cross-externals} |
| 560 |
${CMAKE_CURRENT_SOURCE_DIR}/shaders-hlsl |
| 561 |
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>) |
| 562 |
add_test(NAME spirv-cross-test-hlsl-no-opt |
| 563 |
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --hlsl --parallel |
| 564 |
${spirv-cross-externals} |
| 565 |
${CMAKE_CURRENT_SOURCE_DIR}/shaders-hlsl-no-opt |
| 566 |
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>) |
| 567 |
add_test(NAME spirv-cross-test-opt |
| 568 |
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --opt --parallel |
| 569 |
${spirv-cross-externals} |
| 570 |
${CMAKE_CURRENT_SOURCE_DIR}/shaders |
| 571 |
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>) |
| 572 |
add_test(NAME spirv-cross-test-metal-opt |
| 573 |
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --metal --opt --parallel |
| 574 |
${spirv-cross-externals} |
| 575 |
${CMAKE_CURRENT_SOURCE_DIR}/shaders-msl |
| 576 |
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>) |
| 577 |
add_test(NAME spirv-cross-test-hlsl-opt |
| 578 |
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --hlsl --opt --parallel |
| 579 |
${spirv-cross-externals} |
| 580 |
${CMAKE_CURRENT_SOURCE_DIR}/shaders-hlsl |
| 581 |
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>) |
| 582 |
add_test(NAME spirv-cross-test-reflection |
| 583 |
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --reflect --parallel |
| 584 |
${spirv-cross-externals} |
| 585 |
${CMAKE_CURRENT_SOURCE_DIR}/shaders-reflection |
| 586 |
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>) |
| 587 |
add_test(NAME spirv-cross-test-ue4 |
| 588 |
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --msl --parallel |
| 589 |
${spirv-cross-externals} |
| 590 |
${CMAKE_CURRENT_SOURCE_DIR}/shaders-ue4 |
| 591 |
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>) |
| 592 |
add_test(NAME spirv-cross-test-ue4-opt |
| 593 |
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --msl --opt --parallel |
| 594 |
${spirv-cross-externals} |
| 595 |
${CMAKE_CURRENT_SOURCE_DIR}/shaders-ue4 |
| 596 |
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>) |
| 597 |
add_test(NAME spirv-cross-test-ue4-no-opt |
| 598 |
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --msl --parallel |
| 599 |
${spirv-cross-externals} |
| 600 |
${CMAKE_CURRENT_SOURCE_DIR}/shaders-ue4-no-opt |
| 601 |
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>) |
| 602 |
endif() |
| 603 |
elseif(NOT ${PYTHONINTERP_FOUND}) |
| 604 |
message(WARNING "SPIRV-Cross: Testing disabled. Could not find python3. If you have python3 installed try running " |
| 605 |
"cmake with -DPYTHON_EXECUTABLE:FILEPATH=/path/to/python3 to help it find the executable") |
| 606 |
endif() |
| 607 |
endif() |
| 608 |
endif() |