1# Copyright (C) 2020-2023 The Khronos Group Inc. 2# 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# 9# Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 12# Redistributions in binary form must reproduce the above 13# copyright notice, this list of conditions and the following 14# disclaimer in the documentation and/or other materials provided 15# with the distribution. 16# 17# Neither the name of The Khronos Group Inc. nor the names of its 18# contributors may be used to endorse or promote products derived 19# from this software without specific prior written permission. 20# 21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25# COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32# POSSIBILITY OF SUCH DAMAGE. 33 34find_host_package(Python3 REQUIRED) 35 36set(GLSLANG_INTRINSIC_H "${GLSLANG_GENERATED_INCLUDEDIR}/glslang/glsl_intrinsic_header.h") 37set(GLSLANG_INTRINSIC_PY "${CMAKE_CURRENT_SOURCE_DIR}/../gen_extension_headers.py") 38set(GLSLANG_INTRINSIC_HEADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../glslang/ExtensionHeaders") 39 40add_custom_command( 41 OUTPUT ${GLSLANG_INTRINSIC_H} 42 COMMAND Python3::Interpreter "${GLSLANG_INTRINSIC_PY}" 43 "-i" ${GLSLANG_INTRINSIC_HEADER_DIR} 44 "-o" ${GLSLANG_INTRINSIC_H} 45 DEPENDS ${GLSLANG_INTRINSIC_PY} 46 COMMENT "Generating ${GLSLANG_INTRINSIC_H}") 47 48set(SOURCES StandAlone.cpp DirStackFileIncluder.h ${GLSLANG_INTRINSIC_H}) 49 50add_executable(glslang-standalone ${SOURCES}) 51set_property(TARGET glslang-standalone PROPERTY FOLDER tools) 52set_property(TARGET glslang-standalone PROPERTY OUTPUT_NAME glslang) 53glslang_set_link_args(glslang-standalone) 54 55set(LIBRARIES 56 glslang 57 SPIRV 58 glslang-default-resource-limits) 59 60if(ENABLE_SPVREMAPPER) 61 set(LIBRARIES ${LIBRARIES} SPVRemapper) 62endif() 63 64if(WIN32) 65 set(LIBRARIES ${LIBRARIES} psapi) 66elseif(UNIX) 67 if(NOT ANDROID AND NOT QNX) 68 set(LIBRARIES ${LIBRARIES} pthread) 69 endif() 70endif() 71 72target_link_libraries(glslang-standalone ${LIBRARIES}) 73target_include_directories(glslang-standalone PUBLIC 74 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../External> 75 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/External>) 76 77if(ENABLE_OPT) 78 target_include_directories(glslang-standalone 79 PRIVATE ${spirv-tools_SOURCE_DIR}/include 80 ) 81endif() 82 83if(ENABLE_SPVREMAPPER) 84 set(REMAPPER_SOURCES spirv-remap.cpp) 85 add_executable(spirv-remap ${REMAPPER_SOURCES}) 86 set_property(TARGET spirv-remap PROPERTY FOLDER tools) 87 glslang_set_link_args(spirv-remap) 88 target_link_libraries(spirv-remap ${LIBRARIES}) 89endif() 90 91if(WIN32) 92 source_group("Source" FILES ${SOURCES}) 93endif() 94 95if(ENABLE_GLSLANG_INSTALL) 96 install(TARGETS glslang-standalone EXPORT glslang-targets) 97 98 # Backward compatibility 99 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/glslang-standaloneTargets.cmake" " 100 message(WARNING \"Using `glslang-standaloneTargets.cmake` is deprecated: use `find_package(glslang)` to find glslang CMake targets.\") 101 102 if (NOT TARGET glslang::glslang-standalone) 103 include(\"${CMAKE_INSTALL_FULL_LIBDIR}/cmake/${PROJECT_NAME}/glslang-targets.cmake\") 104 endif() 105 106 add_library(glslang-standalone ALIAS glslang::glslang-standalone) 107 ") 108 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/glslang-standaloneTargets.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake) 109 110 # Create a symbolic link to glslang named glslangValidator for backwards compatibility 111 set(legacy_glslang_name "glslangValidator${CMAKE_EXECUTABLE_SUFFIX}") 112 set(link_method create_symlink) 113 if (WIN32 OR MINGW) 114 set(link_method copy_if_different) 115 endif() 116 add_custom_command(TARGET glslang-standalone 117 POST_BUILD 118 COMMAND ${CMAKE_COMMAND} -E ${link_method} $<TARGET_FILE_NAME:glslang-standalone> ${legacy_glslang_name} 119 WORKING_DIRECTORY $<TARGET_FILE_DIR:glslang-standalone>) 120 121 # Create the same symlink at install time 122 install(CODE "execute_process( \ 123 COMMAND ${CMAKE_COMMAND} -E ${link_method} $<TARGET_FILE_NAME:glslang-standalone> ${legacy_glslang_name} \ 124 WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})") 125 126 if(ENABLE_SPVREMAPPER) 127 install(TARGETS spirv-remap EXPORT glslang-targets) 128 129 # Backward compatibility 130 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/spirv-remapTargets.cmake" " 131 message(WARNING \"Using `spirv-remapTargets.cmake` is deprecated: use `find_package(glslang)` to find glslang CMake targets.\") 132 133 if (NOT TARGET glslang::spirv-remap) 134 include(\"${CMAKE_INSTALL_FULL_LIBDIR}/cmake/${PROJECT_NAME}/glslang-targets.cmake\") 135 endif() 136 137 add_library(spirv-remap ALIAS glslang::spirv-remap) 138 ") 139 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/spirv-remapTargets.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake) 140 endif() 141 142endif() 143