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)
|
|
|
|
project(SPIRV-Cross)
|
|
|
|
enable_testing()
|
|
|
|
|
2016-12-15 19:46:10 +00:00
|
|
|
option(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS "Instead of throwing exceptions assert" OFF)
|
2016-12-12 21:33:22 +00:00
|
|
|
|
2016-03-19 21:13:06 +00:00
|
|
|
if(${CMAKE_GENERATOR} MATCHES "Makefile")
|
|
|
|
if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
message(FATAL_ERROR "Build out of tree to avoid overwriting Makefile")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2016-12-15 19:46:10 +00:00
|
|
|
set(spirv-compiler-options "")
|
|
|
|
set(spirv-compiler-defines "")
|
|
|
|
|
|
|
|
if(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
|
|
|
|
set(spirv-compiler-defines ${spirv-compiler-defines} SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
|
|
|
|
endif()
|
|
|
|
|
2016-03-19 21:13:06 +00:00
|
|
|
# To specify special debug or optimization options, use
|
|
|
|
# -DCMAKE_CXX_COMPILE_FLAGS
|
|
|
|
# However, we require the C++11 dialect.
|
|
|
|
if (NOT "${MSVC}")
|
2016-12-15 19:46:10 +00:00
|
|
|
set(spirv-compiler-options ${spirv-compiler-options} -std=c++11 -Wall -Wextra -Werror -Wshadow)
|
|
|
|
set(spirv-compiler-defines ${spirv-compiler-defines} __STDC_LIMIT_MACROS)
|
2016-12-12 21:33:22 +00:00
|
|
|
|
|
|
|
if(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
|
|
|
|
set(spirv-compiler-options ${spirv-compiler-options} -fno-exceptions)
|
|
|
|
endif()
|
|
|
|
endif()
|
2016-03-19 21:13:06 +00:00
|
|
|
|
2017-01-24 00:49:16 +00:00
|
|
|
macro(extract_headers out_abs file_list)
|
|
|
|
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})
|
|
|
|
if(("${ext}" STREQUAL "h") OR ("${ext}" STREQUAL "hpp"))
|
|
|
|
list(APPEND ${out_abs} "${_a}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
macro(spirv_cross_add_library name config_name)
|
|
|
|
add_library(${name} ${ARGN})
|
|
|
|
extract_headers(hdrs "${ARGN}")
|
|
|
|
target_include_directories(${name} PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
|
|
|
$<INSTALL_INTERFACE:include/spirv_cross>)
|
|
|
|
set_target_properties(${name} PROPERTIES
|
|
|
|
PUBLIC_HEADERS "${hdrs}")
|
|
|
|
target_compile_options(${name} PRIVATE ${spirv-compiler-options})
|
|
|
|
target_compile_definitions(${name} PRIVATE ${spirv-compiler-defines})
|
|
|
|
install(TARGETS ${name}
|
|
|
|
EXPORT ${config_name}Config
|
|
|
|
RUNTIME DESTINATION bin
|
|
|
|
LIBRARY DESTINATION lib
|
|
|
|
ARCHIVE DESTINATION lib
|
|
|
|
PUBLIC_HEADER DESTINATION include/spirv_cross)
|
|
|
|
install(FILES ${hdrs} DESTINATION include/spirv_cross)
|
|
|
|
install(EXPORT ${config_name}Config DESTINATION share/${config_name}/cmake)
|
2018-08-04 06:39:33 +00:00
|
|
|
export(TARGETS ${name} FILE ${config_name}Config.cmake)
|
2017-01-24 00:49:16 +00:00
|
|
|
endmacro()
|
|
|
|
|
|
|
|
|
2017-01-24 01:03:35 +00:00
|
|
|
spirv_cross_add_library(spirv-cross-core spirv_cross_core STATIC
|
2017-01-24 00:49:16 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/GLSL.std.450.h
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_common.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross.cpp
|
2018-10-05 09:30:57 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_parser.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_parser.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_parsed_ir.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_parsed_ir.cpp
|
2017-01-24 00:49:16 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cfg.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cfg.cpp)
|
|
|
|
|
|
|
|
spirv_cross_add_library(spirv-cross-glsl spirv_cross_glsl STATIC
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_glsl.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_glsl.hpp)
|
|
|
|
|
|
|
|
spirv_cross_add_library(spirv-cross-cpp spirv_cross_cpp STATIC
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cpp.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cpp.cpp)
|
|
|
|
|
2018-06-03 18:16:37 +00:00
|
|
|
spirv_cross_add_library(spirv-cross-reflect spirv_cross_reflect STATIC
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.cpp)
|
|
|
|
|
2017-01-24 00:49:16 +00:00
|
|
|
spirv_cross_add_library(spirv-cross-msl spirv_cross_msl STATIC
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_msl.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_msl.cpp)
|
|
|
|
|
2017-05-03 21:46:49 +00:00
|
|
|
spirv_cross_add_library(spirv-cross-hlsl spirv_cross_hlsl STATIC
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_hlsl.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_hlsl.cpp)
|
|
|
|
|
2018-03-02 06:47:08 +00:00
|
|
|
spirv_cross_add_library(spirv-cross-util spirv_cross_util STATIC
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_util.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_util.cpp)
|
|
|
|
|
2017-01-24 00:49:16 +00:00
|
|
|
add_executable(spirv-cross main.cpp)
|
2017-09-27 22:19:01 +00:00
|
|
|
target_compile_options(spirv-cross PRIVATE ${spirv-compiler-options})
|
|
|
|
target_compile_definitions(spirv-cross PRIVATE ${spirv-compiler-defines})
|
|
|
|
|
2017-01-24 00:49:16 +00:00
|
|
|
install(TARGETS spirv-cross RUNTIME DESTINATION bin)
|
2018-06-03 18:16:37 +00:00
|
|
|
target_link_libraries(spirv-cross spirv-cross-glsl spirv-cross-hlsl spirv-cross-cpp spirv-cross-reflect spirv-cross-msl spirv-cross-util spirv-cross-core)
|
2018-03-02 06:47:08 +00:00
|
|
|
target_link_libraries(spirv-cross-util spirv-cross-core)
|
2017-01-24 00:49:16 +00:00
|
|
|
target_link_libraries(spirv-cross-glsl spirv-cross-core)
|
|
|
|
target_link_libraries(spirv-cross-msl spirv-cross-glsl)
|
2017-05-03 21:46:49 +00:00
|
|
|
target_link_libraries(spirv-cross-hlsl spirv-cross-glsl)
|
2017-01-24 00:49:16 +00:00
|
|
|
target_link_libraries(spirv-cross-cpp spirv-cross-glsl)
|
2016-03-19 21:13:06 +00:00
|
|
|
|
|
|
|
# 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
|
2016-11-18 22:02:48 +00:00
|
|
|
find_package(PythonInterp)
|
2017-01-12 09:57:44 +00:00
|
|
|
if (${PYTHONINTERP_FOUND})
|
|
|
|
if (${PYTHON_VERSION_MAJOR} GREATER 2)
|
|
|
|
add_test(NAME spirv-cross-test
|
2018-10-26 08:53:11 +00:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --parallel
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/shaders
|
|
|
|
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
2018-04-18 14:43:28 +00:00
|
|
|
add_test(NAME spirv-cross-test-no-opt
|
2018-10-26 08:53:11 +00:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --parallel
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/shaders-no-opt
|
|
|
|
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
2017-01-18 18:05:57 +00:00
|
|
|
add_test(NAME spirv-cross-test-metal
|
2018-10-26 08:53:11 +00:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --metal --parallel
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/shaders-msl
|
|
|
|
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
2018-04-18 14:43:28 +00:00
|
|
|
add_test(NAME spirv-cross-test-metal-no-opt
|
2018-10-26 08:53:11 +00:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --metal --parallel
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/shaders-msl-no-opt
|
|
|
|
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
2017-01-28 07:58:39 +00:00
|
|
|
add_test(NAME spirv-cross-test-hlsl
|
2018-10-26 08:53:11 +00:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --hlsl --parallel
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/shaders-hlsl
|
|
|
|
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
2018-04-18 14:43:28 +00:00
|
|
|
add_test(NAME spirv-cross-test-hlsl-no-opt
|
2018-10-26 08:53:11 +00:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --hlsl --parallel
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/shaders-hlsl-no-opt
|
|
|
|
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
2017-11-21 09:15:13 +00:00
|
|
|
add_test(NAME spirv-cross-test-opt
|
2018-10-26 08:53:11 +00:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --opt --parallel
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/shaders
|
|
|
|
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
2017-11-21 09:15:13 +00:00
|
|
|
add_test(NAME spirv-cross-test-metal-opt
|
2018-10-26 08:53:11 +00:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --metal --opt --parallel
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/shaders-msl
|
|
|
|
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
2017-11-21 09:15:13 +00:00
|
|
|
add_test(NAME spirv-cross-test-hlsl-opt
|
2018-10-26 08:53:11 +00:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --hlsl --opt --parallel
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/shaders-hlsl
|
|
|
|
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
|
|
|
add_test(NAME spirv-cross-test-reflection
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --reflect --parallel
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/shaders-reflection
|
|
|
|
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
2017-01-12 09:57:44 +00:00
|
|
|
endif()
|
2016-11-18 22:02:48 +00:00
|
|
|
else()
|
2016-12-12 21:33:22 +00:00
|
|
|
message(WARNING "Testing disabled. Could not find python3. If you have python3 installed try running "
|
|
|
|
"cmake with -DPYTHON_EXECUTABLE:FILEPATH=/path/to/python3 to help it find the executable")
|
2016-03-19 21:13:06 +00:00
|
|
|
endif()
|