blob: 7dc35b01ae4f51756c53d75a5f4a40cbef6007b7 [file] [log] [blame]
David Seifert22afc382017-04-29 10:57:36 +02001# increase to 3.1 once all major distributions
2# include a version of CMake >= 3.1
3cmake_minimum_required(VERSION 2.8.12)
Tim Diekmannaab00012017-10-10 16:26:31 +02004if (POLICY CMP0048)
5 cmake_policy(SET CMP0048 NEW)
6endif()
Andrew Woloszyndb0eaf92016-05-05 14:45:53 -04007set_property(GLOBAL PROPERTY USE_FOLDERS ON)
John Kessenichd49d5242015-06-26 16:29:10 -06008
David Seifert22afc382017-04-29 10:57:36 +02009# Adhere to GNU filesystem layout conventions
10include(GNUInstallDirs)
11
Matthew Albrecht6c5f6492018-03-30 09:32:03 -050012option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
13
14set(LIB_TYPE STATIC)
15
16if(BUILD_SHARED_LIBS)
17 set(LIB_TYPE SHARED)
18endif()
19
d3x0rf8f494f2017-07-04 05:54:57 -070020option(SKIP_GLSLANG_INSTALL "Skip installation" ${SKIP_GLSLANG_INSTALL})
21if(NOT ${SKIP_GLSLANG_INSTALL})
22 set(ENABLE_GLSLANG_INSTALL ON)
23endif()
Matthew Albrecht857f25c2018-07-07 16:53:06 -050024option(ENABLE_SPVREMAPPER "Enables building of SPVRemapper" ON)
d3x0rf8f494f2017-07-04 05:54:57 -070025
Dominik Witczakdaff1a22016-09-27 09:51:34 +020026option(ENABLE_AMD_EXTENSIONS "Enables support of AMD-specific extensions" ON)
Henrik Rydgård868746a2016-12-20 01:56:00 +010027option(ENABLE_GLSLANG_BINARIES "Builds glslangValidator and spirv-remap" ON)
Rex Xu9d93a232016-05-05 12:30:44 +080028
chaoc0ad6a4e2016-12-19 16:29:34 -080029option(ENABLE_NV_EXTENSIONS "Enables support of Nvidia-specific extensions" ON)
30
Alex Szpakowskiff21a252017-01-09 18:10:14 -040031option(ENABLE_HLSL "Enables HLSL input support" ON)
Alex Szpakowski84eabf72017-01-08 21:20:25 -040032
GregFfd34f0e2017-09-21 16:50:39 -060033option(ENABLE_OPT "Enables spirv-opt capability if present" ON)
34
David Seifert22afc382017-04-29 10:57:36 +020035if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
36 set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "..." FORCE)
37endif()
John Kessenichcfc69d92017-04-28 22:04:24 -060038
Karl Schultz23770b92018-07-06 12:12:09 -060039option(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
Jeff Bolz22d0b7c2018-10-31 15:38:08 -050047# Precompiled header macro. Parameters are source file list and filename for pch cpp file.
Jeff Bolz02ed3102018-11-07 09:35:20 -060048macro(glslang_pch SRCS PCHCPP)
Jeff Bolz22d0b7c2018-10-31 15:38:08 -050049 if(MSVC)
50 if (CMAKE_GENERATOR MATCHES "^Visual Studio")
51 set(PCH_NAME "$(IntDir)\\pch.pch")
52 else()
David Neto03925442018-11-12 17:09:07 -050053 set(PCH_NAME "${CMAKE_CURRENT_BINARY_DIR}/pch.pch")
Jeff Bolz22d0b7c2018-10-31 15:38:08 -050054 endif()
55 # make source files use/depend on PCH_NAME
56 set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS "/Yupch.h /FIpch.h /Fp${PCH_NAME} /Zm300" OBJECT_DEPENDS "${PCH_NAME}")
57 # make PCHCPP file compile and generate PCH_NAME
58 set_source_files_properties(${PCHCPP} PROPERTIES COMPILE_FLAGS "/Ycpch.h /Fp${PCH_NAME} /Zm300" OBJECT_OUTPUTS "${PCH_NAME}")
59 list(APPEND ${SRCS} "${PCHCPP}")
60 endif()
Jeff Bolz02ed3102018-11-07 09:35:20 -060061endmacro(glslang_pch)
Jeff Bolz22d0b7c2018-10-31 15:38:08 -050062
John Kessenichcfc69d92017-04-28 22:04:24 -060063project(glslang)
David Seifert22afc382017-04-29 10:57:36 +020064# make testing optional
65include(CTest)
David Seifert8f824262017-04-28 22:46:52 +020066
Rex Xu9d93a232016-05-05 12:30:44 +080067if(ENABLE_AMD_EXTENSIONS)
68 add_definitions(-DAMD_EXTENSIONS)
69endif(ENABLE_AMD_EXTENSIONS)
70
chaoc0ad6a4e2016-12-19 16:29:34 -080071if(ENABLE_NV_EXTENSIONS)
72 add_definitions(-DNV_EXTENSIONS)
73endif(ENABLE_NV_EXTENSIONS)
74
Alex Szpakowskiff21a252017-01-09 18:10:14 -040075if(ENABLE_HLSL)
76 add_definitions(-DENABLE_HLSL)
77endif(ENABLE_HLSL)
Alex Szpakowski84eabf72017-01-08 21:20:25 -040078
John Kessenichd49d5242015-06-26 16:29:10 -060079if(WIN32)
Matthew Albrechtf9c2aeb2018-07-07 17:00:08 -050080 set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Adds a postfix for debug-built libraries.")
DragoonX681559342017-03-12 04:44:55 +010081 if(MSVC)
82 include(ChooseMSVCCRT.cmake)
83 endif(MSVC)
baldurk876a0e32015-11-16 18:03:28 +010084 add_definitions(-DGLSLANG_OSINCLUDE_WIN32)
John Kessenichd49d5242015-06-26 16:29:10 -060085elseif(UNIX)
baldurk876a0e32015-11-16 18:03:28 +010086 add_definitions(-DGLSLANG_OSINCLUDE_UNIX)
John Kessenichd49d5242015-06-26 16:29:10 -060087else(WIN32)
Eric Engestrom6a6d6dd2016-04-03 01:17:13 +010088 message("unknown platform")
John Kessenichd49d5242015-06-26 16:29:10 -060089endif(WIN32)
90
David Seifert22afc382017-04-29 10:57:36 +020091if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
92 add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
LoopDawg8004d362017-09-17 10:38:52 -060093 -Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions)
David Seifert22afc382017-04-29 10:57:36 +020094 add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
John Kessenichd49d5242015-06-26 16:29:10 -060095elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
David Seifert22afc382017-04-29 10:57:36 +020096 add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs
97 -Wunused-parameter -Wunused-value -Wunused-variable)
98 add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
99endif()
100
101# Request C++11
102if(${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)
106else()
107 set(CMAKE_CXX_STANDARD 11)
108 set(CMAKE_CXX_STANDARD_REQUIRED ON)
109 set(CMAKE_CXX_EXTENSIONS OFF)
John Kessenichd49d5242015-06-26 16:29:10 -0600110endif()
111
David Netob37dc0e2016-06-02 14:37:24 -0400112function(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 Seifert22afc382017-04-29 10:57:36 +0200115 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 Netob37dc0e2016-06-02 14:37:24 -0400119endfunction(glslang_set_link_args)
120
Lei Zhang414eb602016-03-04 16:22:34 -0500121# We depend on these for later projects, so they should come first.
122add_subdirectory(External)
123
GregFfd34f0e2017-09-21 16:50:39 -0600124if(NOT TARGET SPIRV-Tools-opt)
125 set(ENABLE_OPT OFF)
126endif()
127
128if(ENABLE_OPT)
129 message(STATUS "optimizer enabled")
GregFfb03a552018-03-29 11:49:14 -0600130 add_definitions(-DENABLE_OPT=1)
John Kessenich5d8d7882018-04-05 19:52:38 -0600131else()
132 if(ENABLE_HLSL)
133 message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL")
134 endif()
GregFfb03a552018-03-29 11:49:14 -0600135 add_definitions(-DENABLE_OPT=0)
GregFfd34f0e2017-09-21 16:50:39 -0600136endif()
137
John Kessenichd49d5242015-06-26 16:29:10 -0600138add_subdirectory(glslang)
139add_subdirectory(OGLCompilersDLL)
Henrik Rydgård868746a2016-12-20 01:56:00 +0100140if(ENABLE_GLSLANG_BINARIES)
David Seifert22afc382017-04-29 10:57:36 +0200141 add_subdirectory(StandAlone)
Henrik Rydgård868746a2016-12-20 01:56:00 +0100142endif()
John Kessenichd49d5242015-06-26 16:29:10 -0600143add_subdirectory(SPIRV)
Alex Szpakowskiff21a252017-01-09 18:10:14 -0400144if(ENABLE_HLSL)
Alex Szpakowski84eabf72017-01-08 21:20:25 -0400145 add_subdirectory(hlsl)
John Kessenichdc1a8192017-01-11 14:50:16 -0700146endif(ENABLE_HLSL)
Lei Zhang414eb602016-03-04 16:22:34 -0500147add_subdirectory(gtests)