Merge pull request #2327 from ben-clayton/fix-pch
[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)
37     add_subdirectory(OSDependent/Unix)
38 else(WIN32)
39     message("unknown platform")
40 endif(WIN32)
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(EMSCRIPTEN OR ENABLE_GLSLANG_JS)
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/SymbolTable.cpp
77     MachineIndependent/Versions.cpp
78     MachineIndependent/intermOut.cpp
79     MachineIndependent/limits.cpp
80     MachineIndependent/linkValidate.cpp
81     MachineIndependent/parseConst.cpp
82     MachineIndependent/reflection.cpp
83     MachineIndependent/preprocessor/Pp.cpp
84     MachineIndependent/preprocessor/PpAtom.cpp
85     MachineIndependent/preprocessor/PpContext.cpp
86     MachineIndependent/preprocessor/PpScanner.cpp
87     MachineIndependent/preprocessor/PpTokens.cpp
88     MachineIndependent/propagateNoContraction.cpp
89 )
90
91 set(MACHINEINDEPENDENT_HEADERS
92     MachineIndependent/attribute.h
93     MachineIndependent/glslang_tab.cpp.h
94     MachineIndependent/gl_types.h
95     MachineIndependent/Initialize.h
96     MachineIndependent/iomapper.h
97     MachineIndependent/LiveTraverser.h
98     MachineIndependent/localintermediate.h
99     MachineIndependent/ParseHelper.h
100     MachineIndependent/reflection.h
101     MachineIndependent/RemoveTree.h
102     MachineIndependent/Scan.h
103     MachineIndependent/ScanContext.h
104     MachineIndependent/SymbolTable.h
105     MachineIndependent/Versions.h
106     MachineIndependent/parseVersions.h
107     MachineIndependent/propagateNoContraction.h
108     MachineIndependent/preprocessor/PpContext.h
109     MachineIndependent/preprocessor/PpTokens.h
110 )
111
112 if(ENABLE_HLSL)
113     list(APPEND MACHINEINDEPENDENT_SOURCES
114         HLSL/hlslAttributes.cpp
115         HLSL/hlslParseHelper.cpp
116         HLSL/hlslScanContext.cpp
117         HLSL/hlslOpMap.cpp
118         HLSL/hlslTokenStream.cpp
119         HLSL/hlslGrammar.cpp
120         HLSL/hlslParseables.cpp)
121
122     list(APPEND MACHINEINDEPENDENT_HEADERS
123         HLSL/hlslAttributes.h
124         HLSL/hlslParseHelper.h
125         HLSL/hlslTokens.h
126         HLSL/hlslScanContext.h
127         HLSL/hlslOpMap.h
128         HLSL/hlslTokenStream.h
129         HLSL/hlslGrammar.h
130         HLSL/hlslParseables.h)
131 endif(ENABLE_HLSL)
132
133 add_library(MachineIndependent STATIC ${MACHINEINDEPENDENT_SOURCES} ${MACHINEINDEPENDENT_HEADERS})
134 set_property(TARGET MachineIndependent PROPERTY POSITION_INDEPENDENT_CODE ON)
135 set_property(TARGET MachineIndependent PROPERTY FOLDER glslang)
136 glslang_pch(MachineIndependent MachineIndependent/pch.h)
137
138 target_link_libraries(MachineIndependent PRIVATE OGLCompiler OSDependent GenericCodeGen)
139
140 ################################################################################
141 # glslang
142 ################################################################################
143 set(GLSLANG_SOURCES
144     CInterface/glslang_c_interface.cpp)
145
146 set(GLSLANG_HEADERS
147     Public/ShaderLang.h
148     Include/arrays.h
149     Include/BaseTypes.h
150     Include/Common.h
151     Include/ConstantUnion.h
152     Include/glslang_c_interface.h
153     Include/glslang_c_shader_types.h
154     Include/InfoSink.h
155     Include/InitializeGlobals.h
156     Include/intermediate.h
157     Include/PoolAlloc.h
158     Include/ResourceLimits.h
159     Include/revision.h
160     Include/ShHandle.h
161     Include/Types.h)
162
163 add_library(glslang ${LIB_TYPE} ${BISON_GLSLParser_OUTPUT_SOURCE} ${GLSLANG_SOURCES} ${GLSLANG_HEADERS})
164 set_property(TARGET glslang PROPERTY FOLDER glslang)
165 set_property(TARGET glslang PROPERTY POSITION_INDEPENDENT_CODE ON)
166 target_link_libraries(glslang PRIVATE OGLCompiler OSDependent MachineIndependent)
167 target_include_directories(glslang PUBLIC
168     $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
169     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
170
171 glslang_only_export_explicit_symbols(glslang)
172
173 if(WIN32 AND BUILD_SHARED_LIBS)
174     set_target_properties(glslang PROPERTIES PREFIX "")
175 endif()
176
177 ################################################################################
178 # source_groups
179 ################################################################################
180 if(WIN32)
181     source_group("Public" REGULAR_EXPRESSION "Public/*")
182     source_group("MachineIndependent" REGULAR_EXPRESSION "MachineIndependent/[^/]*")
183     source_group("Include" REGULAR_EXPRESSION "Include/[^/]*")
184     source_group("GenericCodeGen" REGULAR_EXPRESSION "GenericCodeGen/*")
185     source_group("MachineIndependent\\Preprocessor" REGULAR_EXPRESSION "MachineIndependent/preprocessor/*")
186     source_group("HLSL" REGULAR_EXPRESSION "HLSL/*")
187     source_group("CInterface" REGULAR_EXPRESSION "CInterface/*")
188 endif(WIN32)
189
190 ################################################################################
191 # install
192 ################################################################################
193 if(ENABLE_GLSLANG_INSTALL)
194     if(BUILD_SHARED_LIBS)
195         install(TARGETS glslang
196                 EXPORT  glslangTargets
197                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
198                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
199                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
200     else()
201         install(TARGETS glslang MachineIndependent GenericCodeGen
202                 EXPORT  glslangTargets
203                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
204     endif()
205
206     install(EXPORT glslangTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
207
208     set(ALL_HEADERS
209         ${GLSLANG_HEADERS}
210         ${MACHINEINDEPENDENT_HEADERS})
211
212     foreach(file ${ALL_HEADERS})
213         get_filename_component(dir ${file} DIRECTORY)
214         install(FILES ${file} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/glslang/${dir})
215     endforeach()
216 endif(ENABLE_GLSLANG_INSTALL)