1 # Copyright (C) 2020 The Khronos Group Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
9 # Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
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.
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.
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.
34 # increase to 3.1 once all major distributions
35 # include a version of CMake >= 3.1
36 cmake_minimum_required(VERSION 2.8.12)
38 cmake_policy(SET CMP0048 NEW)
40 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
42 # Enable compile commands database
43 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
45 # Adhere to GNU filesystem layout conventions
46 include(GNUInstallDirs)
48 # Needed for CMAKE_DEPENDENT_OPTION macro
49 include(CMakeDependentOption)
51 option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
52 option(BUILD_EXTERNAL "Build external dependencies in /External" ON)
60 option(SKIP_GLSLANG_INSTALL "Skip installation" ${SKIP_GLSLANG_INSTALL})
61 if(NOT ${SKIP_GLSLANG_INSTALL})
62 set(ENABLE_GLSLANG_INSTALL ON)
64 option(ENABLE_SPVREMAPPER "Enables building of SPVRemapper" ON)
66 option(ENABLE_GLSLANG_BINARIES "Builds glslangValidator and spirv-remap" ON)
68 option(ENABLE_GLSLANG_JS
69 "If using Emscripten, build glslang.js. Otherwise, builds a sample executable for binary-size testing." OFF)
70 CMAKE_DEPENDENT_OPTION(ENABLE_GLSLANG_WEBMIN
71 "Reduces glslang to minimum needed for web use"
72 OFF "ENABLE_GLSLANG_JS"
74 CMAKE_DEPENDENT_OPTION(ENABLE_GLSLANG_WEBMIN_DEVEL
75 "For ENABLE_GLSLANG_WEBMIN builds, enables compilation error messages"
76 OFF "ENABLE_GLSLANG_WEBMIN"
78 CMAKE_DEPENDENT_OPTION(ENABLE_EMSCRIPTEN_SINGLE_FILE
79 "If using Emscripten, enables SINGLE_FILE build"
80 OFF "ENABLE_GLSLANG_JS AND EMSCRIPTEN"
82 CMAKE_DEPENDENT_OPTION(ENABLE_EMSCRIPTEN_ENVIRONMENT_NODE
83 "If using Emscripten, builds to run on Node instead of Web"
84 OFF "ENABLE_GLSLANG_JS AND EMSCRIPTEN"
87 CMAKE_DEPENDENT_OPTION(ENABLE_HLSL
88 "Enables HLSL input support"
89 ON "NOT ENABLE_GLSLANG_WEBMIN"
92 option(ENABLE_RTTI "Enables RTTI" OFF)
93 option(ENABLE_EXCEPTIONS "Enables Exceptions" OFF)
94 option(ENABLE_OPT "Enables spirv-opt capability if present" ON)
95 option(ENABLE_PCH "Enables Precompiled header" ON)
96 option(ENABLE_CTEST "Enables testing" ON)
98 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
99 set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "..." FORCE)
102 option(USE_CCACHE "Use ccache" OFF)
104 find_program(CCACHE_FOUND ccache)
106 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
110 # Precompiled header macro. Parameters are source file list and filename for pch cpp file.
111 macro(glslang_pch SRCS PCHCPP)
112 if(MSVC AND CMAKE_GENERATOR MATCHES "^Visual Studio" AND NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND ENABLE_PCH)
113 set(PCH_NAME "$(IntDir)\\pch.pch")
114 # make source files use/depend on PCH_NAME
115 set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS "/Yupch.h /FIpch.h /Fp${PCH_NAME} /Zm300" OBJECT_DEPENDS "${PCH_NAME}")
116 # make PCHCPP file compile and generate PCH_NAME
117 set_source_files_properties(${PCHCPP} PROPERTIES COMPILE_FLAGS "/Ycpch.h /Fp${PCH_NAME} /Zm300" OBJECT_OUTPUTS "${PCH_NAME}")
118 list(APPEND ${SRCS} "${PCHCPP}")
120 endmacro(glslang_pch)
129 add_definitions(-DENABLE_HLSL)
132 if(ENABLE_GLSLANG_WEBMIN)
133 add_definitions(-DGLSLANG_WEB)
134 if(ENABLE_GLSLANG_WEBMIN_DEVEL)
135 add_definitions(-DGLSLANG_WEB_DEVEL)
136 endif(ENABLE_GLSLANG_WEBMIN_DEVEL)
137 endif(ENABLE_GLSLANG_WEBMIN)
140 set(CMAKE_DEBUG_POSTFIX "d")
142 include(ChooseMSVCCRT.cmake)
144 add_definitions(-DGLSLANG_OSINCLUDE_WIN32)
146 add_definitions(-DGLSLANG_OSINCLUDE_UNIX)
148 message("unknown platform")
151 if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
152 add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
153 -Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions)
154 add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
155 if(BUILD_SHARED_LIBS)
156 add_compile_options(-fPIC)
159 add_compile_options(-fno-rtti)
161 if(NOT ENABLE_EXCEPTIONS)
162 add_compile_options(-fno-exceptions)
164 if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9.0.0")
165 add_compile_options(-Werror=deprecated-copy)
168 # Error if there's symbols that are not found at link time.
169 add_link_options("-Wl,--no-undefined")
170 elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC)
171 add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs
172 -Wunused-parameter -Wunused-value -Wunused-variable)
173 add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
174 if(BUILD_SHARED_LIBS)
175 add_compile_options(-fPIC)
178 add_compile_options(-fno-rtti)
180 if(NOT ENABLE_EXCEPTIONS)
181 add_compile_options(-fno-exceptions)
184 # Error if there's symbols that are not found at link time.
185 add_link_options("-Wl,-undefined,error")
188 string(FIND "${CMAKE_CXX_FLAGS}" "/GR" MSVC_HAS_GR)
190 string(REGEX REPLACE /GR /GR- CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
192 add_compile_options(/GR-) # Disable RTTI
195 if(ENABLE_EXCEPTIONS)
196 add_compile_options(/EHsc) # Enable Exceptions
200 if(ENABLE_GLSLANG_JS)
202 add_compile_options(/Os /GR-)
204 add_compile_options(-Os -fno-rtti -fno-exceptions)
205 if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC)
206 add_compile_options(-Wno-unused-parameter)
207 add_compile_options(-Wno-unused-variable -Wno-unused-const-variable)
210 endif(ENABLE_GLSLANG_JS)
213 if(${CMAKE_VERSION} VERSION_LESS 3.1)
214 # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD
215 # remove this block once CMake >=3.1 has fixated in the ecosystem
216 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
218 set(CMAKE_CXX_STANDARD 11)
219 set(CMAKE_CXX_STANDARD_REQUIRED ON)
220 set(CMAKE_CXX_EXTENSIONS OFF)
223 function(glslang_set_link_args TARGET)
224 # For MinGW compiles, statically link against the GCC and C++ runtimes.
225 # This avoids the need to ship those runtimes as DLLs.
226 if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
227 set_target_properties(${TARGET} PROPERTIES
228 LINK_FLAGS "-static -static-libgcc -static-libstdc++")
230 endfunction(glslang_set_link_args)
232 # CMake needs to find the right version of python, right from the beginning,
233 # otherwise, it will find the wrong version and fail later
234 if(BUILD_EXTERNAL AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/External)
235 find_package(PythonInterp 3 REQUIRED)
237 # We depend on these for later projects, so they should come first.
238 add_subdirectory(External)
241 # glslang_only_export_explicit_symbols() makes the symbol visibility hidden by
242 # default for <target> when building shared libraries, and sets the
243 # GLSLANG_IS_SHARED_LIBRARY define, and GLSLANG_EXPORTING to 1 when specifically
245 function(glslang_only_export_explicit_symbols target)
246 if(BUILD_SHARED_LIBS)
247 target_compile_definitions(${target} PUBLIC "GLSLANG_IS_SHARED_LIBRARY=1")
249 target_compile_definitions(${target} PRIVATE "GLSLANG_EXPORTING=1")
251 target_compile_options(${target} PRIVATE "-fvisibility=hidden")
256 if(NOT TARGET SPIRV-Tools-opt)
261 message(STATUS "optimizer enabled")
262 add_definitions(-DENABLE_OPT=1)
265 message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL")
267 add_definitions(-DENABLE_OPT=0)
270 add_subdirectory(glslang)
271 add_subdirectory(OGLCompilersDLL)
272 if(ENABLE_GLSLANG_BINARIES)
273 add_subdirectory(StandAlone)
275 add_subdirectory(SPIRV)
277 add_subdirectory(hlsl)
280 add_subdirectory(gtests)
283 if(ENABLE_CTEST AND BUILD_TESTING)
284 # glslang-testsuite runs a bash script on Windows.
285 # Make sure to use '-o igncr' flag to ignore carriage returns (\r).
286 set(IGNORE_CR_FLAG "")
288 set(IGNORE_CR_FLAG -o igncr)
291 if (CMAKE_CONFIGURATION_TYPES)
292 set(RESULTS_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/localResults)
293 set(VALIDATOR_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/$<CONFIGURATION>/glslangValidator)
294 set(REMAP_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/$<CONFIGURATION>/spirv-remap)
295 else(CMAKE_CONFIGURATION_TYPES)
296 set(RESULTS_PATH ${CMAKE_CURRENT_BINARY_DIR}/localResults)
297 set(VALIDATOR_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/glslangValidator)
298 set(REMAP_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/spirv-remap)
299 endif(CMAKE_CONFIGURATION_TYPES)
301 add_test(NAME glslang-testsuite
302 COMMAND bash ${IGNORE_CR_FLAG} runtests ${RESULTS_PATH} ${VALIDATOR_PATH} ${REMAP_PATH}
303 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Test/)