blob: c8e318262aba03a55f4d1e7046fb9733ea30d590 [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 Bolz0a93cfb2018-12-11 20:53:59 -060049 if(MSVC AND CMAKE_GENERATOR MATCHES "^Visual Studio")
50 set(PCH_NAME "$(IntDir)\\pch.pch")
Jeff Bolz22d0b7c2018-10-31 15:38:08 -050051 # 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 Bolz02ed3102018-11-07 09:35:20 -060057endmacro(glslang_pch)
Jeff Bolz22d0b7c2018-10-31 15:38:08 -050058
John Kessenichcfc69d92017-04-28 22:04:24 -060059project(glslang)
David Seifert22afc382017-04-29 10:57:36 +020060# make testing optional
61include(CTest)
David Seifert8f824262017-04-28 22:46:52 +020062
Rex Xu9d93a232016-05-05 12:30:44 +080063if(ENABLE_AMD_EXTENSIONS)
64 add_definitions(-DAMD_EXTENSIONS)
65endif(ENABLE_AMD_EXTENSIONS)
66
chaoc0ad6a4e2016-12-19 16:29:34 -080067if(ENABLE_NV_EXTENSIONS)
68 add_definitions(-DNV_EXTENSIONS)
69endif(ENABLE_NV_EXTENSIONS)
70
Alex Szpakowskiff21a252017-01-09 18:10:14 -040071if(ENABLE_HLSL)
72 add_definitions(-DENABLE_HLSL)
73endif(ENABLE_HLSL)
Alex Szpakowski84eabf72017-01-08 21:20:25 -040074
John Kessenichd49d5242015-06-26 16:29:10 -060075if(WIN32)
Nuno Subtil424612c2019-01-25 09:30:37 -080076 set(CMAKE_DEBUG_POSTFIX "d")
DragoonX681559342017-03-12 04:44:55 +010077 if(MSVC)
78 include(ChooseMSVCCRT.cmake)
79 endif(MSVC)
baldurk876a0e32015-11-16 18:03:28 +010080 add_definitions(-DGLSLANG_OSINCLUDE_WIN32)
John Kessenichd49d5242015-06-26 16:29:10 -060081elseif(UNIX)
baldurk876a0e32015-11-16 18:03:28 +010082 add_definitions(-DGLSLANG_OSINCLUDE_UNIX)
John Kessenichd49d5242015-06-26 16:29:10 -060083else(WIN32)
Eric Engestrom6a6d6dd2016-04-03 01:17:13 +010084 message("unknown platform")
John Kessenichd49d5242015-06-26 16:29:10 -060085endif(WIN32)
86
David Seifert22afc382017-04-29 10:57:36 +020087if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
88 add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
LoopDawg8004d362017-09-17 10:38:52 -060089 -Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions)
David Seifert22afc382017-04-29 10:57:36 +020090 add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
Ryan Harrison8126eb12019-07-30 11:25:19 -040091 add_compile_options(-fno-rtti)
John Kessenichd49d5242015-06-26 16:29:10 -060092elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
David Seifert22afc382017-04-29 10:57:36 +020093 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 Harrison8126eb12019-07-30 11:25:19 -040096 add_compile_options(-fno-rtti)
97elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC")
98 add_compile_options(/GR-) # Disable RTTI
David Seifert22afc382017-04-29 10:57:36 +020099endif()
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
John Kessenich6fef1ca2019-05-09 03:43:26 -0600121# CMake needs to find the right version of python, right from the beginning,
122# otherwise, it will find the wrong version and fail later
123if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/External)
124 find_package(PythonInterp 3 REQUIRED)
125endif()
126
Lei Zhang414eb602016-03-04 16:22:34 -0500127# We depend on these for later projects, so they should come first.
128add_subdirectory(External)
129
GregFfd34f0e2017-09-21 16:50:39 -0600130if(NOT TARGET SPIRV-Tools-opt)
131 set(ENABLE_OPT OFF)
132endif()
133
134if(ENABLE_OPT)
135 message(STATUS "optimizer enabled")
GregFfb03a552018-03-29 11:49:14 -0600136 add_definitions(-DENABLE_OPT=1)
John Kessenich5d8d7882018-04-05 19:52:38 -0600137else()
138 if(ENABLE_HLSL)
139 message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL")
140 endif()
GregFfb03a552018-03-29 11:49:14 -0600141 add_definitions(-DENABLE_OPT=0)
GregFfd34f0e2017-09-21 16:50:39 -0600142endif()
143
John Kessenichd49d5242015-06-26 16:29:10 -0600144add_subdirectory(glslang)
145add_subdirectory(OGLCompilersDLL)
Henrik Rydgård868746a2016-12-20 01:56:00 +0100146if(ENABLE_GLSLANG_BINARIES)
David Seifert22afc382017-04-29 10:57:36 +0200147 add_subdirectory(StandAlone)
Henrik Rydgård868746a2016-12-20 01:56:00 +0100148endif()
John Kessenichd49d5242015-06-26 16:29:10 -0600149add_subdirectory(SPIRV)
Alex Szpakowskiff21a252017-01-09 18:10:14 -0400150if(ENABLE_HLSL)
Alex Szpakowski84eabf72017-01-08 21:20:25 -0400151 add_subdirectory(hlsl)
John Kessenichdc1a8192017-01-11 14:50:16 -0700152endif(ENABLE_HLSL)
Lei Zhang414eb602016-03-04 16:22:34 -0500153add_subdirectory(gtests)