f63e8fc328eea9dc94d2771ec77641d2b61c43ce
[platform/upstream/glslang.git] / glslang / CMakeLists.txt
1 # Copyright (C) 2020 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
34 if(WIN32)
35     add_subdirectory(OSDependent/Windows)
36 elseif(UNIX OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
37     add_subdirectory(OSDependent/Unix)
38 else()
39     message("unknown platform")
40 endif()
41
42 if(EMSCRIPTEN OR ENABLE_GLSLANG_JS)
43     # May be enabled on non-Emscripten builds for binary-size testing.
44     add_subdirectory(OSDependent/Web)
45 endif()
46
47 ################################################################################
48 # GenericCodeGen
49 ################################################################################
50 add_library(GenericCodeGen STATIC
51     GenericCodeGen/CodeGen.cpp
52     GenericCodeGen/Link.cpp)
53 set_property(TARGET GenericCodeGen PROPERTY POSITION_INDEPENDENT_CODE ON)
54 set_property(TARGET GenericCodeGen PROPERTY FOLDER glslang)
55
56 ################################################################################
57 # MachineIndependent
58 ################################################################################
59 set(MACHINEINDEPENDENT_SOURCES
60     MachineIndependent/glslang.m4
61     MachineIndependent/glslang.y
62     MachineIndependent/glslang_tab.cpp
63     MachineIndependent/attribute.cpp
64     MachineIndependent/Constant.cpp
65     MachineIndependent/iomapper.cpp
66     MachineIndependent/InfoSink.cpp
67     MachineIndependent/Initialize.cpp
68     MachineIndependent/IntermTraverse.cpp
69     MachineIndependent/Intermediate.cpp
70     MachineIndependent/ParseContextBase.cpp
71     MachineIndependent/ParseHelper.cpp
72     MachineIndependent/PoolAlloc.cpp
73     MachineIndependent/RemoveTree.cpp
74     MachineIndependent/Scan.cpp
75     MachineIndependent/ShaderLang.cpp
76     MachineIndependent/SpirvIntrinsics.cpp
77     MachineIndependent/SymbolTable.cpp
78     MachineIndependent/Versions.cpp
79     MachineIndependent/intermOut.cpp
80     MachineIndependent/limits.cpp
81     MachineIndependent/linkValidate.cpp
82     MachineIndependent/parseConst.cpp
83     MachineIndependent/reflection.cpp
84     MachineIndependent/preprocessor/Pp.cpp
85     MachineIndependent/preprocessor/PpAtom.cpp
86     MachineIndependent/preprocessor/PpContext.cpp
87     MachineIndependent/preprocessor/PpScanner.cpp
88     MachineIndependent/preprocessor/PpTokens.cpp
89     MachineIndependent/propagateNoContraction.cpp
90 )
91
92 set(MACHINEINDEPENDENT_HEADERS
93     MachineIndependent/attribute.h
94     MachineIndependent/glslang_tab.cpp.h
95     MachineIndependent/gl_types.h
96     MachineIndependent/Initialize.h
97     MachineIndependent/iomapper.h
98     MachineIndependent/LiveTraverser.h
99     MachineIndependent/localintermediate.h
100     MachineIndependent/ParseHelper.h
101     MachineIndependent/reflection.h
102     MachineIndependent/RemoveTree.h
103     MachineIndependent/Scan.h
104     MachineIndependent/ScanContext.h
105     MachineIndependent/SymbolTable.h
106     MachineIndependent/Versions.h
107     MachineIndependent/parseVersions.h
108     MachineIndependent/propagateNoContraction.h
109     MachineIndependent/preprocessor/PpContext.h
110     MachineIndependent/preprocessor/PpTokens.h
111 )
112
113 if(ENABLE_HLSL)
114     list(APPEND MACHINEINDEPENDENT_SOURCES
115         HLSL/hlslAttributes.cpp
116         HLSL/hlslParseHelper.cpp
117         HLSL/hlslScanContext.cpp
118         HLSL/hlslOpMap.cpp
119         HLSL/hlslTokenStream.cpp
120         HLSL/hlslGrammar.cpp
121         HLSL/hlslParseables.cpp)
122
123     list(APPEND MACHINEINDEPENDENT_HEADERS
124         HLSL/hlslAttributes.h
125         HLSL/hlslParseHelper.h
126         HLSL/hlslTokens.h
127         HLSL/hlslScanContext.h
128         HLSL/hlslOpMap.h
129         HLSL/hlslTokenStream.h
130         HLSL/hlslGrammar.h
131         HLSL/hlslParseables.h)
132 endif()
133
134 add_library(MachineIndependent STATIC ${MACHINEINDEPENDENT_SOURCES} ${MACHINEINDEPENDENT_HEADERS})
135 set_property(TARGET MachineIndependent PROPERTY POSITION_INDEPENDENT_CODE ON)
136 set_property(TARGET MachineIndependent PROPERTY FOLDER glslang)
137
138 glslang_add_build_info_dependency(MachineIndependent)
139
140 glslang_pch(MachineIndependent MachineIndependent/pch.h)
141
142 target_link_libraries(MachineIndependent PRIVATE OGLCompiler OSDependent GenericCodeGen)
143
144 ################################################################################
145 # glslang
146 ################################################################################
147 set(GLSLANG_SOURCES
148     CInterface/glslang_c_interface.cpp)
149
150 set(GLSLANG_HEADERS
151     Public/ShaderLang.h
152     Include/arrays.h
153     Include/BaseTypes.h
154     Include/Common.h
155     Include/ConstantUnion.h
156     Include/glslang_c_interface.h
157     Include/glslang_c_shader_types.h
158     Include/InfoSink.h
159     Include/InitializeGlobals.h
160     Include/intermediate.h
161     Include/PoolAlloc.h
162     Include/ResourceLimits.h
163     Include/ShHandle.h
164     Include/SpirvIntrinsics.h
165     Include/Types.h)
166
167 add_library(glslang ${LIB_TYPE} ${BISON_GLSLParser_OUTPUT_SOURCE} ${GLSLANG_SOURCES} ${GLSLANG_HEADERS})
168 set_target_properties(glslang PROPERTIES
169     FOLDER glslang
170     POSITION_INDEPENDENT_CODE ON
171     VERSION   "${GLSLANG_VERSION}"
172     SOVERSION "${GLSLANG_VERSION_MAJOR}")
173 target_link_libraries(glslang PRIVATE OGLCompiler OSDependent MachineIndependent)
174 target_include_directories(glslang PUBLIC
175     $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
176     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
177
178 glslang_add_build_info_dependency(glslang)
179
180 glslang_only_export_explicit_symbols(glslang)
181
182 if(WIN32 AND BUILD_SHARED_LIBS)
183     set_target_properties(glslang PROPERTIES PREFIX "")
184 endif()
185
186 ################################################################################
187 # source_groups
188 ################################################################################
189 if(WIN32)
190     source_group("Public" REGULAR_EXPRESSION "Public/*")
191     source_group("MachineIndependent" REGULAR_EXPRESSION "MachineIndependent/[^/]*")
192     source_group("Include" REGULAR_EXPRESSION "Include/[^/]*")
193     source_group("GenericCodeGen" REGULAR_EXPRESSION "GenericCodeGen/*")
194     source_group("MachineIndependent\\Preprocessor" REGULAR_EXPRESSION "MachineIndependent/preprocessor/*")
195     source_group("HLSL" REGULAR_EXPRESSION "HLSL/*")
196     source_group("CInterface" REGULAR_EXPRESSION "CInterface/*")
197 endif()
198
199 ################################################################################
200 # install
201 ################################################################################
202 if(ENABLE_GLSLANG_INSTALL)
203     install(TARGETS glslang EXPORT glslang-targets)
204     install(TARGETS MachineIndependent EXPORT glslang-targets)
205     install(TARGETS GenericCodeGen EXPORT glslang-targets)
206
207     # Backward compatibility
208     file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/glslangTargets.cmake" "
209         message(WARNING \"Using `glslangTargets.cmake` is deprecated: use `find_package(glslang)` to find glslang CMake targets.\")
210
211         if (NOT TARGET glslang::glslang)
212             include(\"\${CMAKE_CURRENT_LIST_DIR}/../../${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/glslang-targets.cmake\")
213         endif()
214
215         if(${BUILD_SHARED_LIBS})
216             add_library(glslang ALIAS glslang::glslang)
217         else()
218             add_library(glslang ALIAS glslang::glslang)
219             add_library(MachineIndependent ALIAS glslang::MachineIndependent)
220             add_library(GenericCodeGen ALIAS glslang::GenericCodeGen)
221         endif()
222     ")
223     install(FILES "${CMAKE_CURRENT_BINARY_DIR}/glslangTargets.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
224
225     set(ALL_HEADERS
226         ${GLSLANG_HEADERS}
227         ${MACHINEINDEPENDENT_HEADERS})
228
229     foreach(file ${ALL_HEADERS})
230         get_filename_component(dir ${file} DIRECTORY)
231         install(FILES ${file} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/glslang/${dir})
232     endforeach()
233
234     install(FILES ${GLSLANG_BUILD_INFO_H} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/glslang)
235
236 endif()