David Seifert | 22afc38 | 2017-04-29 10:57:36 +0200 | [diff] [blame] | 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) |
Tim Diekmann | aab0001 | 2017-10-10 16:26:31 +0200 | [diff] [blame] | 4 | if (POLICY CMP0048) |
| 5 | cmake_policy(SET CMP0048 NEW) |
| 6 | endif() |
Andrew Woloszyn | db0eaf9 | 2016-05-05 14:45:53 -0400 | [diff] [blame] | 7 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
John Kessenich | d49d524 | 2015-06-26 16:29:10 -0600 | [diff] [blame] | 8 | |
David Seifert | 22afc38 | 2017-04-29 10:57:36 +0200 | [diff] [blame] | 9 | # Adhere to GNU filesystem layout conventions |
| 10 | include(GNUInstallDirs) |
| 11 | |
Matthew Albrecht | 6c5f649 | 2018-03-30 09:32:03 -0500 | [diff] [blame] | 12 | option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) |
| 13 | |
| 14 | set(LIB_TYPE STATIC) |
| 15 | |
| 16 | if(BUILD_SHARED_LIBS) |
| 17 | set(LIB_TYPE SHARED) |
| 18 | endif() |
| 19 | |
d3x0r | f8f494f | 2017-07-04 05:54:57 -0700 | [diff] [blame] | 20 | option(SKIP_GLSLANG_INSTALL "Skip installation" ${SKIP_GLSLANG_INSTALL}) |
| 21 | if(NOT ${SKIP_GLSLANG_INSTALL}) |
| 22 | set(ENABLE_GLSLANG_INSTALL ON) |
| 23 | endif() |
Matthew Albrecht | 857f25c | 2018-07-07 16:53:06 -0500 | [diff] [blame] | 24 | option(ENABLE_SPVREMAPPER "Enables building of SPVRemapper" ON) |
d3x0r | f8f494f | 2017-07-04 05:54:57 -0700 | [diff] [blame] | 25 | |
Dominik Witczak | daff1a2 | 2016-09-27 09:51:34 +0200 | [diff] [blame] | 26 | option(ENABLE_AMD_EXTENSIONS "Enables support of AMD-specific extensions" ON) |
Henrik Rydgård | 868746a | 2016-12-20 01:56:00 +0100 | [diff] [blame] | 27 | option(ENABLE_GLSLANG_BINARIES "Builds glslangValidator and spirv-remap" ON) |
Rex Xu | 9d93a23 | 2016-05-05 12:30:44 +0800 | [diff] [blame] | 28 | |
chaoc | 0ad6a4e | 2016-12-19 16:29:34 -0800 | [diff] [blame] | 29 | option(ENABLE_NV_EXTENSIONS "Enables support of Nvidia-specific extensions" ON) |
| 30 | |
Alex Szpakowski | ff21a25 | 2017-01-09 18:10:14 -0400 | [diff] [blame] | 31 | option(ENABLE_HLSL "Enables HLSL input support" ON) |
Alex Szpakowski | 84eabf7 | 2017-01-08 21:20:25 -0400 | [diff] [blame] | 32 | |
GregF | fd34f0e | 2017-09-21 16:50:39 -0600 | [diff] [blame] | 33 | option(ENABLE_OPT "Enables spirv-opt capability if present" ON) |
| 34 | |
David Seifert | 22afc38 | 2017-04-29 10:57:36 +0200 | [diff] [blame] | 35 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32) |
| 36 | set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "..." FORCE) |
| 37 | endif() |
John Kessenich | cfc69d9 | 2017-04-28 22:04:24 -0600 | [diff] [blame] | 38 | |
Karl Schultz | 23770b9 | 2018-07-06 12:12:09 -0600 | [diff] [blame] | 39 | option(USE_CCACHE "Use ccache" OFF) |
| 40 | if(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) |
| 45 | endif() |
| 46 | |
Jeff Bolz | 22d0b7c | 2018-10-31 15:38:08 -0500 | [diff] [blame] | 47 | # Precompiled header macro. Parameters are source file list and filename for pch cpp file. |
Jeff Bolz | 02ed310 | 2018-11-07 09:35:20 -0600 | [diff] [blame] | 48 | macro(glslang_pch SRCS PCHCPP) |
Jeff Bolz | 0a93cfb | 2018-12-11 20:53:59 -0600 | [diff] [blame] | 49 | if(MSVC AND CMAKE_GENERATOR MATCHES "^Visual Studio") |
| 50 | set(PCH_NAME "$(IntDir)\\pch.pch") |
Jeff Bolz | 22d0b7c | 2018-10-31 15:38:08 -0500 | [diff] [blame] | 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() |
Jeff Bolz | 02ed310 | 2018-11-07 09:35:20 -0600 | [diff] [blame] | 57 | endmacro(glslang_pch) |
Jeff Bolz | 22d0b7c | 2018-10-31 15:38:08 -0500 | [diff] [blame] | 58 | |
John Kessenich | cfc69d9 | 2017-04-28 22:04:24 -0600 | [diff] [blame] | 59 | project(glslang) |
David Seifert | 22afc38 | 2017-04-29 10:57:36 +0200 | [diff] [blame] | 60 | # make testing optional |
| 61 | include(CTest) |
David Seifert | 8f82426 | 2017-04-28 22:46:52 +0200 | [diff] [blame] | 62 | |
Rex Xu | 9d93a23 | 2016-05-05 12:30:44 +0800 | [diff] [blame] | 63 | if(ENABLE_AMD_EXTENSIONS) |
| 64 | add_definitions(-DAMD_EXTENSIONS) |
| 65 | endif(ENABLE_AMD_EXTENSIONS) |
| 66 | |
chaoc | 0ad6a4e | 2016-12-19 16:29:34 -0800 | [diff] [blame] | 67 | if(ENABLE_NV_EXTENSIONS) |
| 68 | add_definitions(-DNV_EXTENSIONS) |
| 69 | endif(ENABLE_NV_EXTENSIONS) |
| 70 | |
Alex Szpakowski | ff21a25 | 2017-01-09 18:10:14 -0400 | [diff] [blame] | 71 | if(ENABLE_HLSL) |
| 72 | add_definitions(-DENABLE_HLSL) |
| 73 | endif(ENABLE_HLSL) |
Alex Szpakowski | 84eabf7 | 2017-01-08 21:20:25 -0400 | [diff] [blame] | 74 | |
John Kessenich | d49d524 | 2015-06-26 16:29:10 -0600 | [diff] [blame] | 75 | if(WIN32) |
Nuno Subtil | 424612c | 2019-01-25 09:30:37 -0800 | [diff] [blame] | 76 | set(CMAKE_DEBUG_POSTFIX "d") |
DragoonX6 | 8155934 | 2017-03-12 04:44:55 +0100 | [diff] [blame] | 77 | if(MSVC) |
| 78 | include(ChooseMSVCCRT.cmake) |
| 79 | endif(MSVC) |
baldurk | 876a0e3 | 2015-11-16 18:03:28 +0100 | [diff] [blame] | 80 | add_definitions(-DGLSLANG_OSINCLUDE_WIN32) |
John Kessenich | d49d524 | 2015-06-26 16:29:10 -0600 | [diff] [blame] | 81 | elseif(UNIX) |
baldurk | 876a0e3 | 2015-11-16 18:03:28 +0100 | [diff] [blame] | 82 | add_definitions(-DGLSLANG_OSINCLUDE_UNIX) |
John Kessenich | d49d524 | 2015-06-26 16:29:10 -0600 | [diff] [blame] | 83 | else(WIN32) |
Eric Engestrom | 6a6d6dd | 2016-04-03 01:17:13 +0100 | [diff] [blame] | 84 | message("unknown platform") |
John Kessenich | d49d524 | 2015-06-26 16:29:10 -0600 | [diff] [blame] | 85 | endif(WIN32) |
| 86 | |
David Seifert | 22afc38 | 2017-04-29 10:57:36 +0200 | [diff] [blame] | 87 | if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") |
| 88 | add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs |
LoopDawg | 8004d36 | 2017-09-17 10:38:52 -0600 | [diff] [blame] | 89 | -Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions) |
David Seifert | 22afc38 | 2017-04-29 10:57:36 +0200 | [diff] [blame] | 90 | add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over. |
Ryan Harrison | 8126eb1 | 2019-07-30 11:25:19 -0400 | [diff] [blame] | 91 | add_compile_options(-fno-rtti) |
John Kessenich | d49d524 | 2015-06-26 16:29:10 -0600 | [diff] [blame] | 92 | elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") |
David Seifert | 22afc38 | 2017-04-29 10:57:36 +0200 | [diff] [blame] | 93 | add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs |
| 94 | -Wunused-parameter -Wunused-value -Wunused-variable) |
| 95 | add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over. |
Ryan Harrison | 8126eb1 | 2019-07-30 11:25:19 -0400 | [diff] [blame] | 96 | add_compile_options(-fno-rtti) |
| 97 | elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC") |
| 98 | add_compile_options(/GR-) # Disable RTTI |
David Seifert | 22afc38 | 2017-04-29 10:57:36 +0200 | [diff] [blame] | 99 | endif() |
| 100 | |
| 101 | # Request C++11 |
| 102 | if(${CMAKE_VERSION} VERSION_LESS 3.1) |
| 103 | # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD |
| 104 | # remove this block once CMake >=3.1 has fixated in the ecosystem |
| 105 | add_compile_options(-std=c++11) |
| 106 | else() |
| 107 | set(CMAKE_CXX_STANDARD 11) |
| 108 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 109 | set(CMAKE_CXX_EXTENSIONS OFF) |
John Kessenich | d49d524 | 2015-06-26 16:29:10 -0600 | [diff] [blame] | 110 | endif() |
| 111 | |
David Neto | b37dc0e | 2016-06-02 14:37:24 -0400 | [diff] [blame] | 112 | function(glslang_set_link_args TARGET) |
| 113 | # For MinGW compiles, statically link against the GCC and C++ runtimes. |
| 114 | # This avoids the need to ship those runtimes as DLLs. |
David Seifert | 22afc38 | 2017-04-29 10:57:36 +0200 | [diff] [blame] | 115 | if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") |
| 116 | set_target_properties(${TARGET} PROPERTIES |
| 117 | LINK_FLAGS "-static -static-libgcc -static-libstdc++") |
| 118 | endif() |
David Neto | b37dc0e | 2016-06-02 14:37:24 -0400 | [diff] [blame] | 119 | endfunction(glslang_set_link_args) |
| 120 | |
John Kessenich | 6fef1ca | 2019-05-09 03:43:26 -0600 | [diff] [blame] | 121 | # CMake needs to find the right version of python, right from the beginning, |
| 122 | # otherwise, it will find the wrong version and fail later |
| 123 | if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/External) |
| 124 | find_package(PythonInterp 3 REQUIRED) |
| 125 | endif() |
| 126 | |
Lei Zhang | 414eb60 | 2016-03-04 16:22:34 -0500 | [diff] [blame] | 127 | # We depend on these for later projects, so they should come first. |
| 128 | add_subdirectory(External) |
| 129 | |
GregF | fd34f0e | 2017-09-21 16:50:39 -0600 | [diff] [blame] | 130 | if(NOT TARGET SPIRV-Tools-opt) |
| 131 | set(ENABLE_OPT OFF) |
| 132 | endif() |
| 133 | |
| 134 | if(ENABLE_OPT) |
| 135 | message(STATUS "optimizer enabled") |
GregF | fb03a55 | 2018-03-29 11:49:14 -0600 | [diff] [blame] | 136 | add_definitions(-DENABLE_OPT=1) |
John Kessenich | 5d8d788 | 2018-04-05 19:52:38 -0600 | [diff] [blame] | 137 | else() |
| 138 | if(ENABLE_HLSL) |
| 139 | message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL") |
| 140 | endif() |
GregF | fb03a55 | 2018-03-29 11:49:14 -0600 | [diff] [blame] | 141 | add_definitions(-DENABLE_OPT=0) |
GregF | fd34f0e | 2017-09-21 16:50:39 -0600 | [diff] [blame] | 142 | endif() |
| 143 | |
John Kessenich | d49d524 | 2015-06-26 16:29:10 -0600 | [diff] [blame] | 144 | add_subdirectory(glslang) |
| 145 | add_subdirectory(OGLCompilersDLL) |
Henrik Rydgård | 868746a | 2016-12-20 01:56:00 +0100 | [diff] [blame] | 146 | if(ENABLE_GLSLANG_BINARIES) |
David Seifert | 22afc38 | 2017-04-29 10:57:36 +0200 | [diff] [blame] | 147 | add_subdirectory(StandAlone) |
Henrik Rydgård | 868746a | 2016-12-20 01:56:00 +0100 | [diff] [blame] | 148 | endif() |
John Kessenich | d49d524 | 2015-06-26 16:29:10 -0600 | [diff] [blame] | 149 | add_subdirectory(SPIRV) |
Alex Szpakowski | ff21a25 | 2017-01-09 18:10:14 -0400 | [diff] [blame] | 150 | if(ENABLE_HLSL) |
Alex Szpakowski | 84eabf7 | 2017-01-08 21:20:25 -0400 | [diff] [blame] | 151 | add_subdirectory(hlsl) |
John Kessenich | dc1a819 | 2017-01-11 14:50:16 -0700 | [diff] [blame] | 152 | endif(ENABLE_HLSL) |
Lei Zhang | 414eb60 | 2016-03-04 16:22:34 -0500 | [diff] [blame] | 153 | add_subdirectory(gtests) |