1 # increase to 3.1 once all major distributions
2 # include a version of CMake >= 3.1
3 cmake_minimum_required(VERSION 2.8.12)
5 cmake_policy(SET CMP0048 NEW)
7 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
9 # Enable compile commands database
10 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
12 # Adhere to GNU filesystem layout conventions
13 include(GNUInstallDirs)
15 # Needed for CMAKE_DEPENDENT_OPTION macro
16 include(CMakeDependentOption)
18 option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
19 option(BUILD_EXTERNAL "Build external dependencies in /External" ON)
27 option(SKIP_GLSLANG_INSTALL "Skip installation" ${SKIP_GLSLANG_INSTALL})
28 if(NOT ${SKIP_GLSLANG_INSTALL})
29 set(ENABLE_GLSLANG_INSTALL ON)
31 option(ENABLE_SPVREMAPPER "Enables building of SPVRemapper" ON)
33 option(ENABLE_GLSLANG_BINARIES "Builds glslangValidator and spirv-remap" ON)
35 option(ENABLE_GLSLANG_WEB "Reduces glslang to minimum needed for web use" OFF)
36 option(ENABLE_GLSLANG_WEB_DEVEL "For ENABLE_GLSLANG_WEB builds, enables compilation error messages" OFF)
37 option(ENABLE_EMSCRIPTEN_SINGLE_FILE "If using Emscripten, enables SINGLE_FILE build" OFF)
38 option(ENABLE_EMSCRIPTEN_ENVIRONMENT_NODE "If using Emscripten, builds to run on Node instead of Web" OFF)
40 CMAKE_DEPENDENT_OPTION(ENABLE_HLSL "Enables HLSL input support" ON "NOT ENABLE_GLSLANG_WEB" OFF)
42 option(ENABLE_OPT "Enables spirv-opt capability if present" ON)
43 option(ENABLE_PCH "Enables Precompiled header" ON)
44 option(ENABLE_CTEST "Enables testing" ON)
46 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
47 set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "..." FORCE)
50 option(USE_CCACHE "Use ccache" OFF)
52 find_program(CCACHE_FOUND ccache)
54 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
58 # Precompiled header macro. Parameters are source file list and filename for pch cpp file.
59 macro(glslang_pch SRCS PCHCPP)
60 if(MSVC AND CMAKE_GENERATOR MATCHES "^Visual Studio" AND ENABLE_PCH)
61 set(PCH_NAME "$(IntDir)\\pch.pch")
62 # make source files use/depend on PCH_NAME
63 set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS "/Yupch.h /FIpch.h /Fp${PCH_NAME} /Zm300" OBJECT_DEPENDS "${PCH_NAME}")
64 # make PCHCPP file compile and generate PCH_NAME
65 set_source_files_properties(${PCHCPP} PROPERTIES COMPILE_FLAGS "/Ycpch.h /Fp${PCH_NAME} /Zm300" OBJECT_OUTPUTS "${PCH_NAME}")
66 list(APPEND ${SRCS} "${PCHCPP}")
77 add_definitions(-DENABLE_HLSL)
80 if(ENABLE_GLSLANG_WEB)
81 add_definitions(-DGLSLANG_WEB)
82 if(ENABLE_GLSLANG_WEB_DEVEL)
83 add_definitions(-DGLSLANG_WEB_DEVEL)
84 endif(ENABLE_GLSLANG_WEB_DEVEL)
85 endif(ENABLE_GLSLANG_WEB)
88 set(CMAKE_DEBUG_POSTFIX "d")
90 include(ChooseMSVCCRT.cmake)
92 add_definitions(-DGLSLANG_OSINCLUDE_WIN32)
94 add_definitions(-DGLSLANG_OSINCLUDE_UNIX)
96 message("unknown platform")
99 if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
100 add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
101 -Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions)
102 add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
103 add_compile_options(-fno-rtti)
104 if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "9.0.0")
105 add_compile_options(-Werror=deprecated-copy)
107 elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
108 add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs
109 -Wunused-parameter -Wunused-value -Wunused-variable)
110 add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
111 add_compile_options(-fno-rtti)
112 elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC")
113 add_compile_options(/GR-) # Disable RTTI
117 add_compile_options(-Os -fno-exceptions)
118 add_compile_options("SHELL: -s WASM=1")
119 add_compile_options("SHELL: -s WASM_OBJECT_FILES=0")
120 add_link_options(-Os)
121 add_link_options("SHELL: -s FILESYSTEM=0")
122 add_link_options("SHELL: --llvm-lto 1")
123 add_link_options("SHELL: --closure 1")
124 add_link_options("SHELL: -s ALLOW_MEMORY_GROWTH=1")
126 if(ENABLE_EMSCRIPTEN_SINGLE_FILE)
127 add_link_options("SHELL: -s SINGLE_FILE=1")
128 endif(ENABLE_EMSCRIPTEN_SINGLE_FILE)
130 if(ENABLE_GLSLANG_WEB)
132 add_compile_options(/Os /GR-)
134 add_compile_options(-Os -fno-exceptions)
135 add_link_options(-Os)
137 endif(ENABLE_GLSLANG_WEB)
141 if(${CMAKE_VERSION} VERSION_LESS 3.1)
142 # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD
143 # remove this block once CMake >=3.1 has fixated in the ecosystem
144 add_compile_options(-std=c++11)
146 set(CMAKE_CXX_STANDARD 11)
147 set(CMAKE_CXX_STANDARD_REQUIRED ON)
148 set(CMAKE_CXX_EXTENSIONS OFF)
151 function(glslang_set_link_args TARGET)
152 # For MinGW compiles, statically link against the GCC and C++ runtimes.
153 # This avoids the need to ship those runtimes as DLLs.
154 if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
155 set_target_properties(${TARGET} PROPERTIES
156 LINK_FLAGS "-static -static-libgcc -static-libstdc++")
158 endfunction(glslang_set_link_args)
160 # CMake needs to find the right version of python, right from the beginning,
161 # otherwise, it will find the wrong version and fail later
162 if(BUILD_EXTERNAL AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/External)
163 find_package(PythonInterp 3 REQUIRED)
165 # We depend on these for later projects, so they should come first.
166 add_subdirectory(External)
169 if(NOT TARGET SPIRV-Tools-opt)
174 message(STATUS "optimizer enabled")
175 add_definitions(-DENABLE_OPT=1)
178 message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL")
180 add_definitions(-DENABLE_OPT=0)
183 add_subdirectory(glslang)
184 add_subdirectory(OGLCompilersDLL)
185 if(ENABLE_GLSLANG_BINARIES)
186 add_subdirectory(StandAlone)
188 add_subdirectory(SPIRV)
190 add_subdirectory(hlsl)
193 add_subdirectory(gtests)
197 # glslang-testsuite runs a bash script on Windows.
198 # Make sure to use '-o igncr' flag to ignore carriage returns (\r).
199 set(IGNORE_CR_FLAG "")
201 set(IGNORE_CR_FLAG -o igncr)
204 if (CMAKE_CONFIGURATION_TYPES)
205 set(RESULTS_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/localResults)
206 set(VALIDATOR_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/$<CONFIGURATION>/glslangValidator)
207 set(REMAP_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/$<CONFIGURATION>/spirv-remap)
208 else(CMAKE_CONFIGURATION_TYPES)
209 set(RESULTS_PATH ${CMAKE_CURRENT_BINARY_DIR}/localResults)
210 set(VALIDATOR_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/glslangValidator)
211 set(REMAP_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/spirv-remap)
212 endif(CMAKE_CONFIGURATION_TYPES)
214 add_test(NAME glslang-testsuite
215 COMMAND bash ${IGNORE_CR_FLAG} runtests ${RESULTS_PATH} ${VALIDATOR_PATH} ${REMAP_PATH}
216 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Test/)