blob: dbe4308cda8042cd148fc443b5cc56edce54a1eb [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)
Andrew Woloszyndb0eaf92016-05-05 14:45:53 -04004set_property(GLOBAL PROPERTY USE_FOLDERS ON)
John Kessenichd49d5242015-06-26 16:29:10 -06005
David Seifert22afc382017-04-29 10:57:36 +02006# Adhere to GNU filesystem layout conventions
7include(GNUInstallDirs)
8
d3x0rf8f494f2017-07-04 05:54:57 -07009option(SKIP_GLSLANG_INSTALL "Skip installation" ${SKIP_GLSLANG_INSTALL})
10if(NOT ${SKIP_GLSLANG_INSTALL})
11 set(ENABLE_GLSLANG_INSTALL ON)
12endif()
13
Dominik Witczakdaff1a22016-09-27 09:51:34 +020014option(ENABLE_AMD_EXTENSIONS "Enables support of AMD-specific extensions" ON)
Henrik Rydgård868746a2016-12-20 01:56:00 +010015option(ENABLE_GLSLANG_BINARIES "Builds glslangValidator and spirv-remap" ON)
Rex Xu9d93a232016-05-05 12:30:44 +080016
chaoc0ad6a4e2016-12-19 16:29:34 -080017option(ENABLE_NV_EXTENSIONS "Enables support of Nvidia-specific extensions" ON)
18
Alex Szpakowskiff21a252017-01-09 18:10:14 -040019option(ENABLE_HLSL "Enables HLSL input support" ON)
Alex Szpakowski84eabf72017-01-08 21:20:25 -040020
GregFfd34f0e2017-09-21 16:50:39 -060021option(ENABLE_OPT "Enables spirv-opt capability if present" ON)
22
David Seifert22afc382017-04-29 10:57:36 +020023if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
24 set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "..." FORCE)
25endif()
John Kessenichcfc69d92017-04-28 22:04:24 -060026
27project(glslang)
David Seifert22afc382017-04-29 10:57:36 +020028# make testing optional
29include(CTest)
David Seifert8f824262017-04-28 22:46:52 +020030
Rex Xu9d93a232016-05-05 12:30:44 +080031if(ENABLE_AMD_EXTENSIONS)
32 add_definitions(-DAMD_EXTENSIONS)
33endif(ENABLE_AMD_EXTENSIONS)
34
chaoc0ad6a4e2016-12-19 16:29:34 -080035if(ENABLE_NV_EXTENSIONS)
36 add_definitions(-DNV_EXTENSIONS)
37endif(ENABLE_NV_EXTENSIONS)
38
Alex Szpakowskiff21a252017-01-09 18:10:14 -040039if(ENABLE_HLSL)
40 add_definitions(-DENABLE_HLSL)
41endif(ENABLE_HLSL)
Alex Szpakowski84eabf72017-01-08 21:20:25 -040042
John Kessenichd49d5242015-06-26 16:29:10 -060043if(WIN32)
Brad Davis1e194e82016-05-25 13:08:34 -070044 set(CMAKE_DEBUG_POSTFIX "d")
DragoonX681559342017-03-12 04:44:55 +010045 if(MSVC)
46 include(ChooseMSVCCRT.cmake)
47 endif(MSVC)
baldurk876a0e32015-11-16 18:03:28 +010048 add_definitions(-DGLSLANG_OSINCLUDE_WIN32)
John Kessenichd49d5242015-06-26 16:29:10 -060049elseif(UNIX)
baldurk876a0e32015-11-16 18:03:28 +010050 add_definitions(-DGLSLANG_OSINCLUDE_UNIX)
John Kessenichd49d5242015-06-26 16:29:10 -060051else(WIN32)
Eric Engestrom6a6d6dd2016-04-03 01:17:13 +010052 message("unknown platform")
John Kessenichd49d5242015-06-26 16:29:10 -060053endif(WIN32)
54
David Seifert22afc382017-04-29 10:57:36 +020055if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
56 add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
LoopDawg8004d362017-09-17 10:38:52 -060057 -Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions)
David Seifert22afc382017-04-29 10:57:36 +020058 add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
John Kessenichd49d5242015-06-26 16:29:10 -060059elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
David Seifert22afc382017-04-29 10:57:36 +020060 add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs
61 -Wunused-parameter -Wunused-value -Wunused-variable)
62 add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
63endif()
64
65# Request C++11
66if(${CMAKE_VERSION} VERSION_LESS 3.1)
67 # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD
68 # remove this block once CMake >=3.1 has fixated in the ecosystem
69 add_compile_options(-std=c++11)
70else()
71 set(CMAKE_CXX_STANDARD 11)
72 set(CMAKE_CXX_STANDARD_REQUIRED ON)
73 set(CMAKE_CXX_EXTENSIONS OFF)
John Kessenichd49d5242015-06-26 16:29:10 -060074endif()
75
David Netob37dc0e2016-06-02 14:37:24 -040076function(glslang_set_link_args TARGET)
77 # For MinGW compiles, statically link against the GCC and C++ runtimes.
78 # This avoids the need to ship those runtimes as DLLs.
David Seifert22afc382017-04-29 10:57:36 +020079 if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
80 set_target_properties(${TARGET} PROPERTIES
81 LINK_FLAGS "-static -static-libgcc -static-libstdc++")
82 endif()
David Netob37dc0e2016-06-02 14:37:24 -040083endfunction(glslang_set_link_args)
84
Lei Zhang414eb602016-03-04 16:22:34 -050085# We depend on these for later projects, so they should come first.
86add_subdirectory(External)
87
GregFfd34f0e2017-09-21 16:50:39 -060088if(NOT TARGET SPIRV-Tools-opt)
89 set(ENABLE_OPT OFF)
90endif()
91
92if(ENABLE_OPT)
93 message(STATUS "optimizer enabled")
94 add_definitions(-DENABLE_OPT)
95elseif(ENABLE_HLSL)
96 message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL")
97endif()
98
John Kessenichd49d5242015-06-26 16:29:10 -060099add_subdirectory(glslang)
100add_subdirectory(OGLCompilersDLL)
Henrik Rydgård868746a2016-12-20 01:56:00 +0100101if(ENABLE_GLSLANG_BINARIES)
David Seifert22afc382017-04-29 10:57:36 +0200102 add_subdirectory(StandAlone)
Henrik Rydgård868746a2016-12-20 01:56:00 +0100103endif()
John Kessenichd49d5242015-06-26 16:29:10 -0600104add_subdirectory(SPIRV)
Alex Szpakowskiff21a252017-01-09 18:10:14 -0400105if(ENABLE_HLSL)
Alex Szpakowski84eabf72017-01-08 21:20:25 -0400106 add_subdirectory(hlsl)
John Kessenichdc1a8192017-01-11 14:50:16 -0700107endif(ENABLE_HLSL)
Lei Zhang414eb602016-03-04 16:22:34 -0500108add_subdirectory(gtests)