2016-01-07 18:44:22 +00:00
|
|
|
# Copyright (c) 2015-2016 The Khronos Group Inc.
|
2015-05-22 17:26:19 +00:00
|
|
|
#
|
2016-09-01 19:33:59 +00:00
|
|
|
# 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
|
2015-05-22 17:26:19 +00:00
|
|
|
#
|
2016-09-01 19:33:59 +00:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2015-05-22 17:26:19 +00:00
|
|
|
#
|
2016-09-01 19:33:59 +00:00
|
|
|
# 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.
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2016-03-14 12:41:32 +00:00
|
|
|
cmake_minimum_required(VERSION 2.8.12)
|
2017-10-10 12:23:42 +00:00
|
|
|
if (POLICY CMP0048)
|
|
|
|
cmake_policy(SET CMP0048 NEW)
|
|
|
|
endif()
|
2016-08-08 02:49:00 +00:00
|
|
|
if (POLICY CMP0054)
|
|
|
|
# Avoid dereferencing variables or interpret keywords that have been
|
|
|
|
# quoted or bracketed.
|
|
|
|
# https://cmake.org/cmake/help/v3.1/policy/CMP0054.html
|
|
|
|
cmake_policy(SET CMP0054 NEW)
|
|
|
|
endif()
|
2017-04-05 21:32:39 +00:00
|
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
2016-08-08 02:49:00 +00:00
|
|
|
|
2015-07-29 19:22:09 +00:00
|
|
|
project(spirv-tools)
|
2016-02-02 19:41:35 +00:00
|
|
|
enable_testing()
|
2015-11-18 14:22:10 +00:00
|
|
|
set(SPIRV_TOOLS "SPIRV-Tools")
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2017-07-04 13:11:40 +00:00
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
2016-04-03 22:21:35 +00:00
|
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
|
|
|
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)
|
2016-12-19 18:26:42 +00:00
|
|
|
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN")
|
|
|
|
add_definitions(-DSPIRV_WINDOWS)
|
2015-05-22 17:26:19 +00:00
|
|
|
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
|
|
|
|
add_definitions(-DSPIRV_MAC)
|
2016-04-18 14:59:47 +00:00
|
|
|
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
|
|
|
|
add_definitions(-DSPIRV_ANDROID)
|
2017-05-28 21:19:58 +00:00
|
|
|
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
|
|
|
|
add_definitions(-DSPIRV_FREEBSD)
|
2015-05-22 17:26:19 +00:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Your platform '${CMAKE_SYSTEM_NAME}' is not supported!")
|
|
|
|
endif()
|
|
|
|
|
2017-11-22 22:03:55 +00:00
|
|
|
|
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()
|
|
|
|
|
2017-07-04 13:11:40 +00:00
|
|
|
option(SKIP_SPIRV_TOOLS_INSTALL "Skip installation" ${SKIP_SPIRV_TOOLS_INSTALL})
|
|
|
|
if(NOT ${SKIP_SPIRV_TOOLS_INSTALL})
|
|
|
|
set(ENABLE_SPIRV_TOOLS_INSTALL ON)
|
|
|
|
endif()
|
2017-09-25 16:45:48 +00:00
|
|
|
|
|
|
|
option(SPIRV_BUILD_COMPRESSION "Build SPIR-V compressing codec" OFF)
|
|
|
|
|
2015-11-19 14:22:53 +00:00
|
|
|
option(SPIRV_WERROR "Enable error on warning" ON)
|
2016-08-08 02:49:00 +00:00
|
|
|
if(("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
|
2016-02-29 06:01:04 +00:00
|
|
|
set(COMPILER_IS_LIKE_GNU TRUE)
|
|
|
|
endif()
|
|
|
|
if(${COMPILER_IS_LIKE_GNU})
|
2017-02-28 19:34:18 +00:00
|
|
|
set(SPIRV_WARNINGS -Wall -Wextra -Wnon-virtual-dtor -Wno-missing-field-initializers)
|
2015-10-15 20:43:14 +00:00
|
|
|
|
2015-12-09 16:40:56 +00:00
|
|
|
option(SPIRV_WARN_EVERYTHING "Enable -Weverything" ${SPIRV_WARN_EVERYTHING})
|
2015-11-18 14:22:10 +00:00
|
|
|
if(${SPIRV_WARN_EVERYTHING})
|
2015-12-09 16:40:56 +00:00
|
|
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
|
|
set(SPIRV_WARNINGS ${SPIRV_WARNINGS}
|
|
|
|
-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded)
|
|
|
|
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
|
|
|
set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Wpedantic -pedantic-errors)
|
|
|
|
else()
|
|
|
|
message(STATUS "Unknown compiler ${CMAKE_CXX_COMPILER_ID}, "
|
|
|
|
"so SPIRV_WARN_EVERYTHING has no effect")
|
|
|
|
endif()
|
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()
|
2016-02-29 06:01:04 +00:00
|
|
|
elseif(MSVC)
|
2015-11-18 14:22:10 +00:00
|
|
|
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()
|
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/source)
|
|
|
|
|
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()
|
|
|
|
|
2016-09-08 15:43:48 +00:00
|
|
|
option(SPIRV_LOG_DEBUG "Enable excessive debug output" OFF)
|
|
|
|
if(${SPIRV_LOG_DEBUG})
|
|
|
|
add_definitions(-DSPIRV_LOG_DEBUG)
|
|
|
|
endif()
|
|
|
|
|
2017-08-16 20:42:50 +00:00
|
|
|
if (DEFINED SPIRV_TOOLS_EXTRA_DEFINITIONS)
|
|
|
|
add_definitions(${SPIRV_TOOLS_EXTRA_DEFINITIONS})
|
|
|
|
endif()
|
|
|
|
|
2016-01-26 23:04:55 +00:00
|
|
|
function(spvtools_default_compile_options TARGET)
|
2015-11-18 14:22:10 +00:00
|
|
|
target_compile_options(${TARGET} PRIVATE ${SPIRV_WARNINGS})
|
2016-02-29 06:01:04 +00:00
|
|
|
|
|
|
|
if (${COMPILER_IS_LIKE_GNU})
|
2015-11-18 14:22:10 +00:00
|
|
|
target_compile_options(${TARGET} PRIVATE
|
|
|
|
-std=c++11 -fno-exceptions -fno-rtti)
|
2016-01-11 15:54:20 +00:00
|
|
|
target_compile_options(${TARGET} PRIVATE
|
|
|
|
-Wall -Wextra -Wno-long-long -Wshadow -Wundef -Wconversion
|
|
|
|
-Wno-sign-conversion)
|
2015-11-18 14:22:10 +00:00
|
|
|
# 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")
|
|
|
|
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()
|
2016-01-11 15:54:20 +00:00
|
|
|
else()
|
|
|
|
target_compile_options(${TARGET} PRIVATE
|
|
|
|
-Wno-missing-field-initializers)
|
2015-11-18 14:22:10 +00:00
|
|
|
endif()
|
2015-05-22 17:26:19 +00:00
|
|
|
endif()
|
2016-02-29 06:01:04 +00:00
|
|
|
|
2017-04-03 17:41:20 +00:00
|
|
|
if (MSVC)
|
|
|
|
# Specify /EHs for exception handling. This makes using SPIRV-Tools as
|
|
|
|
# dependencies in other projects easier.
|
|
|
|
target_compile_options(${TARGET} PRIVATE /EHs)
|
|
|
|
endif()
|
|
|
|
|
2016-02-29 06:01:04 +00:00
|
|
|
# For MinGW cross compile, statically link to the C++ runtime.
|
|
|
|
# But it still depends on MSVCRT.dll.
|
|
|
|
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
|
|
|
if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
|
2016-08-05 17:46:45 +00:00
|
|
|
set_target_properties(${TARGET} PROPERTIES
|
|
|
|
LINK_FLAGS -static -static-libgcc -static-libstdc++)
|
2016-02-29 06:01:04 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
2015-11-18 14:22:10 +00:00
|
|
|
endfunction()
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2016-02-24 15:11:07 +00:00
|
|
|
if(NOT COMMAND find_host_package)
|
|
|
|
macro(find_host_package)
|
|
|
|
find_package(${ARGN})
|
|
|
|
endmacro()
|
|
|
|
endif()
|
|
|
|
if(NOT COMMAND find_host_program)
|
|
|
|
macro(find_host_program)
|
|
|
|
find_program(${ARGN})
|
|
|
|
endmacro()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_host_package(PythonInterp)
|
|
|
|
|
2017-11-22 22:03:55 +00:00
|
|
|
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
|
|
|
|
macro(spvtools_check_symbol_exports TARGET)
|
|
|
|
add_test(NAME spirv-tools-symbol-exports-${TARGET}
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE}
|
|
|
|
${spirv-tools_SOURCE_DIR}/utils/check_symbol_exports.py "$<TARGET_FILE:${TARGET}>")
|
|
|
|
endmacro()
|
|
|
|
else()
|
|
|
|
macro(spvtools_check_symbol_exports TARGET)
|
|
|
|
message("Skipping symbol exports test for ${TARGET}")
|
|
|
|
endmacro()
|
|
|
|
endif()
|
2016-02-22 21:07:19 +00:00
|
|
|
|
2015-12-09 16:40:56 +00:00
|
|
|
# Defaults to OFF if the user didn't set it.
|
2015-11-18 14:22:10 +00:00
|
|
|
option(SPIRV_SKIP_EXECUTABLES
|
2016-08-05 17:46:45 +00:00
|
|
|
"Skip building the executable and tests along with the library"
|
|
|
|
${SPIRV_SKIP_EXECUTABLES})
|
|
|
|
option(SPIRV_SKIP_TESTS
|
|
|
|
"Skip building tests along with the library" ${SPIRV_SKIP_TESTS})
|
|
|
|
if ("${SPIRV_SKIP_EXECUTABLES}")
|
|
|
|
set(SPIRV_SKIP_TESTS ON)
|
|
|
|
endif()
|
2015-09-04 19:13:57 +00:00
|
|
|
|
2017-11-09 16:24:41 +00:00
|
|
|
# Defaults to ON. The checks can be time consuming.
|
|
|
|
# Turn off if they take too long.
|
|
|
|
option(SPIRV_CHECK_CONTEXT "In a debug build, check if the IR context is in a valid state." ON)
|
|
|
|
if (${SPIRV_CHECK_CONTEXT})
|
|
|
|
add_definitions(-DSPIRV_CHECK_CONTEXT)
|
|
|
|
endif()
|
|
|
|
|
2016-03-17 02:43:31 +00:00
|
|
|
add_subdirectory(external)
|
2015-11-18 14:22:10 +00:00
|
|
|
|
2017-11-08 05:23:42 +00:00
|
|
|
if (TARGET effcee)
|
|
|
|
add_definitions(-DSPIRV_EFFCEE)
|
|
|
|
endif()
|
|
|
|
|
2016-03-17 02:43:31 +00:00
|
|
|
add_subdirectory(source)
|
|
|
|
add_subdirectory(tools)
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2016-03-17 02:43:31 +00:00
|
|
|
add_subdirectory(test)
|
2016-09-28 14:50:43 +00:00
|
|
|
add_subdirectory(examples)
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2017-07-04 13:11:40 +00:00
|
|
|
if(ENABLE_SPIRV_TOOLS_INSTALL)
|
|
|
|
install(
|
|
|
|
FILES
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/libspirv.h
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/libspirv.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/optimizer.hpp
|
2017-07-13 00:16:51 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/linker.hpp
|
2017-07-04 13:11:40 +00:00
|
|
|
DESTINATION
|
|
|
|
${CMAKE_INSTALL_INCLUDEDIR}/spirv-tools/)
|
|
|
|
endif(ENABLE_SPIRV_TOOLS_INSTALL)
|
2016-09-02 13:29:52 +00:00
|
|
|
|
2017-09-28 01:22:05 +00:00
|
|
|
if (NOT "${SPIRV_SKIP_TESTS}")
|
|
|
|
add_test(NAME spirv-tools-copyrights
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE} utils/check_copyright.py
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
2017-11-22 22:03:55 +00:00
|
|
|
endif()
|
2017-11-25 17:58:50 +00:00
|
|
|
|
|
|
|
set(SPIRV_LIBRARIES "-lSPIRV-Tools -lSPIRV-Tools-link -lSPIRV-Tools-opt")
|
|
|
|
if(SPIRV_BUILD_COMPRESSION)
|
|
|
|
set(SPIRV_LIBRARIES "${SPIRV_LIBRARIES} -lSPIRV-Tools-comp")
|
|
|
|
endif(SPIRV_BUILD_COMPRESSION)
|
|
|
|
|
|
|
|
# Build pkg-config file
|
|
|
|
# Use a first-class target so it's regenerated when relevant files are updated.
|
|
|
|
add_custom_target(spirv-tools-pkg-config ALL
|
|
|
|
COMMAND cmake -DCHANGES_FILE=${CMAKE_CURRENT_SOURCE_DIR}/CHANGES
|
|
|
|
-DTEMPLATE_FILE=${CMAKE_CURRENT_SOURCE_DIR}/cmake/SPIRV-Tools.pc.in
|
|
|
|
-DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools.pc
|
|
|
|
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
|
|
|
|
-DSPIRV_LIBRARIES=${SPIRV_LIBRARIES}
|
|
|
|
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/write_pkg_config.cmake
|
|
|
|
DEPENDS "CHANGES" "cmake/SPIRV-Tools.pc.in" "cmake/write_pkg_config.cmake")
|
|
|
|
|
|
|
|
# Install pkg-config file
|
|
|
|
if (ENABLE_SPIRV_TOOLS_INSTALL)
|
|
|
|
install(
|
|
|
|
FILES
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools.pc
|
|
|
|
DESTINATION
|
|
|
|
${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
|
|
|
endif()
|