2015-05-22 17:26:19 +00:00
|
|
|
# Copyright (c) 2015 The Khronos Group Inc.
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
# copy of this software and/or associated documentation files (the
|
|
|
|
# "Materials"), to deal in the Materials without restriction, including
|
|
|
|
# without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
# distribute, sublicense, and/or sell copies of the Materials, and to
|
|
|
|
# permit persons to whom the Materials are furnished to do so, subject to
|
|
|
|
# the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included
|
|
|
|
# in all copies or substantial portions of the Materials.
|
|
|
|
#
|
|
|
|
# MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
|
|
|
|
# KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
|
|
|
|
# SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
|
|
|
|
# https://www.khronos.org/registry/
|
|
|
|
#
|
|
|
|
# THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
# MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 2.8)
|
2015-07-29 19:22:09 +00:00
|
|
|
project(spirv-tools)
|
2015-11-18 14:22:10 +00:00
|
|
|
set(SPIRV_TOOLS "SPIRV-Tools")
|
2015-05-22 17:26:19 +00:00
|
|
|
|
|
|
|
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
|
|
|
|
add_definitions(-DSPIRV_LINUX)
|
|
|
|
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
|
|
|
|
add_definitions(-DSPIRV_WINDOWS)
|
|
|
|
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
|
|
|
|
add_definitions(-DSPIRV_MAC)
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Your platform '${CMAKE_SYSTEM_NAME}' is not supported!")
|
|
|
|
endif()
|
|
|
|
|
2015-11-18 14:22:10 +00:00
|
|
|
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
|
2015-05-22 17:26:19 +00:00
|
|
|
message(STATUS "No build type selected, default to Debug")
|
|
|
|
set(CMAKE_BUILD_TYPE "Debug")
|
|
|
|
endif()
|
|
|
|
|
2015-11-19 14:22:53 +00:00
|
|
|
option(SPIRV_WERROR "Enable error on warning" ON)
|
2015-05-22 17:26:19 +00:00
|
|
|
if(UNIX)
|
2015-11-18 14:22:10 +00:00
|
|
|
set(SPIRV_WARNINGS -Wall -Wextra -Wno-missing-field-initializers)
|
2015-10-15 20:43:14 +00:00
|
|
|
|
2015-11-18 14:22:10 +00:00
|
|
|
option(SPIRV_WARN_EVERYTHING "Enable -Weverything" OFF)
|
|
|
|
if(${SPIRV_WARN_EVERYTHING})
|
|
|
|
set(SPIRV_WARNINGS ${SPIRV_WARNINGS}
|
|
|
|
-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded)
|
2015-10-15 20:43:14 +00:00
|
|
|
endif()
|
|
|
|
|
2015-11-18 14:22:10 +00:00
|
|
|
if(${SPIRV_WERROR})
|
|
|
|
set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Werror)
|
2015-05-22 17:26:19 +00:00
|
|
|
endif()
|
2015-11-18 14:22:10 +00:00
|
|
|
elseif(WIN32)
|
|
|
|
set(SPIRV_WARNINGS -D_CRT_SECURE_NO_WARNINGS /wd4800)
|
2015-11-19 14:22:53 +00:00
|
|
|
|
|
|
|
if(${SPIRV_WERROR})
|
|
|
|
set(SPIRV_WARNINGS ${SPIRV_WARNINGS} /WX)
|
|
|
|
endif()
|
2015-05-22 17:26:19 +00:00
|
|
|
endif()
|
|
|
|
|
2015-11-12 16:44:42 +00:00
|
|
|
option(SPIRV_COLOR_TERMINAL "Enable color terminal output" ON)
|
|
|
|
if(${SPIRV_COLOR_TERMINAL})
|
|
|
|
add_definitions(-DSPIRV_COLOR_TERMINAL)
|
2015-05-22 17:26:19 +00:00
|
|
|
endif()
|
|
|
|
|
2015-11-18 14:22:10 +00:00
|
|
|
function(default_compile_options TARGET)
|
|
|
|
target_compile_options(${TARGET} PRIVATE ${SPIRV_WARNINGS})
|
|
|
|
if (UNIX)
|
|
|
|
target_compile_options(${TARGET} PRIVATE
|
|
|
|
-std=c++11 -fno-exceptions -fno-rtti)
|
|
|
|
# For good call stacks in profiles, keep the frame pointers.
|
|
|
|
if(NOT "${SPIRV_PERF}" STREQUAL "")
|
|
|
|
target_compile_options(${TARGET} PRIVATE -fno-omit-frame-pointer)
|
|
|
|
endif()
|
|
|
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
|
|
target_compile_options(${TARGET} PRIVATE -fcolor-diagnostics)
|
|
|
|
set(SPIRV_USE_SANITIZER "" CACHE STRING
|
|
|
|
"Use the clang sanitizer [address|memory|thread|...]")
|
|
|
|
if(NOT "${SPIRV_USE_SANITIZER}" STREQUAL "")
|
|
|
|
target_compile_options(${TARGET} PRIVATE
|
|
|
|
-fsanitize=${SPIRV_USE_SANITIZER})
|
|
|
|
endif()
|
|
|
|
endif()
|
2015-05-22 17:26:19 +00:00
|
|
|
endif()
|
2015-11-18 14:22:10 +00:00
|
|
|
endfunction()
|
2015-05-22 17:26:19 +00:00
|
|
|
|
|
|
|
set(SPIRV_SOURCES
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include/libspirv/libspirv.h
|
2015-10-23 13:53:58 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include/util/bitutils.h
|
2015-10-23 17:23:19 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include/util/hex_float.h
|
2015-11-18 14:22:10 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/assembly_grammar.h
|
2015-05-22 17:26:19 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/binary.h
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/diagnostic.h
|
2015-10-27 20:14:40 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/endian.h
|
2015-10-06 20:22:00 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/ext_inst.h
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/instruction.h
|
2015-05-22 17:26:19 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/opcode.h
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/operand.h
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/print.h
|
2015-11-11 19:24:04 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/spirv_constant.h
|
2015-11-11 21:50:55 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/spirv_definition.h
|
2015-11-11 17:14:36 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/table.h
|
2015-05-22 17:26:19 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/text.h
|
2015-09-24 14:26:51 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/text_handler.h
|
2015-05-22 17:26:19 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/validate.h
|
2015-10-27 19:31:10 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/assembly_grammar.cpp
|
2015-05-22 17:26:19 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/binary.cpp
|
2015-10-27 20:56:14 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/disassemble.cpp
|
2015-05-22 17:26:19 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/diagnostic.cpp
|
2015-10-27 20:14:40 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/endian.cpp
|
2015-05-22 17:26:19 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/ext_inst.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/opcode.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/operand.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/print.cpp
|
2015-11-12 18:48:30 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/table.cpp
|
2015-05-22 17:26:19 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/text.cpp
|
2015-09-24 14:26:51 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/text_handler.cpp
|
2015-05-22 17:26:19 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/validate.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/source/validate_id.cpp)
|
|
|
|
|
2015-11-13 01:42:16 +00:00
|
|
|
add_library(${SPIRV_TOOLS} ${SPIRV_SOURCES})
|
2015-11-18 14:22:10 +00:00
|
|
|
default_compile_options(${SPIRV_TOOLS})
|
|
|
|
target_include_directories(${SPIRV_TOOLS} PUBLIC
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/external/include)
|
|
|
|
|
|
|
|
option(SPIRV_SKIP_EXECUTABLES
|
|
|
|
"Skip building the executables and tests along with the library" OFF)
|
|
|
|
set(SPIRV_INSTALL_TARGETS ${SPIRV_TOOLS})
|
|
|
|
if (NOT ${SPIRV_SKIP_EXECUTABLES})
|
|
|
|
list(APPEND SPIRV_INSTALL_TARGETS spirv-as spirv-dis spirv-val)
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2015-11-18 14:22:10 +00:00
|
|
|
add_executable(spirv-as ${CMAKE_CURRENT_SOURCE_DIR}/tools/as/as.cpp)
|
|
|
|
default_compile_options(spirv-as)
|
|
|
|
target_link_libraries(spirv-as PRIVATE ${SPIRV_TOOLS})
|
2015-09-04 19:13:57 +00:00
|
|
|
|
2015-11-18 14:22:10 +00:00
|
|
|
add_executable(spirv-dis ${CMAKE_CURRENT_SOURCE_DIR}/tools/dis/dis.cpp)
|
|
|
|
default_compile_options(spirv-dis)
|
|
|
|
target_link_libraries(spirv-dis PRIVATE ${SPIRV_TOOLS})
|
|
|
|
|
|
|
|
add_executable(spirv-val ${CMAKE_CURRENT_SOURCE_DIR}/tools/val/val.cpp)
|
|
|
|
default_compile_options(spirv-val)
|
|
|
|
target_link_libraries(spirv-val PRIVATE ${SPIRV_TOOLS})
|
2015-09-04 19:13:57 +00:00
|
|
|
|
2015-10-21 13:26:54 +00:00
|
|
|
set(GMOCK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest/googlemock)
|
|
|
|
if(EXISTS ${GMOCK_DIR})
|
2015-09-04 19:13:57 +00:00
|
|
|
if(WIN32)
|
|
|
|
option(gtest_force_shared_crt
|
|
|
|
"Use shared (DLL) run-time lib even when Google Test is built as static lib."
|
|
|
|
ON)
|
|
|
|
endif()
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2015-10-21 13:26:54 +00:00
|
|
|
add_subdirectory(${GMOCK_DIR})
|
2015-09-04 19:13:57 +00:00
|
|
|
endif()
|
|
|
|
if (TARGET gmock)
|
|
|
|
message(STATUS "Found Google Mock, building tests.")
|
|
|
|
|
2015-11-18 14:22:10 +00:00
|
|
|
set(TEST_SOURCES
|
2015-09-04 19:13:57 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TestFixture.h
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/UnitSPIRV.h
|
|
|
|
|
2015-10-06 20:22:00 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/AssemblyContext.cpp
|
2015-09-10 18:00:00 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/AssemblyFormat.cpp
|
2015-09-08 19:15:23 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/BinaryDestroy.cpp
|
2015-09-04 19:13:57 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/BinaryEndianness.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/BinaryHeaderGet.cpp
|
2015-10-30 20:06:15 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/BinaryParse.cpp
|
2015-09-04 19:13:57 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/BinaryToText.cpp
|
2015-10-14 18:18:43 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/BinaryToText.Literal.cpp
|
2015-09-04 19:13:57 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/Comment.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/DiagnosticPrint.cpp
|
2015-10-09 19:48:09 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/DiagnosticStream.cpp
|
2015-09-04 19:13:57 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/ExtInstGLSLstd450.cpp
|
2015-11-04 22:38:17 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/ExtInst.OpenCL.std.cpp
|
2015-09-04 19:13:57 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/FixWord.cpp
|
2015-10-26 19:43:12 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/GeneratorMagicNumber.cpp
|
2015-10-23 17:23:19 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/HexFloat.cpp
|
2015-09-04 19:13:57 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/ImmediateInt.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/LibspirvMacros.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/NamedId.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/OpcodeMake.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/OpcodeRequiresCapabilities.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/OpcodeSplit.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/OpcodeTableGet.cpp
|
2015-11-04 22:38:17 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/OperandCapabilities.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/Operand.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/OperandPattern.cpp
|
2015-09-04 19:13:57 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextAdvance.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextDestroy.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextLiteral.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextStartsNewInst.cpp
|
2015-09-10 17:23:11 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Annotation.cpp
|
2015-09-23 14:07:17 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Barrier.cpp
|
2015-09-15 14:27:22 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Constant.cpp
|
2015-09-14 18:28:33 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.ControlFlow.cpp
|
2015-11-04 22:38:17 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.cpp
|
2015-09-09 14:58:02 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Debug.cpp
|
2015-09-30 15:44:34 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.DeviceSideEnqueue.cpp
|
2015-11-09 23:55:42 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Extension.cpp
|
2015-09-14 18:50:37 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Function.cpp
|
2015-09-14 21:07:11 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Group.cpp
|
2015-09-18 15:19:18 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Image.cpp
|
2015-09-15 17:36:21 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Literal.cpp
|
2015-09-14 19:08:48 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Memory.cpp
|
2015-09-08 21:11:40 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Miscellaneous.cpp
|
2015-09-10 20:39:09 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.ModeSetting.cpp
|
2015-09-12 02:35:04 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.TypeDeclaration.cpp
|
2015-09-04 19:13:57 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/TextWordGet.cpp
|
2015-09-09 22:10:01 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/UnitSPIRV.cpp
|
2015-09-04 19:13:57 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/Validate.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/ValidateID.cpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test/main.cpp)
|
2015-11-04 22:38:17 +00:00
|
|
|
|
2015-11-18 14:22:10 +00:00
|
|
|
add_executable(UnitSPIRV ${TEST_SOURCES})
|
|
|
|
default_compile_options(UnitSPIRV)
|
|
|
|
target_include_directories(UnitSPIRV PRIVATE
|
|
|
|
${gmock_SOURCE_DIR}/include ${gtest_SOURCE_DIR}/include)
|
|
|
|
target_link_libraries(UnitSPIRV PRIVATE ${SPIRV_TOOLS} gmock)
|
2015-09-04 19:13:57 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "Did not find googletest, tests will not be built."
|
|
|
|
"To enable tests place googletest in '<spirv-dir>/external/googletest'.")
|
2015-05-22 17:26:19 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2015-11-18 14:22:10 +00:00
|
|
|
install(TARGETS ${SPIRV_INSTALL_TARGETS}
|
2015-05-22 17:26:19 +00:00
|
|
|
RUNTIME DESTINATION bin
|
|
|
|
LIBRARY DESTINATION lib
|
|
|
|
ARCHIVE DESTINATION lib)
|
|
|
|
|
|
|
|
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/libspirv/libspirv.h
|
|
|
|
DESTINATION include/libspirv/)
|