Skip to content

Commit

Permalink
Introduce new option to skip installation
Browse files Browse the repository at this point in the history
Define an option SHADERC_SKIP_INSTALL which depending on the value sets
SHADERC_ENABLE_INSTALL which will be used to test to bypass install()
rules in later projects.
Since this is a static library, I really only need to link to the libraries,
and not install them.

Chain skip install to third party libraries.

Also use GNUInstallDirs to install to lib64 where that's appropriate.
  • Loading branch information
d3x0r authored and dneto0 committed Jul 4, 2017
1 parent cd5199f commit e27569f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 28 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ enable_testing()

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

option(SHADERC_SKIP_INSTALL "Skip installation" ${SHADERC_SKIP_INSTALL})
if(NOT ${SHADERC_SKIP_INSTALL})
set(SHADERC_ENABLE_INSTALL ON)
endif()

option(SHADERC_SKIP_TESTS "Skip building tests" ${SHADERC_SKIP_TESTS})
if(NOT ${SHADERC_SKIP_TESTS})
set(SHADERC_ENABLE_TESTS ON)
Expand All @@ -14,6 +19,7 @@ else()
message(STATUS "Configuring Shaderc to avoid building tests.")
endif()

include(GNUInstallDirs)
include(cmake/setup_build.cmake)
include(cmake/utils.cmake)

Expand Down
6 changes: 4 additions & 2 deletions glslc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ shaderc_add_tests(

shaderc_add_asciidoc(glslc_doc_README README)

install(TARGETS glslc_exe
RUNTIME DESTINATION bin)
if(SHADERC_ENABLE_INSTALL)
install(TARGETS glslc_exe
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif(SHADERC_ENABLE_INSTALL)

add_subdirectory(test)
51 changes: 28 additions & 23 deletions libshaderc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ add_library(shaderc STATIC
shaderc_default_compile_options(shaderc)
target_include_directories(shaderc PUBLIC include PRIVATE ${glslang_SOURCE_DIR})

install(
FILES
include/shaderc/shaderc.h
include/shaderc/shaderc.hpp
DESTINATION
include/shaderc)
if(SHADERC_ENABLE_INSTALL)
install(
FILES
include/shaderc/shaderc.h
include/shaderc/shaderc.hpp
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/shaderc)

install(TARGETS shaderc
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif(SHADERC_ENABLE_INSTALL)

install(TARGETS shaderc
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

find_package(Threads)
target_link_libraries(shaderc PRIVATE
Expand All @@ -45,20 +48,22 @@ shaderc_add_tests(

shaderc_combine_static_lib(shaderc_combined shaderc)

# 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 lib)
else()
install(FILES ${generated_location} DESTINATION lib)
endif()
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
Expand Down
8 changes: 5 additions & 3 deletions libshaderc_util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ shaderc_default_compile_options(shaderc_util)
target_include_directories(shaderc_util
PUBLIC include PRIVATE ${glslang_SOURCE_DIR})

install(TARGETS shaderc_util
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
if(SHADERC_ENABLE_INSTALL)
install(TARGETS shaderc_util
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif(SHADERC_ENABLE_INSTALL)

find_package(Threads)
target_link_libraries(shaderc_util PRIVATE
Expand Down
4 changes: 4 additions & 0 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ set(SHADERC_SPIRV_TOOLS_DIR "${SHADERC_THIRD_PARTY_ROOT_DIR}/spirv-tools" CACHE
set(SHADERC_GLSLANG_DIR "${SHADERC_THIRD_PARTY_ROOT_DIR}/glslang" CACHE STRING
"Location of glslang source")

set( SKIP_GLSLANG_INSTALL ${SHADERC_SKIP_INSTALL} )
set( SKIP_SPIRV_TOOLS_INSTALL ${SHADERC_SKIP_INSTALL} )
set( SKIP_GOOGLETEST_INSTALL ${SHADERC_SKIP_INSTALL} )

# Configure third party projects.
if(${SHADERC_ENABLE_TESTS})
if (IS_DIRECTORY ${SHADERC_GOOGLE_TEST_DIR})
Expand Down

0 comments on commit e27569f

Please sign in to comment.