2016-03-19 21:13:06 +00:00
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required ( VERSION 2.8 )
2019-02-12 10:11:29 +00:00
set ( CMAKE_CXX_STANDARD 11 )
2019-03-04 10:13:41 +00:00
project ( SPIRV-Cross LANGUAGES CXX C )
2016-03-19 21:13:06 +00:00
enable_testing ( )
2016-12-15 19:46:10 +00:00
option ( SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS "Instead of throwing exceptions assert" OFF )
2019-02-12 10:11:29 +00:00
option ( SPIRV_CROSS_SHARED "Build the C API as a single shared library." OFF )
option ( SPIRV_CROSS_STATIC "Build the C and C++ API as static libraries." ON )
option ( SPIRV_CROSS_CLI "Build the CLI binary. Requires SPIRV_CROSS_STATIC." ON )
2019-03-07 09:22:58 +00:00
option ( SPIRV_CROSS_ENABLE_TESTS "Enable SPIRV-Cross tests." ON )
2016-12-12 21:33:22 +00:00
2019-03-27 12:21:11 +00:00
option ( SPIRV_CROSS_ENABLE_GLSL "Enable GLSL support." ON )
option ( SPIRV_CROSS_ENABLE_HLSL "Enable HLSL target support." ON )
option ( SPIRV_CROSS_ENABLE_MSL "Enable MSL target support." ON )
option ( SPIRV_CROSS_ENABLE_CPP "Enable C++ target support." ON )
option ( SPIRV_CROSS_ENABLE_REFLECT "Enable JSON reflection target support." ON )
option ( SPIRV_CROSS_ENABLE_C_API "Enable C API wrapper support in static library." ON )
option ( SPIRV_CROSS_ENABLE_UTIL "Enable util module support." ON )
2019-03-05 09:11:04 +00:00
option ( SPIRV_CROSS_SANITIZE_ADDRESS "Sanitize address" OFF )
2019-03-05 10:15:08 +00:00
option ( SPIRV_CROSS_SANITIZE_MEMORY "Sanitize memory" OFF )
2019-03-05 09:11:04 +00:00
option ( SPIRV_CROSS_SANITIZE_THREADS "Sanitize threads" OFF )
2019-03-05 10:15:08 +00:00
option ( SPIRV_CROSS_SANITIZE_UNDEFINED "Sanitize undefined" OFF )
2019-03-05 09:11:04 +00:00
2019-03-29 09:29:44 +00:00
option ( SPIRV_CROSS_NAMESPACE_OVERRIDE "" "Override the namespace used in the C++ API." )
2019-04-09 11:07:30 +00:00
option ( SPIRV_CROSS_FORCE_STL_TYPES "Force use of STL types instead of STL replacements in certain places. Might reduce performance." OFF )
2019-03-29 09:29:44 +00:00
2016-03-19 21:13:06 +00:00
if ( ${ CMAKE_GENERATOR } MATCHES "Makefile" )
2019-02-12 10:11:29 +00:00
if ( ${ CMAKE_CURRENT_SOURCE_DIR } STREQUAL ${ CMAKE_CURRENT_BINARY_DIR } )
message ( FATAL_ERROR "Build out of tree to avoid overwriting Makefile" )
endif ( )
2016-03-19 21:13:06 +00:00
endif ( )
2016-12-15 19:46:10 +00:00
set ( spirv-compiler-options "" )
set ( spirv-compiler-defines "" )
2019-03-05 09:11:04 +00:00
set ( spirv-cross-link-flags "" )
2016-12-15 19:46:10 +00:00
2019-05-24 13:23:29 +00:00
message ( STATUS "Finding Git version for SPIRV-Cross." )
set ( spirv-cross-build-version "unknown" )
find_package ( Git )
if ( GIT_FOUND )
execute_process (
C O M M A N D $ { G I T _ E X E C U T A B L E } r e v - p a r s e - - s h o r t H E A D
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
O U T P U T _ V A R I A B L E s p i r v - c r o s s - b u i l d - v e r s i o n
E R R O R _ Q U I E T
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
)
message ( STATUS "Git hash: ${spirv-cross-build-version}" )
else ( )
message ( STATUS "Git not found, using unknown build version." )
endif ( )
string ( TIMESTAMP spirv-cross-timestamp )
configure_file ( ${ CMAKE_CURRENT_SOURCE_DIR } /cmake/gitversion.in.h ${ CMAKE_CURRENT_BINARY_DIR } /gitversion.h @ONLY )
2016-12-15 19:46:10 +00:00
if ( SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS )
2019-02-12 10:11:29 +00:00
set ( spirv-compiler-defines ${ spirv-compiler-defines } SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS )
2016-12-15 19:46:10 +00:00
endif ( )
2019-04-09 11:07:30 +00:00
if ( SPIRV_CROSS_FORCE_STL_TYPES )
set ( spirv-compiler-defines ${ spirv-compiler-defines } SPIRV_CROSS_FORCE_STL_TYPES )
endif ( )
2019-02-12 10:11:29 +00:00
if ( CMAKE_COMPILER_IS_GNUCXX OR ( ${ CMAKE_CXX_COMPILER_ID } MATCHES "Clang" ) )
set ( spirv-compiler-options ${ spirv-compiler-options } -Wall -Wextra -Werror -Wshadow )
2016-12-12 21:33:22 +00:00
2019-03-05 09:11:04 +00:00
if ( SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS )
2019-02-12 10:11:29 +00:00
set ( spirv-compiler-options ${ spirv-compiler-options } -fno-exceptions )
endif ( )
2019-03-05 09:11:04 +00:00
if ( SPIRV_CROSS_SANITIZE_ADDRESS )
set ( spirv-compiler-options ${ spirv-compiler-options } -fsanitize=address )
set ( spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=address" )
endif ( )
2019-03-05 10:15:08 +00:00
if ( SPIRV_CROSS_SANITIZE_UNDEFINED )
set ( spirv-compiler-options ${ spirv-compiler-options } -fsanitize=undefined )
set ( spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=undefined" )
endif ( )
if ( SPIRV_CROSS_SANITIZE_MEMORY )
set ( spirv-compiler-options ${ spirv-compiler-options } -fsanitize=memory )
set ( spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=memory" )
endif ( )
2019-03-05 09:11:04 +00:00
if ( SPIRV_CROSS_SANITIZE_THREADS )
set ( spirv-compiler-options ${ spirv-compiler-options } -fsanitize=thread )
set ( spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=thread" )
endif ( )
2019-02-12 10:11:29 +00:00
elseif ( MSVC )
set ( spirv-compiler-options ${ spirv-compiler-options } /wd4267 )
2016-12-12 21:33:22 +00:00
endif ( )
2016-03-19 21:13:06 +00:00
2017-01-24 00:49:16 +00:00
macro ( extract_headers out_abs file_list )
2019-02-12 10:11:29 +00:00
set ( ${ out_abs } ) # absolute paths
foreach ( _a ${ file_list } )
# get_filename_component only returns the longest extension, so use a regex
string ( REGEX REPLACE ".*\\.(h|hpp)" "\\1" ext ${ _a } )
# For shared library, we are only interested in the C header.
if ( SPIRV_CROSS_STATIC )
if ( ( "${ext}" STREQUAL "h" ) OR ( "${ext}" STREQUAL "hpp" ) )
list ( APPEND ${ out_abs } "${_a}" )
endif ( )
else ( )
if ( "${ext}" STREQUAL "h" )
list ( APPEND ${ out_abs } "${_a}" )
endif ( )
endif ( )
endforeach ( )
2017-01-24 00:49:16 +00:00
endmacro ( )
2019-03-29 09:29:44 +00:00
macro ( spirv_cross_add_library name config_name library_type )
add_library ( ${ name } ${ library_type } ${ ARGN } )
2019-02-12 10:11:29 +00:00
extract_headers ( hdrs "${ARGN}" )
target_include_directories ( ${ name } PUBLIC
2019-03-27 12:21:11 +00:00
$ < B U I L D _ I N T E R F A C E : $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } >
$ < I N S T A L L _ I N T E R F A C E : i n c l u d e / s p i r v _ c r o s s > )
2019-02-12 10:11:29 +00:00
set_target_properties ( ${ name } PROPERTIES
2019-03-27 12:21:11 +00:00
P U B L I C _ H E A D E R S " $ { h d r s } " )
2019-02-12 10:11:29 +00:00
target_compile_options ( ${ name } PRIVATE ${ spirv-compiler-options } )
target_compile_definitions ( ${ name } PRIVATE ${ spirv-compiler-defines } )
2019-03-29 09:29:44 +00:00
if ( SPIRV_CROSS_NAMESPACE_OVERRIDE )
if ( ${ library_type } MATCHES "STATIC" )
target_compile_definitions ( ${ name } PUBLIC SPIRV_CROSS_NAMESPACE_OVERRIDE= ${ SPIRV_CROSS_NAMESPACE_OVERRIDE } )
else ( )
target_compile_definitions ( ${ name } PRIVATE SPIRV_CROSS_NAMESPACE_OVERRIDE= ${ SPIRV_CROSS_NAMESPACE_OVERRIDE } )
endif ( )
endif ( )
2019-02-12 10:11:29 +00:00
install ( TARGETS ${ name }
2019-03-27 12:21:11 +00:00
E X P O R T $ { c o n f i g _ n a m e } C o n f i g
R U N T I M E D E S T I N A T I O N b i n
L I B R A R Y D E S T I N A T I O N l i b
A R C H I V E D E S T I N A T I O N l i b
P U B L I C _ H E A D E R D E S T I N A T I O N i n c l u d e / s p i r v _ c r o s s )
2019-02-12 10:11:29 +00:00
install ( FILES ${ hdrs } DESTINATION include/spirv_cross )
install ( EXPORT ${ config_name } Config DESTINATION share/ ${ config_name } /cmake )
export ( TARGETS ${ name } FILE ${ config_name } Config.cmake )
2017-01-24 00:49:16 +00:00
endmacro ( )
2019-02-12 10:11:29 +00:00
set ( spirv-cross-core-sources
2019-03-27 12:21:11 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / G L S L . s t d . 4 5 0 . h
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ c o m m o n . h p p
2019-04-09 11:07:30 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ c r o s s _ c o n t a i n e r s . h p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ c r o s s _ e r r o r _ h a n d l i n g . h p p
2019-03-27 12:21:11 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v . h p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ c r o s s . h p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ c r o s s . c p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ p a r s e r . h p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ p a r s e r . c p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ c r o s s _ p a r s e d _ i r . h p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ c r o s s _ p a r s e d _ i r . c p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ c f g . h p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ c f g . c p p )
2019-02-12 10:11:29 +00:00
set ( spirv-cross-c-sources
2019-03-27 12:21:11 +00:00
s p i r v . h
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ c r o s s _ c . c p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ c r o s s _ c . h )
2019-02-12 10:11:29 +00:00
set ( spirv-cross-glsl-sources
2019-03-27 12:21:11 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ g l s l . c p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ g l s l . h p p )
2019-02-12 10:11:29 +00:00
set ( spirv-cross-cpp-sources
2019-03-27 12:21:11 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ c p p . c p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ c p p . h p p )
2019-02-12 10:11:29 +00:00
set ( spirv-cross-msl-sources
2019-03-27 12:21:11 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ m s l . c p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ m s l . h p p )
2019-02-12 10:11:29 +00:00
set ( spirv-cross-hlsl-sources
2019-03-27 12:21:11 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ h l s l . c p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ h l s l . h p p )
2019-02-12 10:11:29 +00:00
set ( spirv-cross-reflect-sources
2019-03-27 12:21:11 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ r e f l e c t . c p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ r e f l e c t . h p p )
2019-02-12 10:11:29 +00:00
set ( spirv-cross-util-sources
2019-03-27 12:21:11 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ c r o s s _ u t i l . c p p
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s p i r v _ c r o s s _ u t i l . h p p )
2019-02-12 10:11:29 +00:00
if ( SPIRV_CROSS_STATIC )
spirv_cross_add_library ( spirv-cross-core spirv_cross_core STATIC
2019-03-27 12:21:11 +00:00
$ { s p i r v - c r o s s - c o r e - s o u r c e s } )
2019-02-12 10:11:29 +00:00
2019-03-27 12:21:11 +00:00
if ( SPIRV_CROSS_ENABLE_GLSL )
spirv_cross_add_library ( spirv-cross-glsl spirv_cross_glsl STATIC
$ { s p i r v - c r o s s - g l s l - s o u r c e s } )
target_link_libraries ( spirv-cross-glsl PRIVATE spirv-cross-core )
endif ( )
2019-02-12 10:11:29 +00:00
2019-03-27 12:21:11 +00:00
if ( SPIRV_CROSS_ENABLE_CPP )
spirv_cross_add_library ( spirv-cross-cpp spirv_cross_cpp STATIC
$ { s p i r v - c r o s s - c p p - s o u r c e s } )
2019-02-12 10:11:29 +00:00
2019-03-27 12:21:11 +00:00
if ( SPIRV_CROSS_ENABLE_GLSL )
target_link_libraries ( spirv-cross-cpp PRIVATE spirv-cross-glsl )
else ( )
message ( FATAL_ERROR "Must enable GLSL support to enable C++ support." )
endif ( )
endif ( )
2019-02-12 10:11:29 +00:00
2019-03-27 12:21:11 +00:00
if ( SPIRV_CROSS_ENABLE_REFLECT )
2019-03-29 09:29:44 +00:00
if ( SPIRV_CROSS_ENABLE_GLSL )
spirv_cross_add_library ( spirv-cross-reflect spirv_cross_reflect STATIC
$ { s p i r v - c r o s s - r e f l e c t - s o u r c e s } )
else ( )
message ( FATAL_ERROR "Must enable GLSL support to enable JSON reflection support." )
endif ( )
2019-03-27 12:21:11 +00:00
endif ( )
2019-02-12 10:11:29 +00:00
2019-03-27 12:21:11 +00:00
if ( SPIRV_CROSS_ENABLE_MSL )
spirv_cross_add_library ( spirv-cross-msl spirv_cross_msl STATIC
$ { s p i r v - c r o s s - m s l - s o u r c e s } )
if ( SPIRV_CROSS_ENABLE_GLSL )
target_link_libraries ( spirv-cross-msl PRIVATE spirv-cross-glsl )
else ( )
message ( FATAL_ERROR "Must enable GLSL support to enable MSL support." )
endif ( )
endif ( )
2019-02-12 10:11:29 +00:00
2019-03-27 12:21:11 +00:00
if ( SPIRV_CROSS_ENABLE_HLSL )
spirv_cross_add_library ( spirv-cross-hlsl spirv_cross_hlsl STATIC
$ { s p i r v - c r o s s - h l s l - s o u r c e s } )
if ( SPIRV_CROSS_ENABLE_GLSL )
target_link_libraries ( spirv-cross-hlsl PRIVATE spirv-cross-glsl )
else ( )
message ( FATAL_ERROR "Must enable GLSL support to enable HLSL support." )
endif ( )
endif ( )
2019-02-12 10:11:29 +00:00
2019-03-27 12:21:11 +00:00
if ( SPIRV_CROSS_ENABLE_UTIL )
spirv_cross_add_library ( spirv-cross-util spirv_cross_util STATIC
$ { s p i r v - c r o s s - u t i l - s o u r c e s } )
target_link_libraries ( spirv-cross-util PRIVATE spirv-cross-core )
endif ( )
2019-02-12 10:11:29 +00:00
2019-03-27 12:21:11 +00:00
if ( SPIRV_CROSS_ENABLE_C_API )
spirv_cross_add_library ( spirv-cross-c spirv_cross_c STATIC
$ { s p i r v - c r o s s - c - s o u r c e s } )
2019-05-24 13:23:29 +00:00
target_include_directories ( spirv-cross-c PRIVATE ${ CMAKE_CURRENT_BINARY_DIR } )
target_compile_definitions ( spirv-cross-c PRIVATE HAVE_SPIRV_CROSS_GIT_VERSION )
2019-03-27 12:21:11 +00:00
if ( SPIRV_CROSS_ENABLE_GLSL )
target_link_libraries ( spirv-cross-c PRIVATE spirv-cross-glsl )
target_compile_definitions ( spirv-cross-c PRIVATE SPIRV_CROSS_C_API_GLSL=1 )
endif ( )
if ( SPIRV_CROSS_ENABLE_HLSL )
target_link_libraries ( spirv-cross-c PRIVATE spirv-cross-hlsl )
target_compile_definitions ( spirv-cross-c PRIVATE SPIRV_CROSS_C_API_HLSL=1 )
endif ( )
if ( SPIRV_CROSS_ENABLE_MSL )
target_link_libraries ( spirv-cross-c PRIVATE spirv-cross-msl )
target_compile_definitions ( spirv-cross-c PRIVATE SPIRV_CROSS_C_API_MSL=1 )
endif ( )
if ( SPIRV_CROSS_ENABLE_CPP )
target_link_libraries ( spirv-cross-c PRIVATE spirv-cross-cpp )
target_compile_definitions ( spirv-cross-c PRIVATE SPIRV_CROSS_C_API_CPP=1 )
endif ( )
if ( SPIRV_CROSS_ENABLE_REFLECT )
target_link_libraries ( spirv-cross-c PRIVATE spirv-cross-reflect )
target_compile_definitions ( spirv-cross-c PRIVATE SPIRV_CROSS_C_API_REFLECT=1 )
endif ( )
endif ( )
2019-02-12 10:11:29 +00:00
endif ( )
2019-05-18 08:47:02 +00:00
set ( spirv-cross-abi-major 0 )
2019-06-24 08:45:13 +00:00
set ( spirv-cross-abi-minor 15 )
2019-05-18 08:47:02 +00:00
set ( spirv-cross-abi-patch 0 )
2019-02-12 10:11:29 +00:00
if ( SPIRV_CROSS_SHARED )
set ( SPIRV_CROSS_VERSION ${ spirv-cross-abi-major } . ${ spirv-cross-abi-minor } . ${ spirv-cross-abi-patch } )
set ( SPIRV_CROSS_INSTALL_LIB_DIR ${ CMAKE_INSTALL_PREFIX } /lib )
2019-03-04 10:33:01 +00:00
set ( SPIRV_CROSS_INSTALL_INC_DIR ${ CMAKE_INSTALL_PREFIX } /include/spirv_cross )
2019-02-12 10:11:29 +00:00
configure_file (
2019-03-27 12:21:11 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / p k g - c o n f i g / s p i r v - c r o s s - c - s h a r e d . p c . i n
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / s p i r v - c r o s s - c - s h a r e d . p c @ O N L Y )
2019-02-12 10:11:29 +00:00
install ( FILES ${ CMAKE_CURRENT_BINARY_DIR } /spirv-cross-c-shared.pc DESTINATION ${ CMAKE_INSTALL_PREFIX } /share/pkgconfig )
spirv_cross_add_library ( spirv-cross-c-shared spirv_cross_c_shared SHARED
2019-03-27 12:21:11 +00:00
$ { s p i r v - c r o s s - c o r e - s o u r c e s }
$ { s p i r v - c r o s s - c - s o u r c e s } )
2019-05-24 13:23:29 +00:00
target_include_directories ( spirv-cross-c-shared PRIVATE ${ CMAKE_CURRENT_BINARY_DIR } )
target_compile_definitions ( spirv-cross-c-shared PRIVATE HAVE_SPIRV_CROSS_GIT_VERSION )
2019-03-27 12:21:11 +00:00
if ( SPIRV_CROSS_ENABLE_GLSL )
target_sources ( spirv-cross-c-shared PRIVATE ${ spirv-cross-glsl-sources } )
target_compile_definitions ( spirv-cross-c-shared PRIVATE SPIRV_CROSS_C_API_GLSL=1 )
endif ( )
if ( SPIRV_CROSS_ENABLE_HLSL )
if ( SPIRV_CROSS_ENABLE_GLSL )
target_sources ( spirv-cross-c-shared PRIVATE ${ spirv-cross-hlsl-sources } )
else ( )
message ( FATAL_ERROR "Must enable GLSL support to enable HLSL support." )
endif ( )
target_compile_definitions ( spirv-cross-c-shared PRIVATE SPIRV_CROSS_C_API_HLSL=1 )
endif ( )
if ( SPIRV_CROSS_ENABLE_MSL )
if ( SPIRV_CROSS_ENABLE_GLSL )
target_sources ( spirv-cross-c-shared PRIVATE ${ spirv-cross-msl-sources } )
else ( )
message ( FATAL_ERROR "Must enable GLSL support to enable MSL support." )
endif ( )
target_compile_definitions ( spirv-cross-c-shared PRIVATE SPIRV_CROSS_C_API_MSL=1 )
endif ( )
if ( SPIRV_CROSS_ENABLE_CPP )
if ( SPIRV_CROSS_ENABLE_GLSL )
target_sources ( spirv-cross-c-shared PRIVATE ${ spirv-cross-cpp-sources } )
else ( )
message ( FATAL_ERROR "Must enable GLSL support to enable C++ support." )
endif ( )
target_compile_definitions ( spirv-cross-c-shared PRIVATE SPIRV_CROSS_C_API_CPP=1 )
endif ( )
if ( SPIRV_CROSS_ENABLE_REFLECT )
2019-03-29 09:29:44 +00:00
if ( SPIRV_CROSS_ENABLE_GLSL )
target_sources ( spirv-cross-c-shared PRIVATE ${ spirv-cross-reflect-sources } )
else ( )
message ( FATAL_ERROR "Must enable GLSL support to enable JSON reflection support." )
endif ( )
2019-03-27 12:21:11 +00:00
target_compile_definitions ( spirv-cross-c-shared PRIVATE SPIRV_CROSS_C_API_REFLECT=1 )
endif ( )
2019-02-12 10:11:29 +00:00
if ( CMAKE_COMPILER_IS_GNUCXX OR ( ${ CMAKE_CXX_COMPILER_ID } MATCHES "Clang" ) )
# Only export the C API.
target_compile_options ( spirv-cross-c-shared PRIVATE -fvisibility=hidden )
if ( NOT APPLE )
2019-03-05 09:11:04 +00:00
set_target_properties ( spirv-cross-c-shared PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}" )
2019-02-12 10:11:29 +00:00
endif ( )
endif ( )
2019-03-04 09:08:31 +00:00
target_compile_definitions ( spirv-cross-c-shared PRIVATE SPVC_EXPORT_SYMBOLS )
2019-02-12 10:11:29 +00:00
set_target_properties ( spirv-cross-c-shared PROPERTIES
2019-03-27 12:21:11 +00:00
V E R S I O N $ { S P I R V _ C R O S S _ V E R S I O N }
S O V E R S I O N $ { s p i r v - c r o s s - a b i - m a j o r } )
2019-02-12 10:11:29 +00:00
endif ( )
if ( SPIRV_CROSS_CLI )
2019-03-27 12:21:11 +00:00
if ( NOT SPIRV_CROSS_ENABLE_GLSL )
message ( FATAL_ERROR "Must enable GLSL if building CLI." )
endif ( )
if ( NOT SPIRV_CROSS_ENABLE_HLSL )
message ( FATAL_ERROR "Must enable HLSL if building CLI." )
endif ( )
if ( NOT SPIRV_CROSS_ENABLE_MSL )
message ( FATAL_ERROR "Must enable MSL if building CLI." )
endif ( )
if ( NOT SPIRV_CROSS_ENABLE_CPP )
message ( FATAL_ERROR "Must enable C++ if building CLI." )
endif ( )
if ( NOT SPIRV_CROSS_ENABLE_REFLECT )
message ( FATAL_ERROR "Must enable reflection if building CLI." )
endif ( )
if ( NOT SPIRV_CROSS_ENABLE_UTIL )
message ( FATAL_ERROR "Must enable utils if building CLI." )
endif ( )
2019-02-12 10:11:29 +00:00
if ( NOT SPIRV_CROSS_STATIC )
message ( FATAL_ERROR "Must build static libraries if building CLI." )
endif ( )
add_executable ( spirv-cross main.cpp )
target_compile_options ( spirv-cross PRIVATE ${ spirv-compiler-options } )
2019-05-24 13:23:29 +00:00
target_include_directories ( spirv-cross PRIVATE ${ CMAKE_CURRENT_BINARY_DIR } )
target_compile_definitions ( spirv-cross PRIVATE ${ spirv-compiler-defines } HAVE_SPIRV_CROSS_GIT_VERSION )
2019-03-05 10:15:08 +00:00
set_target_properties ( spirv-cross PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}" )
2019-02-12 10:11:29 +00:00
install ( TARGETS spirv-cross RUNTIME DESTINATION bin )
target_link_libraries ( spirv-cross PRIVATE
2019-03-27 12:21:11 +00:00
s p i r v - c r o s s - g l s l
s p i r v - c r o s s - h l s l
s p i r v - c r o s s - c p p
s p i r v - c r o s s - r e f l e c t
s p i r v - c r o s s - m s l
s p i r v - c r o s s - u t i l
s p i r v - c r o s s - c o r e )
2017-01-24 00:49:16 +00:00
2019-03-07 09:22:58 +00:00
if ( SPIRV_CROSS_ENABLE_TESTS )
# Set up tests, using only the simplest modes of the test_shaders
# script. You have to invoke the script manually to:
# - Update the reference files
# - Get cycle counts from malisc
# - Keep failing outputs
find_package ( PythonInterp )
find_program ( spirv-cross-glslang NAMES glslangValidator
2019-03-27 12:21:11 +00:00
P A T H S $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / e x t e r n a l / g l s l a n g - b u i l d / o u t p u t / b i n
N O _ D E F A U L T _ P A T H )
2019-03-07 09:22:58 +00:00
find_program ( spirv-cross-spirv-as NAMES spirv-as
2019-03-27 12:21:11 +00:00
P A T H S $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / e x t e r n a l / s p i r v - t o o l s - b u i l d / o u t p u t / b i n
N O _ D E F A U L T _ P A T H )
2019-03-07 09:22:58 +00:00
find_program ( spirv-cross-spirv-val NAMES spirv-val
2019-03-27 12:21:11 +00:00
P A T H S $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / e x t e r n a l / s p i r v - t o o l s - b u i l d / o u t p u t / b i n
N O _ D E F A U L T _ P A T H )
2019-03-07 11:36:16 +00:00
find_program ( spirv-cross-spirv-opt NAMES spirv-opt
2019-03-27 12:21:11 +00:00
P A T H S $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / e x t e r n a l / s p i r v - t o o l s - b u i l d / o u t p u t / b i n
N O _ D E F A U L T _ P A T H )
2019-03-07 09:22:58 +00:00
2019-03-07 11:36:16 +00:00
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" ) )
2019-03-07 09:22:58 +00:00
set ( SPIRV_CROSS_ENABLE_TESTS OFF )
message ( "Could not find glslang or SPIRV-Tools build under external/. Run ./checkout_glslang_spirv_tools.sh and ./build_glslang_spirv_tools.sh. Testing will be disabled." )
else ( )
set ( SPIRV_CROSS_ENABLE_TESTS ON )
message ( "Found glslang and SPIRV-Tools. Enabling test suite." )
message ( "Found glslangValidator in: ${spirv-cross-glslang}." )
message ( "Found spirv-as in: ${spirv-cross-spirv-as}." )
message ( "Found spirv-val in: ${spirv-cross-spirv-val}." )
2019-03-07 11:36:16 +00:00
message ( "Found spirv-opt in: ${spirv-cross-spirv-opt}." )
2019-03-07 09:22:58 +00:00
endif ( )
2019-03-07 11:36:16 +00:00
set ( spirv-cross-externals
2019-03-27 12:21:11 +00:00
- - g l s l a n g " $ { s p i r v - c r o s s - g l s l a n g } "
- - s p i r v - a s " $ { s p i r v - c r o s s - s p i r v - a s } "
- - s p i r v - o p t " $ { s p i r v - c r o s s - s p i r v - o p t } "
- - s p i r v - v a l " $ { s p i r v - c r o s s - s p i r v - v a l } " )
2019-03-07 11:36:16 +00:00
2019-03-07 09:22:58 +00:00
if ( ${ PYTHONINTERP_FOUND } AND SPIRV_CROSS_ENABLE_TESTS )
if ( ${ PYTHON_VERSION_MAJOR } GREATER 2 )
add_executable ( spirv-cross-c-api-test tests-other/c_api_test.c )
target_link_libraries ( spirv-cross-c-api-test spirv-cross-c )
set_target_properties ( spirv-cross-c-api-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}" )
2019-04-08 13:22:22 +00:00
add_executable ( spirv-cross-small-vector-test tests-other/small_vector.cpp )
target_link_libraries ( spirv-cross-small-vector-test spirv-cross-core )
set_target_properties ( spirv-cross-small-vector-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}" )
2019-06-10 13:41:36 +00:00
add_executable ( spirv-cross-msl-constexpr-test tests-other/msl_constexpr_test.cpp )
target_link_libraries ( spirv-cross-msl-constexpr-test spirv-cross-c )
set_target_properties ( spirv-cross-msl-constexpr-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}" )
2019-06-24 08:45:13 +00:00
add_executable ( spirv-cross-msl-resource-binding-test tests-other/msl_resource_bindings.cpp )
target_link_libraries ( spirv-cross-msl-resource-binding-test spirv-cross-c )
set_target_properties ( spirv-cross-msl-resource-binding-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}" )
2019-03-07 09:22:58 +00:00
if ( CMAKE_COMPILER_IS_GNUCXX OR ( ${ CMAKE_CXX_COMPILER_ID } MATCHES "Clang" ) )
target_compile_options ( spirv-cross-c-api-test PRIVATE -std=c89 -Wall -Wextra )
endif ( )
2019-03-07 11:36:16 +00:00
add_test ( NAME spirv-cross-c-api-test
2019-05-14 08:06:33 +00:00
C O M M A N D $ < T A R G E T _ F I L E : s p i r v - c r o s s - c - a p i - t e s t > $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t s - o t h e r / c _ a p i _ t e s t . s p v
$ { s p i r v - c r o s s - a b i - m a j o r }
$ { s p i r v - c r o s s - a b i - m i n o r }
$ { s p i r v - c r o s s - a b i - p a t c h } )
2019-04-08 13:22:22 +00:00
add_test ( NAME spirv-cross-small-vector-test
C O M M A N D $ < T A R G E T _ F I L E : s p i r v - c r o s s - s m a l l - v e c t o r - t e s t > )
2019-06-10 13:41:36 +00:00
add_test ( NAME spirv-cross-msl-constexpr-test
C O M M A N D $ < T A R G E T _ F I L E : s p i r v - c r o s s - m s l - c o n s t e x p r - t e s t > $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t s - o t h e r / m s l _ c o n s t e x p r _ t e s t . s p v )
2019-06-24 08:45:13 +00:00
add_test ( NAME spirv-cross-msl-resource-binding-test
C O M M A N D $ < T A R G E T _ F I L E : s p i r v - c r o s s - m s l - r e s o u r c e - b i n d i n g - t e s t > $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t s - o t h e r / m s l _ r e s o u r c e _ b i n d i n g . s p v )
2019-03-07 11:36:16 +00:00
add_test ( NAME spirv-cross-test
2019-03-27 12:21:11 +00:00
C O M M A N D $ { P Y T H O N _ E X E C U T A B L E } $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t _ s h a d e r s . p y - - p a r a l l e l
$ { s p i r v - c r o s s - e x t e r n a l s }
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s h a d e r s
W O R K I N G _ D I R E C T O R Y $ < T A R G E T _ F I L E _ D I R : s p i r v - c r o s s > )
2019-03-07 11:36:16 +00:00
add_test ( NAME spirv-cross-test-no-opt
2019-03-27 12:21:11 +00:00
C O M M A N D $ { P Y T H O N _ E X E C U T A B L E } $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t _ s h a d e r s . p y - - p a r a l l e l
$ { s p i r v - c r o s s - e x t e r n a l s }
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s h a d e r s - n o - o p t
W O R K I N G _ D I R E C T O R Y $ < T A R G E T _ F I L E _ D I R : s p i r v - c r o s s > )
2019-03-07 11:36:16 +00:00
add_test ( NAME spirv-cross-test-metal
2019-03-27 12:21:11 +00:00
C O M M A N D $ { P Y T H O N _ E X E C U T A B L E } $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t _ s h a d e r s . p y - - m e t a l - - p a r a l l e l
$ { s p i r v - c r o s s - e x t e r n a l s }
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s h a d e r s - m s l
W O R K I N G _ D I R E C T O R Y $ < T A R G E T _ F I L E _ D I R : s p i r v - c r o s s > )
2019-03-07 11:36:16 +00:00
add_test ( NAME spirv-cross-test-metal-no-opt
2019-03-27 12:21:11 +00:00
C O M M A N D $ { P Y T H O N _ E X E C U T A B L E } $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t _ s h a d e r s . p y - - m e t a l - - p a r a l l e l
$ { s p i r v - c r o s s - e x t e r n a l s }
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s h a d e r s - m s l - n o - o p t
W O R K I N G _ D I R E C T O R Y $ < T A R G E T _ F I L E _ D I R : s p i r v - c r o s s > )
2019-03-07 11:36:16 +00:00
add_test ( NAME spirv-cross-test-hlsl
2019-03-27 12:21:11 +00:00
C O M M A N D $ { P Y T H O N _ E X E C U T A B L E } $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t _ s h a d e r s . p y - - h l s l - - p a r a l l e l
$ { s p i r v - c r o s s - e x t e r n a l s }
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s h a d e r s - h l s l
W O R K I N G _ D I R E C T O R Y $ < T A R G E T _ F I L E _ D I R : s p i r v - c r o s s > )
2019-03-07 11:36:16 +00:00
add_test ( NAME spirv-cross-test-hlsl-no-opt
2019-03-27 12:21:11 +00:00
C O M M A N D $ { P Y T H O N _ E X E C U T A B L E } $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t _ s h a d e r s . p y - - h l s l - - p a r a l l e l
$ { s p i r v - c r o s s - e x t e r n a l s }
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s h a d e r s - h l s l - n o - o p t
W O R K I N G _ D I R E C T O R Y $ < T A R G E T _ F I L E _ D I R : s p i r v - c r o s s > )
2019-03-07 11:36:16 +00:00
add_test ( NAME spirv-cross-test-opt
2019-03-27 12:21:11 +00:00
C O M M A N D $ { P Y T H O N _ E X E C U T A B L E } $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t _ s h a d e r s . p y - - o p t - - p a r a l l e l
$ { s p i r v - c r o s s - e x t e r n a l s }
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s h a d e r s
W O R K I N G _ D I R E C T O R Y $ < T A R G E T _ F I L E _ D I R : s p i r v - c r o s s > )
2019-03-07 11:36:16 +00:00
add_test ( NAME spirv-cross-test-metal-opt
2019-03-27 12:21:11 +00:00
C O M M A N D $ { P Y T H O N _ E X E C U T A B L E } $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t _ s h a d e r s . p y - - m e t a l - - o p t - - p a r a l l e l
$ { s p i r v - c r o s s - e x t e r n a l s }
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s h a d e r s - m s l
W O R K I N G _ D I R E C T O R Y $ < T A R G E T _ F I L E _ D I R : s p i r v - c r o s s > )
2019-03-07 11:36:16 +00:00
add_test ( NAME spirv-cross-test-hlsl-opt
2019-03-27 12:21:11 +00:00
C O M M A N D $ { P Y T H O N _ E X E C U T A B L E } $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t _ s h a d e r s . p y - - h l s l - - o p t - - p a r a l l e l
$ { s p i r v - c r o s s - e x t e r n a l s }
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s h a d e r s - h l s l
W O R K I N G _ D I R E C T O R Y $ < T A R G E T _ F I L E _ D I R : s p i r v - c r o s s > )
2019-03-07 11:36:16 +00:00
add_test ( NAME spirv-cross-test-reflection
2019-03-27 12:21:11 +00:00
C O M M A N D $ { P Y T H O N _ E X E C U T A B L E } $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t _ s h a d e r s . p y - - r e f l e c t - - p a r a l l e l
$ { s p i r v - c r o s s - e x t e r n a l s }
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s h a d e r s - r e f l e c t i o n
W O R K I N G _ D I R E C T O R Y $ < T A R G E T _ F I L E _ D I R : s p i r v - c r o s s > )
2019-03-04 10:13:41 +00:00
endif ( )
2019-03-07 09:22:58 +00:00
elseif ( NOT ${ PYTHONINTERP_FOUND } )
message ( WARNING "Testing disabled. Could not find python3. If you have python3 installed try running "
2019-03-27 12:21:11 +00:00
" c m a k e w i t h - D P Y T H O N _ E X E C U T A B L E : F I L E P A T H = / p a t h / t o / p y t h o n 3 t o h e l p i t f i n d t h e e x e c u t a b l e " )
2019-02-12 10:11:29 +00:00
endif ( )
endif ( )
2016-03-19 21:13:06 +00:00
endif ( )