diff --git a/CMakeLists.txt b/CMakeLists.txt index a4c2facb0..b9bd0df1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) diff --git a/glslc/CMakeLists.txt b/glslc/CMakeLists.txt index 8f21aa2b2..acf6fb0b2 100644 --- a/glslc/CMakeLists.txt +++ b/glslc/CMakeLists.txt @@ -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) diff --git a/libshaderc/CMakeLists.txt b/libshaderc/CMakeLists.txt index 62060945b..6b91fceaf 100644 --- a/libshaderc/CMakeLists.txt +++ b/libshaderc/CMakeLists.txt @@ -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 @@ -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 diff --git a/libshaderc_util/CMakeLists.txt b/libshaderc_util/CMakeLists.txt index 196edafd6..e63645228 100644 --- a/libshaderc_util/CMakeLists.txt +++ b/libshaderc_util/CMakeLists.txt @@ -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 diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 9702712bd..ace4e3100 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -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})