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# Adhere to GNU filesystem layout conventions 10include(GNUInstallDirs) 11 12option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) 13 14set(LIB_TYPE STATIC) 15 16if(BUILD_SHARED_LIBS) 17 set(LIB_TYPE SHARED) 18endif() 19 20option(SKIP_GLSLANG_INSTALL "Skip installation" ${SKIP_GLSLANG_INSTALL}) 21if(NOT ${SKIP_GLSLANG_INSTALL}) 22 set(ENABLE_GLSLANG_INSTALL ON) 23endif() 24option(ENABLE_SPVREMAPPER "Enables building of SPVRemapper" ON) 25 26option(ENABLE_AMD_EXTENSIONS "Enables support of AMD-specific extensions" ON) 27option(ENABLE_GLSLANG_BINARIES "Builds glslangValidator and spirv-remap" ON) 28 29option(ENABLE_NV_EXTENSIONS "Enables support of Nvidia-specific extensions" ON) 30 31option(ENABLE_HLSL "Enables HLSL input support" ON) 32 33option(ENABLE_OPT "Enables spirv-opt capability if present" ON) 34 35if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32) 36 set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "..." FORCE) 37endif() 38 39option(USE_CCACHE "Use ccache" OFF) 40if(USE_CCACHE) 41 find_program(CCACHE_FOUND ccache) 42 if(CCACHE_FOUND) 43 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) 44 endif(CCACHE_FOUND) 45endif() 46 47# Precompiled header macro. Parameters are source file list and filename for pch cpp file. 48macro(glslang_pch SRCS PCHCPP) 49 if(MSVC AND CMAKE_GENERATOR MATCHES "^Visual Studio") 50 set(PCH_NAME "$(IntDir)\\pch.pch") 51 # make source files use/depend on PCH_NAME 52 set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS "/Yupch.h /FIpch.h /Fp${PCH_NAME} /Zm300" OBJECT_DEPENDS "${PCH_NAME}") 53 # make PCHCPP file compile and generate PCH_NAME 54 set_source_files_properties(${PCHCPP} PROPERTIES COMPILE_FLAGS "/Ycpch.h /Fp${PCH_NAME} /Zm300" OBJECT_OUTPUTS "${PCH_NAME}") 55 list(APPEND ${SRCS} "${PCHCPP}") 56 endif() 57endmacro(glslang_pch) 58 59project(glslang) 60# make testing optional 61include(CTest) 62 63if(ENABLE_AMD_EXTENSIONS) 64 add_definitions(-DAMD_EXTENSIONS) 65endif(ENABLE_AMD_EXTENSIONS) 66 67if(ENABLE_NV_EXTENSIONS) 68 add_definitions(-DNV_EXTENSIONS) 69endif(ENABLE_NV_EXTENSIONS) 70 71if(ENABLE_HLSL) 72 add_definitions(-DENABLE_HLSL) 73endif(ENABLE_HLSL) 74 75if(WIN32) 76 set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Adds a postfix for debug-built libraries.") 77 if(MSVC) 78 include(ChooseMSVCCRT.cmake) 79 endif(MSVC) 80 add_definitions(-DGLSLANG_OSINCLUDE_WIN32) 81elseif(UNIX) 82 add_definitions(-DGLSLANG_OSINCLUDE_UNIX) 83else(WIN32) 84 message("unknown platform") 85endif(WIN32) 86 87if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") 88 add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs 89 -Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions) 90 add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over. 91elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") 92 add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs 93 -Wunused-parameter -Wunused-value -Wunused-variable) 94 add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over. 95endif() 96 97# Request C++11 98if(${CMAKE_VERSION} VERSION_LESS 3.1) 99 # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD 100 # remove this block once CMake >=3.1 has fixated in the ecosystem 101 add_compile_options(-std=c++11) 102else() 103 set(CMAKE_CXX_STANDARD 11) 104 set(CMAKE_CXX_STANDARD_REQUIRED ON) 105 set(CMAKE_CXX_EXTENSIONS OFF) 106endif() 107 108function(glslang_set_link_args TARGET) 109 # For MinGW compiles, statically link against the GCC and C++ runtimes. 110 # This avoids the need to ship those runtimes as DLLs. 111 if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") 112 set_target_properties(${TARGET} PROPERTIES 113 LINK_FLAGS "-static -static-libgcc -static-libstdc++") 114 endif() 115endfunction(glslang_set_link_args) 116 117# We depend on these for later projects, so they should come first. 118add_subdirectory(External) 119 120if(NOT TARGET SPIRV-Tools-opt) 121 set(ENABLE_OPT OFF) 122endif() 123 124if(ENABLE_OPT) 125 message(STATUS "optimizer enabled") 126 add_definitions(-DENABLE_OPT=1) 127else() 128 if(ENABLE_HLSL) 129 message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL") 130 endif() 131 add_definitions(-DENABLE_OPT=0) 132endif() 133 134add_subdirectory(glslang) 135add_subdirectory(OGLCompilersDLL) 136if(ENABLE_GLSLANG_BINARIES) 137 add_subdirectory(StandAlone) 138endif() 139add_subdirectory(SPIRV) 140if(ENABLE_HLSL) 141 add_subdirectory(hlsl) 142endif(ENABLE_HLSL) 143add_subdirectory(gtests) 144