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_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}) 51if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") 52 target_compile_options(glslang-standalone PRIVATE -Wconversion) 53elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC) 54 target_compile_options(glslang-standalone PRIVATE -Wshorten-64-to-32) 55endif() 56set_property(TARGET glslang-standalone PROPERTY FOLDER tools) 57set_property(TARGET glslang-standalone PROPERTY OUTPUT_NAME glslang) 58glslang_set_link_args(glslang-standalone) 59 60set(LIBRARIES 61 glslang 62 OSDependent 63 SPIRV 64 glslang-default-resource-limits) 65 66if(WIN32) 67 set(LIBRARIES ${LIBRARIES} psapi) 68elseif(UNIX) 69 if(NOT ANDROID AND NOT QNX) 70 set(LIBRARIES ${LIBRARIES} pthread) 71 endif() 72endif() 73 74target_link_libraries(glslang-standalone ${LIBRARIES}) 75target_include_directories(glslang-standalone PUBLIC 76 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../External>) 77 78if(ENABLE_SPVREMAPPER) 79 set(REMAPPER_SOURCES spirv-remap.cpp) 80 add_executable(spirv-remap ${REMAPPER_SOURCES}) 81 set_property(TARGET spirv-remap PROPERTY FOLDER tools) 82 glslang_set_link_args(spirv-remap) 83 target_link_libraries(spirv-remap SPVRemapper ${LIBRARIES}) 84endif() 85 86if(WIN32) 87 source_group("Source" FILES ${SOURCES}) 88endif() 89 90if(PROJECT_IS_TOP_LEVEL) 91 install(TARGETS glslang-standalone EXPORT glslang-targets) 92 93 # Backward compatibility 94 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/glslang-standaloneTargets.cmake" " 95 message(WARNING \"Using `glslang-standaloneTargets.cmake` is deprecated: use `find_package(glslang)` to find glslang CMake targets.\") 96 97 if (NOT TARGET glslang::glslang-standalone) 98 include(\"${CMAKE_INSTALL_FULL_LIBDIR}/cmake/${PROJECT_NAME}/glslang-targets.cmake\") 99 endif() 100 101 add_library(glslang-standalone ALIAS glslang::glslang-standalone) 102 ") 103 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/glslang-standaloneTargets.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake) 104 105 # Create a symbolic link to glslang named glslangValidator for backwards compatibility 106 set(legacy_glslang_name "glslangValidator${CMAKE_EXECUTABLE_SUFFIX}") 107 set(link_method create_symlink) 108 if (WIN32 OR MINGW) 109 set(link_method copy_if_different) 110 endif() 111 add_custom_command(TARGET glslang-standalone 112 POST_BUILD 113 COMMAND ${CMAKE_COMMAND} -E ${link_method} $<TARGET_FILE_NAME:glslang-standalone> ${legacy_glslang_name} 114 WORKING_DIRECTORY $<TARGET_FILE_DIR:glslang-standalone>) 115 116 # Create the same symlink at install time 117 install(CODE "execute_process( \ 118 COMMAND ${CMAKE_COMMAND} -E ${link_method} $<TARGET_FILE_NAME:glslang-standalone> ${legacy_glslang_name} \ 119 WORKING_DIRECTORY \$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})") 120 121 if(ENABLE_SPVREMAPPER) 122 install(TARGETS spirv-remap EXPORT glslang-targets) 123 124 # Backward compatibility 125 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/spirv-remapTargets.cmake" " 126 message(WARNING \"Using `spirv-remapTargets.cmake` is deprecated: use `find_package(glslang)` to find glslang CMake targets.\") 127 128 if (NOT TARGET glslang::spirv-remap) 129 include(\"${CMAKE_INSTALL_FULL_LIBDIR}/cmake/${PROJECT_NAME}/glslang-targets.cmake\") 130 endif() 131 132 add_library(spirv-remap ALIAS glslang::spirv-remap) 133 ") 134 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/spirv-remapTargets.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake) 135 endif() 136 137endif() 138