Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SHADERC_BUILD_SHARED to control static/shared library #498

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ cmake_minimum_required(VERSION 2.8.12)
project(shaderc)
enable_testing()

set (CMAKE_CXX_STANDARD 11)

message(STATUS "Shaderc: build type is \"${CMAKE_BUILD_TYPE}\".")

# Note that we are not using or setting CMake BUILD_SHARED_LIBS here since that
# also affects external projects and makes libshaderc.so to depend on shared
# libraries compiled from external projects. We want libshaderc.so to depend
# on only standard system libraries.
option(SHADERC_BUILD_SHARED "Build Shaderc as shared library" OFF)

option(SHADERC_SKIP_INSTALL "Skip installation" ${SHADERC_SKIP_INSTALL})
if(NOT ${SHADERC_SKIP_INSTALL})
set(SHADERC_ENABLE_INSTALL ON)
Expand All @@ -19,8 +27,6 @@ else()
message(STATUS "Configuring Shaderc to avoid building tests.")
endif()

set (CMAKE_CXX_STANDARD 11)

option(SHADERC_ENABLE_NV_EXTENSIONS "Enables support of Nvidia-specific extensions" ON)

include(GNUInstallDirs)
Expand Down
84 changes: 38 additions & 46 deletions libshaderc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ set(SHADERC_SOURCES
src/shaderc_private.h
)

add_library(shaderc STATIC ${SHADERC_SOURCES})
if (${SHADERC_BUILD_SHARED})
add_library(shaderc SHARED ${SHADERC_SOURCES})
target_compile_definitions(shaderc
PRIVATE SHADERC_IMPLEMENTATION
PUBLIC SHADERC_SHAREDLIB
)
set_target_properties(shaderc PROPERTIES SOVERSION 1)
else()
add_library(shaderc STATIC ${SHADERC_SOURCES})
endif (${SHADERC_BUILD_SHARED})

shaderc_default_compile_options(shaderc)
target_include_directories(shaderc PUBLIC include PRIVATE ${glslang_SOURCE_DIR})

add_library(shaderc_shared SHARED ${SHADERC_SOURCES})
shaderc_default_compile_options(shaderc_shared)
target_include_directories(shaderc_shared PUBLIC include PRIVATE ${glslang_SOURCE_DIR})
target_compile_definitions(shaderc_shared
PRIVATE SHADERC_IMPLEMENTATION
PUBLIC SHADERC_SHAREDLIB
)
set_target_properties(shaderc_shared PROPERTIES SOVERSION 1)

if(SHADERC_ENABLE_INSTALL)
install(
FILES
Expand All @@ -31,7 +32,7 @@ if(SHADERC_ENABLE_INSTALL)
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/shaderc)

install(TARGETS shaderc shaderc_shared
install(TARGETS shaderc
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
Expand All @@ -46,7 +47,6 @@ set(SHADERC_LIBS
)

target_link_libraries(shaderc PRIVATE ${SHADERC_LIBS})
target_link_libraries(shaderc_shared PRIVATE ${SHADERC_LIBS})

shaderc_add_tests(
TEST_PREFIX shaderc
Expand All @@ -58,42 +58,34 @@ shaderc_add_tests(
shaderc_cpp
shaderc_private)

shaderc_add_tests(
TEST_PREFIX shaderc_shared
LINK_LIBS shaderc_shared SPIRV-Tools
INCLUDE_DIRS include ${shaderc_SOURCE_DIR}/libshaderc_util/include ${glslang_SOURCE_DIR}
${spirv-tools_SOURCE_DIR}/include
TEST_NAMES
shaderc
shaderc_cpp
shaderc_private)

shaderc_combine_static_lib(shaderc_combined shaderc)
if (NOT ${SHADERC_BUILD_SHARED})
shaderc_combine_static_lib(shaderc_combined shaderc)

if(SHADERC_ENABLE_INSTALL)
# Since shaderc_combined is defined as an imported library, we cannot use the
# install() directive to install it. Install it like a normal file.
get_target_property(generated_location shaderc_combined LOCATION)
string(REGEX MATCH "Visual Studio .*" vs_generator "${CMAKE_GENERATOR}")
if (NOT "${vs_generator}" STREQUAL "")
# With Visual Studio generators, the LOCATION property is not properly
# expanded according to the current build configuration. We need to work
# around this problem by manually substitution.
string(REPLACE "$(Configuration)" "\${CMAKE_INSTALL_CONFIG_NAME}"
install_location "${generated_location}")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${install_location} DESTINATION ${CMAKE_INSTALL_LIBDIR})
else()
install(FILES ${generated_location} DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
endif(SHADERC_ENABLE_INSTALL)
if(SHADERC_ENABLE_INSTALL)
# Since shaderc_combined is defined as an imported library, we cannot use the
# install() directive to install it. Install it like a normal file.
get_target_property(generated_location shaderc_combined LOCATION)
string(REGEX MATCH "Visual Studio .*" vs_generator "${CMAKE_GENERATOR}")
if (NOT "${vs_generator}" STREQUAL "")
# With Visual Studio generators, the LOCATION property is not properly
# expanded according to the current build configuration. We need to work
# around this problem by manually substitution.
string(REPLACE "$(Configuration)" "\${CMAKE_INSTALL_CONFIG_NAME}"
install_location "${generated_location}")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${install_location} DESTINATION ${CMAKE_INSTALL_LIBDIR})
else()
install(FILES ${generated_location} DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
endif(SHADERC_ENABLE_INSTALL)

shaderc_add_tests(
TEST_PREFIX shaderc_combined
LINK_LIBS shaderc_combined ${CMAKE_THREAD_LIBS_INIT}
INCLUDE_DIRS include ${glslang_SOURCE_DIR} ${spirv-tools_SOURCE_DIR}/include
TEST_NAMES
shaderc
shaderc_cpp)
shaderc_add_tests(
TEST_PREFIX shaderc_combined
LINK_LIBS shaderc_combined ${CMAKE_THREAD_LIBS_INIT}
INCLUDE_DIRS include ${glslang_SOURCE_DIR} ${spirv-tools_SOURCE_DIR}/include
TEST_NAMES
shaderc
shaderc_cpp)
endif(NOT ${SHADERC_BUILD_SHARED})

if(${SHADERC_ENABLE_TESTS})
add_executable(shaderc_c_smoke_test ./src/shaderc_c_smoke_test.c)
Expand Down