| 1 |
# Copyright 2018 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 3.19) |
| 16 |
project(SPIRV-Cross) |
| 17 |
|
| 18 |
# Use assertions instead of exceptions so we can succesfully compile with -fno-exceptions. |
| 19 |
option(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS "Instead of throwing exceptions assert" ON) |
| 20 |
|
| 21 |
if(${CMAKE_GENERATOR} MATCHES "Makefile") |
| 22 |
if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR}) |
| 23 |
message(FATAL_ERROR "Build out of tree to avoid overwriting Makefile") |
| 24 |
endif() |
| 25 |
endif() |
| 26 |
|
| 27 |
set(spirv-compiler-options "") |
| 28 |
set(spirv-compiler-defines "") |
| 29 |
set(spirv-compiler-public-defines "") |
| 30 |
|
| 31 |
if(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS) |
| 32 |
# This needs to be public, because exceptions are exposed in public headers. |
| 33 |
set(spirv-compiler-public-defines ${spirv-compiler-public-defines} SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS) |
| 34 |
endif() |
| 35 |
|
| 36 |
# To specify special debug or optimization options, use |
| 37 |
# -DCMAKE_CXX_COMPILE_FLAGS |
| 38 |
# However, we require the C++11 dialect. |
| 39 |
if (NOT "${MSVC}") |
| 40 |
set(spirv-compiler-options ${spirv-compiler-options} -std=c++11 -Wall -Wextra -Werror -Wshadow) |
| 41 |
set(spirv-compiler-defines ${spirv-compiler-defines} __STDC_LIMIT_MACROS) |
| 42 |
|
| 43 |
if(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS) |
| 44 |
set(spirv-compiler-options ${spirv-compiler-options} -fno-exceptions) |
| 45 |
endif() |
| 46 |
endif() |
| 47 |
|
| 48 |
macro(extract_headers out_abs file_list) |
| 49 |
set(${out_abs}) # absolute paths |
| 50 |
foreach(_a ${file_list}) |
| 51 |
# get_filename_component only returns the longest extension, so use a regex |
| 52 |
string(REGEX REPLACE ".*\\.(h|hpp)" "\\1" ext ${_a}) |
| 53 |
if(("${ext}" STREQUAL "h") OR ("${ext}" STREQUAL "hpp")) |
| 54 |
list(APPEND ${out_abs} "${_a}") |
| 55 |
endif() |
| 56 |
endforeach() |
| 57 |
endmacro() |
| 58 |
|
| 59 |
macro(spirv_cross_add_library name config_name) |
| 60 |
add_library(${name} ${ARGN}) |
| 61 |
extract_headers(hdrs "${ARGN}") |
| 62 |
target_include_directories(${name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..) |
| 63 |
set_target_properties(${name} PROPERTIES |
| 64 |
PUBLIC_HEADERS "${hdrs}") |
| 65 |
target_compile_options(${name} PRIVATE ${spirv-compiler-options}) |
| 66 |
target_compile_definitions(${name} PRIVATE ${spirv-compiler-defines}) |
| 67 |
target_compile_definitions(${name} PUBLIC ${spirv-compiler-public-defines}) |
| 68 |
target_compile_options(${name} PRIVATE $<$<PLATFORM_ID:Linux>:-fPIC>) |
| 69 |
endmacro() |
| 70 |
|
| 71 |
spirv_cross_add_library(spirv-cross-core spirv_cross_core STATIC |
| 72 |
../GLSL.std.450.h |
| 73 |
../spirv_common.hpp |
| 74 |
../spirv_cross_containers.hpp |
| 75 |
../spirv_cross_error_handling.hpp |
| 76 |
../spirv.hpp |
| 77 |
../spirv_cross.hpp |
| 78 |
../spirv_cross.cpp |
| 79 |
../spirv_parser.hpp |
| 80 |
../spirv_parser.cpp |
| 81 |
../spirv_cross_parsed_ir.hpp |
| 82 |
../spirv_cross_parsed_ir.cpp |
| 83 |
../spirv_cfg.hpp |
| 84 |
../spirv_cfg.cpp) |
| 85 |
|
| 86 |
spirv_cross_add_library(spirv-cross-glsl spirv_cross_glsl STATIC |
| 87 |
../spirv_glsl.cpp |
| 88 |
../spirv_glsl.hpp) |
| 89 |
|
| 90 |
spirv_cross_add_library(spirv-cross-msl spirv_cross_msl STATIC |
| 91 |
../spirv_msl.cpp |
| 92 |
../spirv_msl.hpp) |
| 93 |
|
| 94 |
target_link_libraries(spirv-cross-glsl spirv-cross-msl spirv-cross-core) |