| 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 |
project(glslang |
| 35 |
LANGUAGES CXX) |
| 36 |
|
| 37 |
# increase to 3.1 once all major distributions |
| 38 |
# include a version of CMake >= 3.1 |
| 39 |
cmake_minimum_required(VERSION 2.8.12) |
| 40 |
if (POLICY CMP0048) |
| 41 |
cmake_policy(SET CMP0048 NEW) |
| 42 |
endif() |
| 43 |
set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 44 |
|
| 45 |
# Enable compile commands database |
| 46 |
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 47 |
|
| 48 |
# Adhere to GNU filesystem layout conventions |
| 49 |
include(GNUInstallDirs) |
| 50 |
|
| 51 |
# Needed for CMAKE_DEPENDENT_OPTION macro |
| 52 |
include(CMakeDependentOption) |
| 53 |
|
| 54 |
option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) |
| 55 |
option(BUILD_EXTERNAL "Build external dependencies in /External" ON) |
| 56 |
|
| 57 |
set(LIB_TYPE STATIC) |
| 58 |
|
| 59 |
if(BUILD_SHARED_LIBS) |
| 60 |
set(LIB_TYPE SHARED) |
| 61 |
endif() |
| 62 |
|
| 63 |
if ("${CMAKE_BUILD_TYPE}" STREQUAL "") |
| 64 |
# This logic inside SPIRV-Tools, which can upset build target dependencies |
| 65 |
# if changed after targets are already defined. To prevent these issues, |
| 66 |
# ensure CMAKE_BUILD_TYPE is assigned early and at the glslang root scope. |
| 67 |
message(STATUS "No build type selected, default to Debug") |
| 68 |
set(CMAKE_BUILD_TYPE "Debug") |
| 69 |
endif() |
| 70 |
|
| 71 |
option(SKIP_GLSLANG_INSTALL "Skip installation" ${SKIP_GLSLANG_INSTALL}) |
| 72 |
if(NOT ${SKIP_GLSLANG_INSTALL}) |
| 73 |
set(ENABLE_GLSLANG_INSTALL ON) |
| 74 |
endif() |
| 75 |
option(ENABLE_SPVREMAPPER "Enables building of SPVRemapper" ON) |
| 76 |
|
| 77 |
option(ENABLE_GLSLANG_BINARIES "Builds glslangValidator and spirv-remap" ON) |
| 78 |
|
| 79 |
option(ENABLE_GLSLANG_JS |
| 80 |
"If using Emscripten, build glslang.js. Otherwise, builds a sample executable for binary-size testing." OFF) |
| 81 |
CMAKE_DEPENDENT_OPTION(ENABLE_GLSLANG_WEBMIN |
| 82 |
"Reduces glslang to minimum needed for web use" |
| 83 |
OFF "ENABLE_GLSLANG_JS" |
| 84 |
OFF) |
| 85 |
CMAKE_DEPENDENT_OPTION(ENABLE_GLSLANG_WEBMIN_DEVEL |
| 86 |
"For ENABLE_GLSLANG_WEBMIN builds, enables compilation error messages" |
| 87 |
OFF "ENABLE_GLSLANG_WEBMIN" |
| 88 |
OFF) |
| 89 |
CMAKE_DEPENDENT_OPTION(ENABLE_EMSCRIPTEN_SINGLE_FILE |
| 90 |
"If using Emscripten, enables SINGLE_FILE build" |
| 91 |
OFF "ENABLE_GLSLANG_JS AND EMSCRIPTEN" |
| 92 |
OFF) |
| 93 |
CMAKE_DEPENDENT_OPTION(ENABLE_EMSCRIPTEN_ENVIRONMENT_NODE |
| 94 |
"If using Emscripten, builds to run on Node instead of Web" |
| 95 |
OFF "ENABLE_GLSLANG_JS AND EMSCRIPTEN" |
| 96 |
OFF) |
| 97 |
|
| 98 |
CMAKE_DEPENDENT_OPTION(ENABLE_HLSL |
| 99 |
"Enables HLSL input support" |
| 100 |
ON "NOT ENABLE_GLSLANG_WEBMIN" |
| 101 |
OFF) |
| 102 |
|
| 103 |
option(ENABLE_RTTI "Enables RTTI" OFF) |
| 104 |
option(ENABLE_EXCEPTIONS "Enables Exceptions" OFF) |
| 105 |
option(ENABLE_OPT "Enables spirv-opt capability if present" ON) |
| 106 |
option(ENABLE_PCH "Enables Precompiled header" ON) |
| 107 |
option(ENABLE_CTEST "Enables testing" ON) |
| 108 |
|
| 109 |
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32) |
| 110 |
set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "..." FORCE) |
| 111 |
endif() |
| 112 |
|
| 113 |
option(USE_CCACHE "Use ccache" OFF) |
| 114 |
if(USE_CCACHE) |
| 115 |
find_program(CCACHE_FOUND ccache) |
| 116 |
if(CCACHE_FOUND) |
| 117 |
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) |
| 118 |
endif(CCACHE_FOUND) |
| 119 |
endif() |
| 120 |
|
| 121 |
if(ENABLE_CTEST) |
| 122 |
include(CTest) |
| 123 |
endif() |
| 124 |
|
| 125 |
if(ENABLE_HLSL) |
| 126 |
add_definitions(-DENABLE_HLSL) |
| 127 |
endif(ENABLE_HLSL) |
| 128 |
|
| 129 |
if(ENABLE_GLSLANG_WEBMIN) |
| 130 |
add_definitions(-DGLSLANG_WEB) |
| 131 |
if(ENABLE_GLSLANG_WEBMIN_DEVEL) |
| 132 |
add_definitions(-DGLSLANG_WEB_DEVEL) |
| 133 |
endif(ENABLE_GLSLANG_WEBMIN_DEVEL) |
| 134 |
endif(ENABLE_GLSLANG_WEBMIN) |
| 135 |
|
| 136 |
if(WIN32) |
| 137 |
set(CMAKE_DEBUG_POSTFIX "d") |
| 138 |
if(MSVC) |
| 139 |
include(ChooseMSVCCRT.cmake) |
| 140 |
endif(MSVC) |
| 141 |
add_definitions(-DGLSLANG_OSINCLUDE_WIN32) |
| 142 |
elseif(UNIX) |
| 143 |
add_definitions(-DGLSLANG_OSINCLUDE_UNIX) |
| 144 |
else(WIN32) |
| 145 |
message("unknown platform") |
| 146 |
endif(WIN32) |
| 147 |
|
| 148 |
if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") |
| 149 |
add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs |
| 150 |
-Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions) |
| 151 |
add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over. |
| 152 |
if(NOT ENABLE_RTTI) |
| 153 |
add_compile_options(-fno-rtti) |
| 154 |
endif() |
| 155 |
if(NOT ENABLE_EXCEPTIONS) |
| 156 |
add_compile_options(-fno-exceptions) |
| 157 |
endif() |
| 158 |
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9.0.0") |
| 159 |
add_compile_options(-Werror=deprecated-copy) |
| 160 |
endif() |
| 161 |
|
| 162 |
if(NOT CMAKE_VERSION VERSION_LESS "3.13") |
| 163 |
# Error if there's symbols that are not found at link time. |
| 164 |
# add_link_options() was added in CMake 3.13 - if using an earlier |
| 165 |
# version don't set this - it should be caught by presubmits anyway. |
| 166 |
add_link_options("-Wl,--no-undefined") |
| 167 |
endif() |
| 168 |
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC) |
| 169 |
add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs |
| 170 |
-Wunused-parameter -Wunused-value -Wunused-variable) |
| 171 |
add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over. |
| 172 |
if(NOT ENABLE_RTTI) |
| 173 |
add_compile_options(-fno-rtti) |
| 174 |
endif() |
| 175 |
if(NOT ENABLE_EXCEPTIONS) |
| 176 |
add_compile_options(-fno-exceptions) |
| 177 |
endif() |
| 178 |
|
| 179 |
if(NOT CMAKE_VERSION VERSION_LESS "3.13") |
| 180 |
# Error if there's symbols that are not found at link time. |
| 181 |
# add_link_options() was added in CMake 3.13 - if using an earlier |
| 182 |
# version don't set this - it should be caught by presubmits anyway. |
| 183 |
add_link_options("-Wl,-undefined,error") |
| 184 |
endif() |
| 185 |
elseif(MSVC) |
| 186 |
if(NOT ENABLE_RTTI) |
| 187 |
string(FIND "${CMAKE_CXX_FLAGS}" "/GR" MSVC_HAS_GR) |
| 188 |
if(MSVC_HAS_GR) |
| 189 |
string(REGEX REPLACE /GR /GR- CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) |
| 190 |
else() |
| 191 |
add_compile_options(/GR-) # Disable RTTI |
| 192 |
endif() |
| 193 |
endif() |
| 194 |
if(ENABLE_EXCEPTIONS) |
| 195 |
add_compile_options(/EHsc) # Enable Exceptions |
| 196 |
endif() |
| 197 |
endif() |
| 198 |
|
| 199 |
if(ENABLE_GLSLANG_JS) |
| 200 |
if(MSVC) |
| 201 |
add_compile_options(/Os /GR-) |
| 202 |
else() |
| 203 |
add_compile_options(-Os -fno-rtti -fno-exceptions) |
| 204 |
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC) |
| 205 |
add_compile_options(-Wno-unused-parameter) |
| 206 |
add_compile_options(-Wno-unused-variable -Wno-unused-const-variable) |
| 207 |
endif() |
| 208 |
endif() |
| 209 |
endif(ENABLE_GLSLANG_JS) |
| 210 |
|
| 211 |
# Request C++11 |
| 212 |
if(${CMAKE_VERSION} VERSION_LESS 3.1) |
| 213 |
# CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD |
| 214 |
# remove this block once CMake >=3.1 has fixated in the ecosystem |
| 215 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") |
| 216 |
else() |
| 217 |
set(CMAKE_CXX_STANDARD 11) |
| 218 |
set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 219 |
set(CMAKE_CXX_EXTENSIONS OFF) |
| 220 |
endif() |
| 221 |
|
| 222 |
function(glslang_set_link_args TARGET) |
| 223 |
# For MinGW compiles, statically link against the GCC and C++ runtimes. |
| 224 |
# This avoids the need to ship those runtimes as DLLs. |
| 225 |
if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") |
| 226 |
set_target_properties(${TARGET} PROPERTIES |
| 227 |
LINK_FLAGS "-static -static-libgcc -static-libstdc++") |
| 228 |
endif() |
| 229 |
endfunction(glslang_set_link_args) |
| 230 |
|
| 231 |
if(NOT COMMAND find_host_package) |
| 232 |
macro(find_host_package) |
| 233 |
find_package(${ARGN}) |
| 234 |
endmacro() |
| 235 |
endif() |
| 236 |
|
| 237 |
# CMake needs to find the right version of python, right from the beginning, |
| 238 |
# otherwise, it will find the wrong version and fail later |
| 239 |
find_host_package(PythonInterp 3 REQUIRED) |
| 240 |
|
| 241 |
# Root directory for build-time generated include files |
| 242 |
set(GLSLANG_GENERATED_INCLUDEDIR "${CMAKE_BINARY_DIR}/include") |
| 243 |
|
| 244 |
################################################################################ |
| 245 |
# Build version information generation |
| 246 |
################################################################################ |
| 247 |
set(GLSLANG_CHANGES_FILE "${CMAKE_CURRENT_SOURCE_DIR}/CHANGES.md") |
| 248 |
set(GLSLANG_BUILD_INFO_PY "${CMAKE_CURRENT_SOURCE_DIR}/build_info.py") |
| 249 |
set(GLSLANG_BUILD_INFO_H_TMPL "${CMAKE_CURRENT_SOURCE_DIR}/build_info.h.tmpl") |
| 250 |
set(GLSLANG_BUILD_INFO_H "${GLSLANG_GENERATED_INCLUDEDIR}/glslang/build_info.h") |
| 251 |
|
| 252 |
# Command to build the build_info.h file |
| 253 |
add_custom_command( |
| 254 |
OUTPUT ${GLSLANG_BUILD_INFO_H} |
| 255 |
COMMAND ${PYTHON_EXECUTABLE} "${GLSLANG_BUILD_INFO_PY}" |
| 256 |
${CMAKE_CURRENT_SOURCE_DIR} |
| 257 |
"-i" ${GLSLANG_BUILD_INFO_H_TMPL} |
| 258 |
"-o" ${GLSLANG_BUILD_INFO_H} |
| 259 |
DEPENDS ${GLSLANG_BUILD_INFO_PY} |
| 260 |
${GLSLANG_CHANGES_FILE} |
| 261 |
${GLSLANG_BUILD_INFO_H_TMPL} |
| 262 |
COMMENT "Generating ${GLSLANG_BUILD_INFO_H}") |
| 263 |
|
| 264 |
# Target to build the build_info.h file |
| 265 |
add_custom_target(glslang-build-info DEPENDS ${GLSLANG_BUILD_INFO_H}) |
| 266 |
|
| 267 |
# Populate the CMake GLSLANG_VERSION* variables with the build version |
| 268 |
# information. |
| 269 |
execute_process( |
| 270 |
COMMAND ${PYTHON_EXECUTABLE} "${GLSLANG_BUILD_INFO_PY}" |
| 271 |
${CMAKE_CURRENT_SOURCE_DIR} "<major>.<minor>.<patch><-flavor>;<major>;<minor>;<patch>;<flavor>" |
| 272 |
OUTPUT_VARIABLE "GLSLANG_VERSIONS" |
| 273 |
OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 274 |
list(GET "GLSLANG_VERSIONS" 0 "GLSLANG_VERSION") |
| 275 |
list(GET "GLSLANG_VERSIONS" 1 "GLSLANG_VERSION_MAJOR") |
| 276 |
list(GET "GLSLANG_VERSIONS" 2 "GLSLANG_VERSION_MINOR") |
| 277 |
list(GET "GLSLANG_VERSIONS" 3 "GLSLANG_VERSION_PATCH") |
| 278 |
list(GET "GLSLANG_VERSIONS" 4 "GLSLANG_VERSION_FLAVOR") |
| 279 |
configure_file(${GLSLANG_CHANGES_FILE} "${CMAKE_CURRENT_BINARY_DIR}/CHANGES.md") # Required to re-run cmake on version change |
| 280 |
|
| 281 |
# glslang_add_build_info_dependency() adds the glslang-build-info dependency and |
| 282 |
# generated include directories to target. |
| 283 |
function(glslang_add_build_info_dependency target) |
| 284 |
target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${GLSLANG_GENERATED_INCLUDEDIR}>) |
| 285 |
add_dependencies(${target} glslang-build-info) |
| 286 |
endfunction() |
| 287 |
|
| 288 |
# glslang_only_export_explicit_symbols() makes the symbol visibility hidden by |
| 289 |
# default for <target> when building shared libraries, and sets the |
| 290 |
# GLSLANG_IS_SHARED_LIBRARY define, and GLSLANG_EXPORTING to 1 when specifically |
| 291 |
# building <target>. |
| 292 |
function(glslang_only_export_explicit_symbols target) |
| 293 |
if(BUILD_SHARED_LIBS) |
| 294 |
target_compile_definitions(${target} PUBLIC "GLSLANG_IS_SHARED_LIBRARY=1") |
| 295 |
if(WIN32) |
| 296 |
target_compile_definitions(${target} PRIVATE "GLSLANG_EXPORTING=1") |
| 297 |
else() |
| 298 |
target_compile_options(${target} PRIVATE "-fvisibility=hidden") |
| 299 |
endif() |
| 300 |
endif() |
| 301 |
endfunction() |
| 302 |
|
| 303 |
# glslang_pch() adds precompiled header rules to <target> for the pre-compiled |
| 304 |
# header file <pch>. As target_precompile_headers() was added in CMake 3.16, |
| 305 |
# this is a no-op if called on earlier versions of CMake. |
| 306 |
if(NOT CMAKE_VERSION VERSION_LESS "3.16" AND ENABLE_PCH) |
| 307 |
function(glslang_pch target pch) |
| 308 |
target_precompile_headers(${target} PRIVATE ${pch}) |
| 309 |
endfunction() |
| 310 |
else() |
| 311 |
function(glslang_pch target pch) |
| 312 |
endfunction() |
| 313 |
if(ENABLE_PCH) |
| 314 |
message("Your CMake version is ${CMAKE_VERSION}. Update to at least 3.16 to enable precompiled headers to speed up incremental builds") |
| 315 |
endif() |
| 316 |
endif() |
| 317 |
|
| 318 |
if(BUILD_EXTERNAL AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/External) |
| 319 |
# We depend on these for later projects, so they should come first. |
| 320 |
add_subdirectory(External) |
| 321 |
endif() |
| 322 |
|
| 323 |
if(NOT TARGET SPIRV-Tools-opt) |
| 324 |
set(ENABLE_OPT OFF) |
| 325 |
endif() |
| 326 |
|
| 327 |
if(ENABLE_OPT) |
| 328 |
message(STATUS "optimizer enabled") |
| 329 |
add_definitions(-DENABLE_OPT=1) |
| 330 |
else() |
| 331 |
if(ENABLE_HLSL) |
| 332 |
message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL") |
| 333 |
endif() |
| 334 |
add_definitions(-DENABLE_OPT=0) |
| 335 |
endif() |
| 336 |
|
| 337 |
add_subdirectory(glslang) |
| 338 |
add_subdirectory(OGLCompilersDLL) |
| 339 |
if(ENABLE_GLSLANG_BINARIES) |
| 340 |
add_subdirectory(StandAlone) |
| 341 |
endif() |
| 342 |
add_subdirectory(SPIRV) |
| 343 |
if(ENABLE_HLSL) |
| 344 |
add_subdirectory(hlsl) |
| 345 |
endif(ENABLE_HLSL) |
| 346 |
if(ENABLE_CTEST) |
| 347 |
add_subdirectory(gtests) |
| 348 |
endif() |
| 349 |
|
| 350 |
if(ENABLE_CTEST AND BUILD_TESTING) |
| 351 |
# glslang-testsuite runs a bash script on Windows. |
| 352 |
# Make sure to use '-o igncr' flag to ignore carriage returns (\r). |
| 353 |
set(IGNORE_CR_FLAG "") |
| 354 |
if(WIN32) |
| 355 |
set(IGNORE_CR_FLAG -o igncr) |
| 356 |
endif() |
| 357 |
|
| 358 |
if (CMAKE_CONFIGURATION_TYPES) |
| 359 |
set(RESULTS_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/localResults) |
| 360 |
set(VALIDATOR_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/$<CONFIGURATION>/glslangValidator) |
| 361 |
set(REMAP_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/$<CONFIGURATION>/spirv-remap) |
| 362 |
else(CMAKE_CONFIGURATION_TYPES) |
| 363 |
set(RESULTS_PATH ${CMAKE_CURRENT_BINARY_DIR}/localResults) |
| 364 |
set(VALIDATOR_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/glslangValidator) |
| 365 |
set(REMAP_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/spirv-remap) |
| 366 |
endif(CMAKE_CONFIGURATION_TYPES) |
| 367 |
|
| 368 |
add_test(NAME glslang-testsuite |
| 369 |
COMMAND bash ${IGNORE_CR_FLAG} runtests ${RESULTS_PATH} ${VALIDATOR_PATH} ${REMAP_PATH} |
| 370 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Test/) |
| 371 |
endif() |