Merge pull request #1517 from Kangz/mac_complete_lib
[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 project(glslang)
48 # make testing optional
49 include(CTest)
50
51 if(ENABLE_AMD_EXTENSIONS)
52     add_definitions(-DAMD_EXTENSIONS)
53 endif(ENABLE_AMD_EXTENSIONS)
54
55 if(ENABLE_NV_EXTENSIONS)
56     add_definitions(-DNV_EXTENSIONS)
57 endif(ENABLE_NV_EXTENSIONS)
58
59 if(ENABLE_HLSL)
60     add_definitions(-DENABLE_HLSL)
61 endif(ENABLE_HLSL)
62
63 if(WIN32)
64     set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Adds a postfix for debug-built libraries.")
65     if(MSVC)
66         include(ChooseMSVCCRT.cmake)
67     endif(MSVC)
68     add_definitions(-DGLSLANG_OSINCLUDE_WIN32)
69 elseif(UNIX)
70     add_definitions(-DGLSLANG_OSINCLUDE_UNIX)
71 else(WIN32)
72     message("unknown platform")
73 endif(WIN32)
74
75 if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
76     add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
77                         -Wunused-parameter -Wunused-value  -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions)
78     add_compile_options(-Wno-reorder)  # disable this from -Wall, since it happens all over.
79 elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
80     add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs
81                         -Wunused-parameter -Wunused-value  -Wunused-variable)
82     add_compile_options(-Wno-reorder)  # disable this from -Wall, since it happens all over.
83 endif()
84
85 # Request C++11
86 if(${CMAKE_VERSION} VERSION_LESS 3.1)
87     # CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD
88     # remove this block once CMake >=3.1 has fixated in the ecosystem
89     add_compile_options(-std=c++11)
90 else()
91     set(CMAKE_CXX_STANDARD 11)
92     set(CMAKE_CXX_STANDARD_REQUIRED ON)
93     set(CMAKE_CXX_EXTENSIONS OFF)
94 endif()
95
96 function(glslang_set_link_args TARGET)
97     # For MinGW compiles, statically link against the GCC and C++ runtimes.
98     # This avoids the need to ship those runtimes as DLLs.
99     if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
100         set_target_properties(${TARGET} PROPERTIES
101                               LINK_FLAGS "-static -static-libgcc -static-libstdc++")
102     endif()
103 endfunction(glslang_set_link_args)
104
105 # We depend on these for later projects, so they should come first.
106 add_subdirectory(External)
107
108 if(NOT TARGET SPIRV-Tools-opt)
109     set(ENABLE_OPT OFF)
110 endif()
111
112 if(ENABLE_OPT)
113     message(STATUS "optimizer enabled")
114     add_definitions(-DENABLE_OPT=1)
115 else()
116     if(ENABLE_HLSL)
117         message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL")
118     endif()
119     add_definitions(-DENABLE_OPT=0)
120 endif()
121
122 add_subdirectory(glslang)
123 add_subdirectory(OGLCompilersDLL)
124 if(ENABLE_GLSLANG_BINARIES)
125     add_subdirectory(StandAlone)
126 endif()
127 add_subdirectory(SPIRV)
128 if(ENABLE_HLSL)
129     add_subdirectory(hlsl)
130 endif(ENABLE_HLSL)
131 add_subdirectory(gtests)