Merge pull request #1565 from greg-lunarg/kg25
[platform/upstream/glslang.git] / CMakeLists.txt
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)
4 if (POLICY CMP0048)
5   cmake_policy(SET CMP0048 NEW)
6 endif()
7 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
8
9 # Adhere to GNU filesystem layout conventions
10 include(GNUInstallDirs)
11
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
20 option(SKIP_GLSLANG_INSTALL "Skip installation" ${SKIP_GLSLANG_INSTALL})
21 if(NOT ${SKIP_GLSLANG_INSTALL})
22   set(ENABLE_GLSLANG_INSTALL ON)
23 endif()
24 option(ENABLE_SPVREMAPPER "Enables building of SPVRemapper" ON)
25
26 option(ENABLE_AMD_EXTENSIONS "Enables support of AMD-specific extensions" ON)
27 option(ENABLE_GLSLANG_BINARIES "Builds glslangValidator and spirv-remap" ON)
28
29 option(ENABLE_NV_EXTENSIONS "Enables support of Nvidia-specific extensions" ON)
30
31 option(ENABLE_HLSL "Enables HLSL input support" ON)
32
33 option(ENABLE_OPT "Enables spirv-opt capability if present" ON)
34
35 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
36     set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "..." FORCE)
37 endif()
38
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
47 # Precompiled header macro. Parameters are source file list and filename for pch cpp file.
48 macro(glslang_pch SRCS PCHCPP)
49   if(MSVC)
50     if (CMAKE_GENERATOR MATCHES "^Visual Studio")
51       set(PCH_NAME "$(IntDir)\\pch.pch")
52     else()
53       set(PCH_NAME "pch.pch")
54     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()
61 endmacro(glslang_pch)
62
63 project(glslang)
64 # make testing optional
65 include(CTest)
66
67 if(ENABLE_AMD_EXTENSIONS)
68     add_definitions(-DAMD_EXTENSIONS)
69 endif(ENABLE_AMD_EXTENSIONS)
70
71 if(ENABLE_NV_EXTENSIONS)
72     add_definitions(-DNV_EXTENSIONS)
73 endif(ENABLE_NV_EXTENSIONS)
74
75 if(ENABLE_HLSL)
76     add_definitions(-DENABLE_HLSL)
77 endif(ENABLE_HLSL)
78
79 if(WIN32)
80     set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Adds a postfix for debug-built libraries.")
81     if(MSVC)
82         include(ChooseMSVCCRT.cmake)
83     endif(MSVC)
84     add_definitions(-DGLSLANG_OSINCLUDE_WIN32)
85 elseif(UNIX)
86     add_definitions(-DGLSLANG_OSINCLUDE_UNIX)
87 else(WIN32)
88     message("unknown platform")
89 endif(WIN32)
90
91 if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
92     add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
93                         -Wunused-parameter -Wunused-value  -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions)
94     add_compile_options(-Wno-reorder)  # disable this from -Wall, since it happens all over.
95 elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
96     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.
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)
110 endif()
111
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.
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()
119 endfunction(glslang_set_link_args)
120
121 # We depend on these for later projects, so they should come first.
122 add_subdirectory(External)
123
124 if(NOT TARGET SPIRV-Tools-opt)
125     set(ENABLE_OPT OFF)
126 endif()
127
128 if(ENABLE_OPT)
129     message(STATUS "optimizer enabled")
130     add_definitions(-DENABLE_OPT=1)
131 else()
132     if(ENABLE_HLSL)
133         message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL")
134     endif()
135     add_definitions(-DENABLE_OPT=0)
136 endif()
137
138 add_subdirectory(glslang)
139 add_subdirectory(OGLCompilersDLL)
140 if(ENABLE_GLSLANG_BINARIES)
141     add_subdirectory(StandAlone)
142 endif()
143 add_subdirectory(SPIRV)
144 if(ENABLE_HLSL)
145     add_subdirectory(hlsl)
146 endif(ENABLE_HLSL)
147 add_subdirectory(gtests)