1# increase to 3.1 once all major distributions 2# include a version of CMake >= 3.1 3cmake_minimum_required(VERSION 2.8.12) 4if (POLICY CMP0048) 5 cmake_policy(SET CMP0048 NEW) 6endif() 7set_property(GLOBAL PROPERTY USE_FOLDERS ON) 8 9# Enable compile commands database 10set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 11 12# Adhere to GNU filesystem layout conventions 13include(GNUInstallDirs) 14 15# Needed for CMAKE_DEPENDENT_OPTION macro 16include(CMakeDependentOption) 17 18option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) 19option(BUILD_EXTERNAL "Build external dependencies in /External" ON) 20 21set(LIB_TYPE STATIC) 22 23if(BUILD_SHARED_LIBS) 24 set(LIB_TYPE SHARED) 25endif() 26 27option(SKIP_GLSLANG_INSTALL "Skip installation" ${SKIP_GLSLANG_INSTALL}) 28if(NOT ${SKIP_GLSLANG_INSTALL}) 29 set(ENABLE_GLSLANG_INSTALL ON) 30endif() 31option(ENABLE_SPVREMAPPER "Enables building of SPVRemapper" ON) 32 33option(ENABLE_GLSLANG_BINARIES "Builds glslangValidator and spirv-remap" ON) 34 35option(ENABLE_GLSLANG_JS 36 "If using Emscripten, build glslang.js. Otherwise, builds a sample executable for binary-size testing." OFF) 37CMAKE_DEPENDENT_OPTION(ENABLE_GLSLANG_WEBMIN 38 "Reduces glslang to minimum needed for web use" 39 OFF "ENABLE_GLSLANG_JS" 40 OFF) 41CMAKE_DEPENDENT_OPTION(ENABLE_GLSLANG_WEBMIN_DEVEL 42 "For ENABLE_GLSLANG_WEBMIN builds, enables compilation error messages" 43 OFF "ENABLE_GLSLANG_WEBMIN" 44 OFF) 45CMAKE_DEPENDENT_OPTION(ENABLE_EMSCRIPTEN_SINGLE_FILE 46 "If using Emscripten, enables SINGLE_FILE build" 47 OFF "ENABLE_GLSLANG_JS AND EMSCRIPTEN" 48 OFF) 49CMAKE_DEPENDENT_OPTION(ENABLE_EMSCRIPTEN_ENVIRONMENT_NODE 50 "If using Emscripten, builds to run on Node instead of Web" 51 OFF "ENABLE_GLSLANG_JS AND EMSCRIPTEN" 52 OFF) 53 54CMAKE_DEPENDENT_OPTION(ENABLE_HLSL 55 "Enables HLSL input support" 56 ON "NOT ENABLE_GLSLANG_WEBMIN" 57 OFF) 58 59option(ENABLE_RTTI "Enables RTTI" OFF) 60option(ENABLE_OPT "Enables spirv-opt capability if present" ON) 61option(ENABLE_PCH "Enables Precompiled header" ON) 62option(ENABLE_CTEST "Enables testing" ON) 63 64if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32) 65 set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "..." FORCE) 66endif() 67 68option(USE_CCACHE "Use ccache" OFF) 69if(USE_CCACHE) 70 find_program(CCACHE_FOUND ccache) 71 if(CCACHE_FOUND) 72 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) 73 endif(CCACHE_FOUND) 74endif() 75 76# Precompiled header macro. Parameters are source file list and filename for pch cpp file. 77macro(glslang_pch SRCS PCHCPP) 78 if(MSVC AND CMAKE_GENERATOR MATCHES "^Visual Studio" AND NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND ENABLE_PCH) 79 set(PCH_NAME "$(IntDir)\\pch.pch") 80 # make source files use/depend on PCH_NAME 81 set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS "/Yupch.h /FIpch.h /Fp${PCH_NAME} /Zm300" OBJECT_DEPENDS "${PCH_NAME}") 82 # make PCHCPP file compile and generate PCH_NAME 83 set_source_files_properties(${PCHCPP} PROPERTIES COMPILE_FLAGS "/Ycpch.h /Fp${PCH_NAME} /Zm300" OBJECT_OUTPUTS "${PCH_NAME}") 84 list(APPEND ${SRCS} "${PCHCPP}") 85 endif() 86endmacro(glslang_pch) 87 88project(glslang) 89 90if(ENABLE_CTEST) 91 include(CTest) 92endif() 93 94if(ENABLE_HLSL) 95 add_definitions(-DENABLE_HLSL) 96endif(ENABLE_HLSL) 97 98if(ENABLE_GLSLANG_WEBMIN) 99 add_definitions(-DGLSLANG_WEB) 100 if(ENABLE_GLSLANG_WEBMIN_DEVEL) 101 add_definitions(-DGLSLANG_WEB_DEVEL) 102 endif(ENABLE_GLSLANG_WEBMIN_DEVEL) 103endif(ENABLE_GLSLANG_WEBMIN) 104 105if(WIN32) 106 set(CMAKE_DEBUG_POSTFIX "d") 107 if(MSVC) 108 include(ChooseMSVCCRT.cmake) 109 endif(MSVC) 110 add_definitions(-DGLSLANG_OSINCLUDE_WIN32) 111elseif(UNIX) 112 add_definitions(-DGLSLANG_OSINCLUDE_UNIX) 113else(WIN32) 114 message("unknown platform") 115endif(WIN32) 116 117if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") 118 add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs 119 -Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions) 120 add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over. 121 if(NOT ENABLE_RTTI) 122 add_compile_options(-fno-rtti) 123 endif() 124 if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9.0.0") 125 add_compile_options(-Werror=deprecated-copy) 126 endif() 127elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC) 128 add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs 129 -Wunused-parameter -Wunused-value -Wunused-variable) 130 add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over. 131 if(NOT ENABLE_RTTI) 132 add_compile_options(-fno-rtti) 133 endif() 134elseif(MSVC) 135 if(NOT ENABLE_RTTI) 136 add_compile_options(/GR-) # Disable RTTI 137 endif() 138endif() 139 140if(ENABLE_GLSLANG_JS) 141 if(MSVC) 142 add_compile_options(/Os /GR-) 143 else() 144 add_compile_options(-Os -fno-exceptions) 145 if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC) 146 add_compile_options(-Wno-unused-parameter) 147 add_compile_options(-Wno-unused-variable -Wno-unused-const-variable) 148 endif() 149 endif() 150endif(ENABLE_GLSLANG_JS) 151 152# Request C++11 153if(${CMAKE_VERSION} VERSION_LESS 3.1) 154 # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD 155 # remove this block once CMake >=3.1 has fixated in the ecosystem 156 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 157else() 158 set(CMAKE_CXX_STANDARD 11) 159 set(CMAKE_CXX_STANDARD_REQUIRED ON) 160 set(CMAKE_CXX_EXTENSIONS OFF) 161endif() 162 163function(glslang_set_link_args TARGET) 164 # For MinGW compiles, statically link against the GCC and C++ runtimes. 165 # This avoids the need to ship those runtimes as DLLs. 166 if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") 167 set_target_properties(${TARGET} PROPERTIES 168 LINK_FLAGS "-static -static-libgcc -static-libstdc++") 169 endif() 170endfunction(glslang_set_link_args) 171 172# CMake needs to find the right version of python, right from the beginning, 173# otherwise, it will find the wrong version and fail later 174if(BUILD_EXTERNAL AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/External) 175 find_package(PythonInterp 3 REQUIRED) 176 177 # We depend on these for later projects, so they should come first. 178 add_subdirectory(External) 179endif() 180 181if(NOT TARGET SPIRV-Tools-opt) 182 set(ENABLE_OPT OFF) 183endif() 184 185if(ENABLE_OPT) 186 message(STATUS "optimizer enabled") 187 add_definitions(-DENABLE_OPT=1) 188else() 189 if(ENABLE_HLSL) 190 message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL") 191 endif() 192 add_definitions(-DENABLE_OPT=0) 193endif() 194 195add_subdirectory(glslang) 196add_subdirectory(OGLCompilersDLL) 197if(ENABLE_GLSLANG_BINARIES) 198 add_subdirectory(StandAlone) 199endif() 200add_subdirectory(SPIRV) 201if(ENABLE_HLSL) 202 add_subdirectory(hlsl) 203endif(ENABLE_HLSL) 204if(ENABLE_CTEST) 205 add_subdirectory(gtests) 206endif() 207 208if(BUILD_TESTING) 209 # glslang-testsuite runs a bash script on Windows. 210 # Make sure to use '-o igncr' flag to ignore carriage returns (\r). 211 set(IGNORE_CR_FLAG "") 212 if(WIN32) 213 set(IGNORE_CR_FLAG -o igncr) 214 endif() 215 216 if (CMAKE_CONFIGURATION_TYPES) 217 set(RESULTS_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/localResults) 218 set(VALIDATOR_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/$<CONFIGURATION>/glslangValidator) 219 set(REMAP_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/$<CONFIGURATION>/spirv-remap) 220 else(CMAKE_CONFIGURATION_TYPES) 221 set(RESULTS_PATH ${CMAKE_CURRENT_BINARY_DIR}/localResults) 222 set(VALIDATOR_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/glslangValidator) 223 set(REMAP_PATH ${CMAKE_CURRENT_BINARY_DIR}/StandAlone/spirv-remap) 224 endif(CMAKE_CONFIGURATION_TYPES) 225 226 add_test(NAME glslang-testsuite 227 COMMAND bash ${IGNORE_CR_FLAG} runtests ${RESULTS_PATH} ${VALIDATOR_PATH} ${REMAP_PATH} 228 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Test/) 229endif(BUILD_TESTING) 230