blob: 9a869c2c00110bf23e953125d1c6c77fad7656bc [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()
24
Dominik Witczakdaff1a22016-09-27 09:51:34 +020025option(ENABLE_AMD_EXTENSIONS "Enables support of AMD-specific extensions" ON)
Henrik Rydgård868746a2016-12-20 01:56:00 +010026option(ENABLE_GLSLANG_BINARIES "Builds glslangValidator and spirv-remap" ON)
Rex Xu9d93a232016-05-05 12:30:44 +080027
chaoc0ad6a4e2016-12-19 16:29:34 -080028option(ENABLE_NV_EXTENSIONS "Enables support of Nvidia-specific extensions" ON)
29
Alex Szpakowskiff21a252017-01-09 18:10:14 -040030option(ENABLE_HLSL "Enables HLSL input support" ON)
Alex Szpakowski84eabf72017-01-08 21:20:25 -040031
GregFfd34f0e2017-09-21 16:50:39 -060032option(ENABLE_OPT "Enables spirv-opt capability if present" ON)
33
David Seifert22afc382017-04-29 10:57:36 +020034if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
35 set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "..." FORCE)
36endif()
John Kessenichcfc69d92017-04-28 22:04:24 -060037
38project(glslang)
David Seifert22afc382017-04-29 10:57:36 +020039# make testing optional
40include(CTest)
David Seifert8f824262017-04-28 22:46:52 +020041
Rex Xu9d93a232016-05-05 12:30:44 +080042if(ENABLE_AMD_EXTENSIONS)
43 add_definitions(-DAMD_EXTENSIONS)
44endif(ENABLE_AMD_EXTENSIONS)
45
chaoc0ad6a4e2016-12-19 16:29:34 -080046if(ENABLE_NV_EXTENSIONS)
47 add_definitions(-DNV_EXTENSIONS)
48endif(ENABLE_NV_EXTENSIONS)
49
Alex Szpakowskiff21a252017-01-09 18:10:14 -040050if(ENABLE_HLSL)
51 add_definitions(-DENABLE_HLSL)
52endif(ENABLE_HLSL)
Alex Szpakowski84eabf72017-01-08 21:20:25 -040053
John Kessenichd49d5242015-06-26 16:29:10 -060054if(WIN32)
Brad Davis1e194e82016-05-25 13:08:34 -070055 set(CMAKE_DEBUG_POSTFIX "d")
DragoonX681559342017-03-12 04:44:55 +010056 if(MSVC)
57 include(ChooseMSVCCRT.cmake)
58 endif(MSVC)
baldurk876a0e32015-11-16 18:03:28 +010059 add_definitions(-DGLSLANG_OSINCLUDE_WIN32)
John Kessenichd49d5242015-06-26 16:29:10 -060060elseif(UNIX)
baldurk876a0e32015-11-16 18:03:28 +010061 add_definitions(-DGLSLANG_OSINCLUDE_UNIX)
John Kessenichd49d5242015-06-26 16:29:10 -060062else(WIN32)
Eric Engestrom6a6d6dd2016-04-03 01:17:13 +010063 message("unknown platform")
John Kessenichd49d5242015-06-26 16:29:10 -060064endif(WIN32)
65
David Seifert22afc382017-04-29 10:57:36 +020066if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
67 add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
LoopDawg8004d362017-09-17 10:38:52 -060068 -Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions)
David Seifert22afc382017-04-29 10:57:36 +020069 add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
John Kessenichd49d5242015-06-26 16:29:10 -060070elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
David Seifert22afc382017-04-29 10:57:36 +020071 add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs
72 -Wunused-parameter -Wunused-value -Wunused-variable)
73 add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
74endif()
75
76# Request C++11
77if(${CMAKE_VERSION} VERSION_LESS 3.1)
78 # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD
79 # remove this block once CMake >=3.1 has fixated in the ecosystem
80 add_compile_options(-std=c++11)
81else()
82 set(CMAKE_CXX_STANDARD 11)
83 set(CMAKE_CXX_STANDARD_REQUIRED ON)
84 set(CMAKE_CXX_EXTENSIONS OFF)
John Kessenichd49d5242015-06-26 16:29:10 -060085endif()
86
David Netob37dc0e2016-06-02 14:37:24 -040087function(glslang_set_link_args TARGET)
88 # For MinGW compiles, statically link against the GCC and C++ runtimes.
89 # This avoids the need to ship those runtimes as DLLs.
David Seifert22afc382017-04-29 10:57:36 +020090 if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
91 set_target_properties(${TARGET} PROPERTIES
92 LINK_FLAGS "-static -static-libgcc -static-libstdc++")
93 endif()
David Netob37dc0e2016-06-02 14:37:24 -040094endfunction(glslang_set_link_args)
95
Lei Zhang414eb602016-03-04 16:22:34 -050096# We depend on these for later projects, so they should come first.
97add_subdirectory(External)
98
GregFfd34f0e2017-09-21 16:50:39 -060099if(NOT TARGET SPIRV-Tools-opt)
100 set(ENABLE_OPT OFF)
101endif()
102
103if(ENABLE_OPT)
104 message(STATUS "optimizer enabled")
GregFfb03a552018-03-29 11:49:14 -0600105 add_definitions(-DENABLE_OPT=1)
John Kessenich5d8d7882018-04-05 19:52:38 -0600106else()
107 if(ENABLE_HLSL)
108 message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL")
109 endif()
GregFfb03a552018-03-29 11:49:14 -0600110 add_definitions(-DENABLE_OPT=0)
GregFfd34f0e2017-09-21 16:50:39 -0600111endif()
112
John Kessenichd49d5242015-06-26 16:29:10 -0600113add_subdirectory(glslang)
114add_subdirectory(OGLCompilersDLL)
Henrik Rydgård868746a2016-12-20 01:56:00 +0100115if(ENABLE_GLSLANG_BINARIES)
David Seifert22afc382017-04-29 10:57:36 +0200116 add_subdirectory(StandAlone)
Henrik Rydgård868746a2016-12-20 01:56:00 +0100117endif()
John Kessenichd49d5242015-06-26 16:29:10 -0600118add_subdirectory(SPIRV)
Alex Szpakowskiff21a252017-01-09 18:10:14 -0400119if(ENABLE_HLSL)
Alex Szpakowski84eabf72017-01-08 21:20:25 -0400120 add_subdirectory(hlsl)
John Kessenichdc1a8192017-01-11 14:50:16 -0700121endif(ENABLE_HLSL)
Lei Zhang414eb602016-03-04 16:22:34 -0500122add_subdirectory(gtests)