Skip to content

Commit 257e9a3

Browse files
authored
Merge pull request KhronosGroup#2319 from ben-clayton/build-pic
Add GLSLANG_BUILD_PIC CMake flag
2 parents 0638724 + 1125f1b commit 257e9a3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ if(USE_CCACHE)
107107
endif(CCACHE_FOUND)
108108
endif()
109109

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+
110118
# Precompiled header macro. Parameters are source file list and filename for pch cpp file.
111119
macro(glslang_pch SRCS PCHCPP)
112120
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")
152160
add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
153161
-Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions)
154162
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)
156164
add_compile_options(-fPIC)
157165
endif()
158166
if(NOT ENABLE_RTTI)
@@ -175,7 +183,7 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC)
175183
add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs
176184
-Wunused-parameter -Wunused-value -Wunused-variable)
177185
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)
179187
add_compile_options(-fPIC)
180188
endif()
181189
if(NOT ENABLE_RTTI)

0 commit comments

Comments
 (0)