spec: Added PIE option to complie and linker option.
[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(SKIP_GLSLANG_INSTALL "Skip installation" ${SKIP_GLSLANG_INSTALL})
13 if(NOT ${SKIP_GLSLANG_INSTALL})
14   set(ENABLE_GLSLANG_INSTALL ON)
15 endif()
16
17 option(ENABLE_AMD_EXTENSIONS "Enables support of AMD-specific extensions" ON)
18 option(ENABLE_GLSLANG_BINARIES "Builds glslangValidator and spirv-remap" ON)
19
20 option(ENABLE_NV_EXTENSIONS "Enables support of Nvidia-specific extensions" ON)
21
22 option(ENABLE_HLSL "Enables HLSL input support" ON)
23
24 option(ENABLE_OPT "Enables spirv-opt capability if present" ON)
25
26 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
27     set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "..." FORCE)
28 endif()
29
30 project(glslang)
31 # make testing optional
32 include(CTest)
33
34 if(ENABLE_AMD_EXTENSIONS)
35     add_definitions(-DAMD_EXTENSIONS)
36 endif(ENABLE_AMD_EXTENSIONS)
37
38 if(ENABLE_NV_EXTENSIONS)
39     add_definitions(-DNV_EXTENSIONS)
40 endif(ENABLE_NV_EXTENSIONS)
41
42 if(ENABLE_HLSL)
43     add_definitions(-DENABLE_HLSL)
44 endif(ENABLE_HLSL)
45
46 if(WIN32)
47     set(CMAKE_DEBUG_POSTFIX "d")
48     if(MSVC)
49         include(ChooseMSVCCRT.cmake)
50     endif(MSVC)
51     add_definitions(-DGLSLANG_OSINCLUDE_WIN32)
52 elseif(UNIX)
53     add_definitions(-DGLSLANG_OSINCLUDE_UNIX)
54 else(WIN32)
55     message("unknown platform")
56 endif(WIN32)
57
58 if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
59     add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
60                         -Wunused-parameter -Wunused-value  -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions)
61     add_compile_options(-Wno-reorder)  # disable this from -Wall, since it happens all over.
62 elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
63     add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs
64                         -Wunused-parameter -Wunused-value  -Wunused-variable)
65     add_compile_options(-Wno-reorder)  # disable this from -Wall, since it happens all over.
66 endif()
67
68 # Request C++11
69 if(${CMAKE_VERSION} VERSION_LESS 3.1)
70     # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD
71     # remove this block once CMake >=3.1 has fixated in the ecosystem
72     add_compile_options(-std=c++11)
73 else()
74     set(CMAKE_CXX_STANDARD 11)
75     set(CMAKE_CXX_STANDARD_REQUIRED ON)
76     set(CMAKE_CXX_EXTENSIONS OFF)
77 endif()
78
79 function(glslang_set_link_args TARGET)
80     # For MinGW compiles, statically link against the GCC and C++ runtimes.
81     # This avoids the need to ship those runtimes as DLLs.
82     if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
83         set_target_properties(${TARGET} PROPERTIES
84                               LINK_FLAGS "-static -static-libgcc -static-libstdc++")
85     endif()
86 endfunction(glslang_set_link_args)
87
88 # We depend on these for later projects, so they should come first.
89 add_subdirectory(External)
90
91 if(NOT TARGET SPIRV-Tools-opt)
92     set(ENABLE_OPT OFF)
93 endif()
94
95 if(ENABLE_OPT)
96     message(STATUS "optimizer enabled")
97     add_definitions(-DENABLE_OPT)
98 elseif(ENABLE_HLSL)
99     message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL")
100 endif()
101
102 add_subdirectory(glslang)
103 add_subdirectory(OGLCompilersDLL)
104 if(ENABLE_GLSLANG_BINARIES)
105     add_subdirectory(StandAlone)
106 endif()
107 add_subdirectory(SPIRV)
108 if(ENABLE_HLSL)
109     add_subdirectory(hlsl)
110 endif(ENABLE_HLSL)
111 add_subdirectory(gtests)