Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CMake 5.88 KB | None | 0 0
  1. # Copyright (c) 2015-2016 The Khronos Group 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 2.8.12)
  16. if (POLICY CMP0054)
  17.   # Avoid dereferencing variables or interpret keywords that have been
  18.   # quoted or bracketed.
  19.   # https://cmake.org/cmake/help/v3.1/policy/CMP0054.html
  20.   cmake_policy(SET CMP0054 NEW)
  21. endif()
  22. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  23.  
  24. project(spirv-tools)
  25. enable_testing()
  26. set(SPIRV_TOOLS "SPIRV-Tools")
  27.  
  28. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  29.  
  30. if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
  31.   add_definitions(-DSPIRV_LINUX)
  32. elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
  33.   add_definitions(-DSPIRV_WINDOWS)
  34. elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN")
  35.   add_definitions(-DSPIRV_WINDOWS)
  36. elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
  37.   add_definitions(-DSPIRV_MAC)
  38. elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
  39.   add_definitions(-DSPIRV_ANDROID)
  40. elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
  41.   add_definitions(-DSPIRV_FREEBSD)
  42. else()
  43.   message(FATAL_ERROR "Your platform '${CMAKE_SYSTEM_NAME}' is not supported!")
  44. endif()
  45.  
  46. if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
  47.   message(STATUS "No build type selected, default to Debug")
  48.   set(CMAKE_BUILD_TYPE "Debug")
  49. endif()
  50.  
  51. option(SPIRV_WERROR "Enable error on warning" ON)
  52. if(("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
  53.   set(COMPILER_IS_LIKE_GNU TRUE)
  54. endif()
  55. if(${COMPILER_IS_LIKE_GNU})
  56.   set(SPIRV_WARNINGS -Wall -Wextra -Wnon-virtual-dtor -Wno-missing-field-initializers)
  57.  
  58.   option(SPIRV_WARN_EVERYTHING "Enable -Weverything" ${SPIRV_WARN_EVERYTHING})
  59.   if(${SPIRV_WARN_EVERYTHING})
  60.     if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  61.       set(SPIRV_WARNINGS ${SPIRV_WARNINGS}
  62.         -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded)
  63.     elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  64.       set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Wpedantic -pedantic-errors)
  65.     else()
  66.       message(STATUS "Unknown compiler ${CMAKE_CXX_COMPILER_ID}, "
  67.                      "so SPIRV_WARN_EVERYTHING has no effect")
  68.     endif()
  69.   endif()
  70.  
  71.   if(${SPIRV_WERROR})
  72.     set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Werror)
  73.   endif()
  74. elseif(MSVC)
  75.   set(SPIRV_WARNINGS -D_CRT_SECURE_NO_WARNINGS /wd4800)
  76.  
  77.   if(${SPIRV_WERROR})
  78.     set(SPIRV_WARNINGS ${SPIRV_WARNINGS} /WX)
  79.   endif()
  80. endif()
  81.  
  82. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/source)
  83.  
  84. option(SPIRV_COLOR_TERMINAL "Enable color terminal output" ON)
  85. if(${SPIRV_COLOR_TERMINAL})
  86.   add_definitions(-DSPIRV_COLOR_TERMINAL)
  87. endif()
  88.  
  89. option(SPIRV_LOG_DEBUG "Enable excessive debug output" OFF)
  90. if(${SPIRV_LOG_DEBUG})
  91.   add_definitions(-DSPIRV_LOG_DEBUG)
  92. endif()
  93.  
  94. function(spvtools_default_compile_options TARGET)
  95.   target_compile_options(${TARGET} PRIVATE ${SPIRV_WARNINGS})
  96.  
  97.   if (${COMPILER_IS_LIKE_GNU})
  98.     target_compile_options(${TARGET} PRIVATE
  99.       -std=c++11 -fno-exceptions -fno-rtti)
  100.     target_compile_options(${TARGET} PRIVATE
  101.       -Wall -Wextra -Wno-long-long -Wshadow -Wundef -Wconversion
  102.       -Wno-sign-conversion)
  103.     # For good call stacks in profiles, keep the frame pointers.
  104.     if(NOT "${SPIRV_PERF}" STREQUAL "")
  105.       target_compile_options(${TARGET} PRIVATE -fno-omit-frame-pointer)
  106.     endif()
  107.     if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  108.       set(SPIRV_USE_SANITIZER "" CACHE STRING
  109.         "Use the clang sanitizer [address|memory|thread|...]")
  110.       if(NOT "${SPIRV_USE_SANITIZER}" STREQUAL "")
  111.         target_compile_options(${TARGET} PRIVATE
  112.           -fsanitize=${SPIRV_USE_SANITIZER})
  113.       endif()
  114.     else()
  115.       target_compile_options(${TARGET} PRIVATE
  116.          -Wno-missing-field-initializers)
  117.     endif()
  118.   endif()
  119.  
  120.   if (MSVC)
  121.     # Specify /EHs for exception handling. This makes using SPIRV-Tools as
  122.     # dependencies in other projects easier.
  123.     target_compile_options(${TARGET} PRIVATE /EHs)
  124.   endif()
  125.  
  126.   # For MinGW cross compile, statically link to the C++ runtime.
  127.   # But it still depends on MSVCRT.dll.
  128.   if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
  129.     if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
  130.       set_target_properties(${TARGET} PROPERTIES
  131.         LINK_FLAGS -static -static-libgcc -static-libstdc++)
  132.     endif()
  133.   endif()
  134. endfunction()
  135.  
  136. if(NOT COMMAND find_host_package)
  137.   macro(find_host_package)
  138.     find_package(${ARGN})
  139.   endmacro()
  140. endif()
  141. if(NOT COMMAND find_host_program)
  142.   macro(find_host_program)
  143.     find_program(${ARGN})
  144.   endmacro()
  145. endif()
  146.  
  147. find_host_package(PythonInterp)
  148.  
  149.  
  150. # Defaults to OFF if the user didn't set it.
  151. option(SPIRV_SKIP_EXECUTABLES
  152.   "Skip building the executable and tests along with the library"
  153.   ${SPIRV_SKIP_EXECUTABLES})
  154. option(SPIRV_SKIP_TESTS
  155.   "Skip building tests along with the library" ${SPIRV_SKIP_TESTS})
  156. if ("${SPIRV_SKIP_EXECUTABLES}")
  157.   set(SPIRV_SKIP_TESTS ON)
  158. endif()
  159.  
  160. add_subdirectory(external)
  161.  
  162. add_subdirectory(source)
  163. add_subdirectory(tools)
  164.  
  165. add_subdirectory(test)
  166. add_subdirectory(examples)
  167.  
  168. install(
  169.   FILES
  170.     ${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/libspirv.h
  171.     ${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/libspirv.hpp
  172.     ${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/optimizer.hpp
  173.   DESTINATION
  174.     include/spirv-tools/)
  175.  
  176. add_test(NAME spirv-tools-copyrights
  177.          COMMAND ${PYTHON_EXECUTABLE} utils/check_copyright.py
  178.          WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement