1617a3babSopenharmony_ci# Copyright (C) 2020-2023 The Khronos Group Inc.
2617a3babSopenharmony_ci#
3617a3babSopenharmony_ci# All rights reserved.
4617a3babSopenharmony_ci#
5617a3babSopenharmony_ci# Redistribution and use in source and binary forms, with or without
6617a3babSopenharmony_ci# modification, are permitted provided that the following conditions
7617a3babSopenharmony_ci# are met:
8617a3babSopenharmony_ci#
9617a3babSopenharmony_ci#    Redistributions of source code must retain the above copyright
10617a3babSopenharmony_ci#    notice, this list of conditions and the following disclaimer.
11617a3babSopenharmony_ci#
12617a3babSopenharmony_ci#    Redistributions in binary form must reproduce the above
13617a3babSopenharmony_ci#    copyright notice, this list of conditions and the following
14617a3babSopenharmony_ci#    disclaimer in the documentation and/or other materials provided
15617a3babSopenharmony_ci#    with the distribution.
16617a3babSopenharmony_ci#
17617a3babSopenharmony_ci#    Neither the name of The Khronos Group Inc. nor the names of its
18617a3babSopenharmony_ci#    contributors may be used to endorse or promote products derived
19617a3babSopenharmony_ci#    from this software without specific prior written permission.
20617a3babSopenharmony_ci#
21617a3babSopenharmony_ci# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22617a3babSopenharmony_ci# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23617a3babSopenharmony_ci# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24617a3babSopenharmony_ci# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25617a3babSopenharmony_ci# COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26617a3babSopenharmony_ci# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27617a3babSopenharmony_ci# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28617a3babSopenharmony_ci# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29617a3babSopenharmony_ci# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30617a3babSopenharmony_ci# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31617a3babSopenharmony_ci# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32617a3babSopenharmony_ci# POSSIBILITY OF SUCH DAMAGE.
33617a3babSopenharmony_ci
34617a3babSopenharmony_cifind_package(Python3 REQUIRED)
35617a3babSopenharmony_ci
36617a3babSopenharmony_ciset(GLSLANG_INTRINSIC_H          "${GLSLANG_GENERATED_INCLUDEDIR}/glslang/glsl_intrinsic_header.h")
37617a3babSopenharmony_ciset(GLSLANG_INTRINSIC_PY         "${CMAKE_CURRENT_SOURCE_DIR}/../gen_extension_headers.py")
38617a3babSopenharmony_ciset(GLSLANG_INTRINSIC_HEADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../glslang/ExtensionHeaders")
39617a3babSopenharmony_ci
40617a3babSopenharmony_ciadd_custom_command(
41617a3babSopenharmony_ci    OUTPUT  ${GLSLANG_INTRINSIC_H}
42617a3babSopenharmony_ci    COMMAND Python3::Interpreter "${GLSLANG_INTRINSIC_PY}"
43617a3babSopenharmony_ci            "-i" ${GLSLANG_INTRINSIC_HEADER_DIR}
44617a3babSopenharmony_ci            "-o" ${GLSLANG_INTRINSIC_H}
45617a3babSopenharmony_ci    DEPENDS ${GLSLANG_INTRINSIC_PY}
46617a3babSopenharmony_ci    COMMENT "Generating ${GLSLANG_INTRINSIC_H}")
47617a3babSopenharmony_ci
48617a3babSopenharmony_ciset(SOURCES StandAlone.cpp DirStackFileIncluder.h  ${GLSLANG_INTRINSIC_H})
49617a3babSopenharmony_ci
50617a3babSopenharmony_ciadd_executable(glslang-standalone ${SOURCES})
51617a3babSopenharmony_ciif(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
52617a3babSopenharmony_ci    target_compile_options(glslang-standalone PRIVATE -Wconversion)
53617a3babSopenharmony_cielseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC)
54617a3babSopenharmony_ci    target_compile_options(glslang-standalone PRIVATE -Wshorten-64-to-32)
55617a3babSopenharmony_ciendif()
56617a3babSopenharmony_ciset_property(TARGET glslang-standalone PROPERTY FOLDER tools)
57617a3babSopenharmony_ciset_property(TARGET glslang-standalone PROPERTY OUTPUT_NAME glslang)
58617a3babSopenharmony_ciglslang_set_link_args(glslang-standalone)
59617a3babSopenharmony_ci
60617a3babSopenharmony_ciset(LIBRARIES
61617a3babSopenharmony_ci    glslang
62617a3babSopenharmony_ci    OSDependent
63617a3babSopenharmony_ci    SPIRV
64617a3babSopenharmony_ci    glslang-default-resource-limits)
65617a3babSopenharmony_ci
66617a3babSopenharmony_ciif(WIN32)
67617a3babSopenharmony_ci    set(LIBRARIES ${LIBRARIES} psapi)
68617a3babSopenharmony_cielseif(UNIX)
69617a3babSopenharmony_ci    if(NOT ANDROID AND NOT QNX)
70617a3babSopenharmony_ci        set(LIBRARIES ${LIBRARIES} pthread)
71617a3babSopenharmony_ci    endif()
72617a3babSopenharmony_ciendif()
73617a3babSopenharmony_ci
74617a3babSopenharmony_citarget_link_libraries(glslang-standalone ${LIBRARIES})
75617a3babSopenharmony_citarget_include_directories(glslang-standalone PUBLIC
76617a3babSopenharmony_ci    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../External>)
77617a3babSopenharmony_ci
78617a3babSopenharmony_ciif(ENABLE_SPVREMAPPER)
79617a3babSopenharmony_ci    set(REMAPPER_SOURCES spirv-remap.cpp)
80617a3babSopenharmony_ci    add_executable(spirv-remap ${REMAPPER_SOURCES})
81617a3babSopenharmony_ci    set_property(TARGET spirv-remap PROPERTY FOLDER tools)
82617a3babSopenharmony_ci    glslang_set_link_args(spirv-remap)
83617a3babSopenharmony_ci    target_link_libraries(spirv-remap SPVRemapper ${LIBRARIES})
84617a3babSopenharmony_ciendif()
85617a3babSopenharmony_ci
86617a3babSopenharmony_ciif(WIN32)
87617a3babSopenharmony_ci    source_group("Source" FILES ${SOURCES})
88617a3babSopenharmony_ciendif()
89617a3babSopenharmony_ci
90617a3babSopenharmony_ciif(PROJECT_IS_TOP_LEVEL)
91617a3babSopenharmony_ci    install(TARGETS glslang-standalone EXPORT glslang-targets)
92617a3babSopenharmony_ci
93617a3babSopenharmony_ci    # Backward compatibility
94617a3babSopenharmony_ci    file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/glslang-standaloneTargets.cmake" "
95617a3babSopenharmony_ci        message(WARNING \"Using `glslang-standaloneTargets.cmake` is deprecated: use `find_package(glslang)` to find glslang CMake targets.\")
96617a3babSopenharmony_ci
97617a3babSopenharmony_ci        if (NOT TARGET glslang::glslang-standalone)
98617a3babSopenharmony_ci            include(\"${CMAKE_INSTALL_FULL_LIBDIR}/cmake/${PROJECT_NAME}/glslang-targets.cmake\")
99617a3babSopenharmony_ci        endif()
100617a3babSopenharmony_ci
101617a3babSopenharmony_ci        add_library(glslang-standalone ALIAS glslang::glslang-standalone)
102617a3babSopenharmony_ci    ")
103617a3babSopenharmony_ci    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/glslang-standaloneTargets.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
104617a3babSopenharmony_ci
105617a3babSopenharmony_ci    # Create a symbolic link to glslang named glslangValidator for backwards compatibility
106617a3babSopenharmony_ci    set(legacy_glslang_name "glslangValidator${CMAKE_EXECUTABLE_SUFFIX}")
107617a3babSopenharmony_ci    set(link_method create_symlink)
108617a3babSopenharmony_ci    if (WIN32 OR MINGW)
109617a3babSopenharmony_ci        set(link_method copy_if_different)
110617a3babSopenharmony_ci    endif()
111617a3babSopenharmony_ci    add_custom_command(TARGET glslang-standalone
112617a3babSopenharmony_ci                       POST_BUILD
113617a3babSopenharmony_ci                       COMMAND ${CMAKE_COMMAND} -E ${link_method} $<TARGET_FILE_NAME:glslang-standalone> ${legacy_glslang_name}
114617a3babSopenharmony_ci                       WORKING_DIRECTORY $<TARGET_FILE_DIR:glslang-standalone>)
115617a3babSopenharmony_ci
116617a3babSopenharmony_ci    # Create the same symlink at install time
117617a3babSopenharmony_ci    install(CODE "execute_process( \
118617a3babSopenharmony_ci                      COMMAND ${CMAKE_COMMAND} -E ${link_method} $<TARGET_FILE_NAME:glslang-standalone> ${legacy_glslang_name} \
119617a3babSopenharmony_ci                      WORKING_DIRECTORY \$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})")
120617a3babSopenharmony_ci
121617a3babSopenharmony_ci    if(ENABLE_SPVREMAPPER)
122617a3babSopenharmony_ci        install(TARGETS spirv-remap EXPORT glslang-targets)
123617a3babSopenharmony_ci
124617a3babSopenharmony_ci        # Backward compatibility
125617a3babSopenharmony_ci        file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/spirv-remapTargets.cmake" "
126617a3babSopenharmony_ci            message(WARNING \"Using `spirv-remapTargets.cmake` is deprecated: use `find_package(glslang)` to find glslang CMake targets.\")
127617a3babSopenharmony_ci
128617a3babSopenharmony_ci            if (NOT TARGET glslang::spirv-remap)
129617a3babSopenharmony_ci                include(\"${CMAKE_INSTALL_FULL_LIBDIR}/cmake/${PROJECT_NAME}/glslang-targets.cmake\")
130617a3babSopenharmony_ci            endif()
131617a3babSopenharmony_ci
132617a3babSopenharmony_ci            add_library(spirv-remap ALIAS glslang::spirv-remap)
133617a3babSopenharmony_ci        ")
134617a3babSopenharmony_ci        install(FILES "${CMAKE_CURRENT_BINARY_DIR}/spirv-remapTargets.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
135617a3babSopenharmony_ci    endif()
136617a3babSopenharmony_ci
137617a3babSopenharmony_ciendif()
138