• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    glslang-default-resource-limits)
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
76if(ENABLE_SPIRV)
77    if(ENABLE_SPVREMAPPER)
78        set(REMAPPER_SOURCES spirv-remap.cpp)
79        add_executable(spirv-remap ${REMAPPER_SOURCES})
80        set_property(TARGET spirv-remap PROPERTY FOLDER tools)
81        glslang_set_link_args(spirv-remap)
82        target_link_libraries(spirv-remap SPVRemapper ${LIBRARIES})
83    endif()
84endif()
85
86if(WIN32)
87    source_group("Source" FILES ${SOURCES})
88endif()
89
90# Create a symbolic link to glslang named glslangValidator for backwards compatibility
91set(legacy_glslang_name "glslangValidator${CMAKE_EXECUTABLE_SUFFIX}")
92set(link_method create_symlink)
93if(WIN32 OR MINGW)
94  set(link_method copy_if_different)
95endif()
96
97add_custom_command(
98    TARGET glslang-standalone POST_BUILD
99    COMMAND "${CMAKE_COMMAND}" -E "${link_method}" "\$<TARGET_FILE_NAME:glslang-standalone>" "${legacy_glslang_name}"
100    WORKING_DIRECTORY "\$<TARGET_FILE_DIR:glslang-standalone>"
101    VERBATIM
102)
103
104if(GLSLANG_ENABLE_INSTALL)
105    install(TARGETS glslang-standalone EXPORT glslang-targets)
106
107    # Create the same symlink at install time
108    install(CODE "\
109        message(STATUS \"Installing (${link_method}): \$<TARGET_FILE_NAME:glslang-standalone> -> \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}\")
110        execute_process(
111            COMMAND \"\${CMAKE_COMMAND}\" -E ${link_method} [=[\$<TARGET_FILE_NAME:glslang-standalone>]=] [=[${legacy_glslang_name}]=]
112            WORKING_DIRECTORY \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}\"
113        )
114    ")
115
116    if(ENABLE_SPIRV)
117        if(ENABLE_SPVREMAPPER)
118            install(TARGETS spirv-remap EXPORT glslang-targets)
119        endif()
120    endif()
121endif(GLSLANG_ENABLE_INSTALL)
122