@@ -107,6 +107,14 @@ if(USE_CCACHE)
107
107
endif (CCACHE_FOUND )
108
108
endif ()
109
109
110
+ # If projects are statically importing glslang targets into a shared library
111
+ # then they'll likely need to build with -fPIC. This can be enabled by setting
112
+ # GLSLANG_BUILD_PIC to 1 before calling add_subdirectory() to import glslang.
113
+ # Note: -fPIC is automatically used when BUILD_SHARED_LIBS is enabled.
114
+ if (NOT DEFINED GLSLANG_BUILD_PIC )
115
+ option (GLSLANG_BUILD_PIC "Compile glslang with -fPIC" OFF )
116
+ endif ()
117
+
110
118
# Precompiled header macro. Parameters are source file list and filename for pch cpp file.
111
119
macro (glslang_pch SRCS PCHCPP )
112
120
if (MSVC AND CMAKE_GENERATOR MATCHES "^Visual Studio" AND NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND ENABLE_PCH )
@@ -152,7 +160,7 @@ if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
152
160
add_compile_options (-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
153
161
-Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions )
154
162
add_compile_options (-Wno-reorder ) # disable this from -Wall, since it happens all over.
155
- if (BUILD_SHARED_LIBS )
163
+ if (BUILD_SHARED_LIBS OR GLSLANG_BUILD_PIC )
156
164
add_compile_options (-fPIC )
157
165
endif ()
158
166
if (NOT ENABLE_RTTI )
@@ -175,7 +183,7 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC)
175
183
add_compile_options (-Wall -Wuninitialized -Wunused -Wunused-local-typedefs
176
184
-Wunused-parameter -Wunused-value -Wunused-variable )
177
185
add_compile_options (-Wno-reorder ) # disable this from -Wall, since it happens all over.
178
- if (BUILD_SHARED_LIBS )
186
+ if (BUILD_SHARED_LIBS OR GLSLANG_BUILD_PIC )
179
187
add_compile_options (-fPIC )
180
188
endif ()
181
189
if (NOT ENABLE_RTTI )
0 commit comments