From ab6d1499e14166bd853ad29f85ad536b516760a6 Mon Sep 17 00:00:00 2001 From: James Rumble Date: Tue, 6 Aug 2019 14:47:51 +0100 Subject: [PATCH 1/2] Export glslang targets on installation This allows the targets to be used in other cmake projects. See the following for more details: https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#creating-packages https://foonathan.net/blog/2016/07/07/cmake-dependency-handling.html --- OGLCompilersDLL/CMakeLists.txt | 3 ++- SPIRV/CMakeLists.txt | 11 +++++++---- StandAlone/CMakeLists.txt | 10 +++++++--- glslang/CMakeLists.txt | 5 +++-- glslang/OSDependent/Unix/CMakeLists.txt | 3 ++- glslang/OSDependent/Windows/CMakeLists.txt | 3 ++- gtests/CMakeLists.txt | 3 ++- hlsl/CMakeLists.txt | 5 +++-- 8 files changed, 28 insertions(+), 15 deletions(-) diff --git a/OGLCompilersDLL/CMakeLists.txt b/OGLCompilersDLL/CMakeLists.txt index 5bb3f0ee..d257828d 100644 --- a/OGLCompilersDLL/CMakeLists.txt +++ b/OGLCompilersDLL/CMakeLists.txt @@ -9,6 +9,7 @@ if(WIN32) endif(WIN32) if(ENABLE_GLSLANG_INSTALL) - install(TARGETS OGLCompiler + install(TARGETS OGLCompiler EXPORT OGLCompilerTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + install(EXPORT OGLCompilerTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) endif(ENABLE_GLSLANG_INSTALL) diff --git a/SPIRV/CMakeLists.txt b/SPIRV/CMakeLists.txt index 594ab1ef..3ddf6f17 100644 --- a/SPIRV/CMakeLists.txt +++ b/SPIRV/CMakeLists.txt @@ -80,22 +80,25 @@ endif(WIN32) if(ENABLE_GLSLANG_INSTALL) if(BUILD_SHARED_LIBS) if (ENABLE_SPVREMAPPER) - install(TARGETS SPVRemapper + install(TARGETS SPVRemapper EXPORT SPVRemapperTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() - install(TARGETS SPIRV + install(TARGETS SPIRV EXPORT SPIRVTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) else() if (ENABLE_SPVREMAPPER) - install(TARGETS SPVRemapper + install(TARGETS SPVRemapper EXPORT SPVRemapperTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() - install(TARGETS SPIRV + install(TARGETS SPIRV EXPORT SPIRVTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() + + install(EXPORT SPVRemapperTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) + install(EXPORT SPIRVTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) install(FILES ${HEADERS} ${SPVREMAP_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SPIRV/) endif(ENABLE_GLSLANG_INSTALL) diff --git a/StandAlone/CMakeLists.txt b/StandAlone/CMakeLists.txt index 5cea53d9..03d64013 100644 --- a/StandAlone/CMakeLists.txt +++ b/StandAlone/CMakeLists.txt @@ -40,14 +40,18 @@ if(WIN32) endif(WIN32) if(ENABLE_GLSLANG_INSTALL) - install(TARGETS glslangValidator + install(TARGETS glslangValidator EXPORT glslangValidatorTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - install(TARGETS spirv-remap + install(TARGETS spirv-remap EXPORT spirv-remapTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + install(EXPORT glslangValidatorTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) + install(EXPORT spirv-remapTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) if(BUILD_SHARED_LIBS) - install(TARGETS glslang-default-resource-limits + install(TARGETS glslang-default-resource-limits EXPORT glslang-default-resource-limitsTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) + install(EXPORT glslang-default-resource-limitsTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) endif() endif(ENABLE_GLSLANG_INSTALL) diff --git a/glslang/CMakeLists.txt b/glslang/CMakeLists.txt index 60169fb7..9019d81d 100644 --- a/glslang/CMakeLists.txt +++ b/glslang/CMakeLists.txt @@ -106,14 +106,15 @@ endif(WIN32) if(ENABLE_GLSLANG_INSTALL) if(BUILD_SHARED_LIBS) - install(TARGETS glslang + install(TARGETS glslang EXPORT glslangTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) else() - install(TARGETS glslang + install(TARGETS glslang EXPORT glslangTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() + install(EXPORT glslangTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) endif(ENABLE_GLSLANG_INSTALL) if(ENABLE_GLSLANG_INSTALL) diff --git a/glslang/OSDependent/Unix/CMakeLists.txt b/glslang/OSDependent/Unix/CMakeLists.txt index e652f456..4a434ef5 100644 --- a/glslang/OSDependent/Unix/CMakeLists.txt +++ b/glslang/OSDependent/Unix/CMakeLists.txt @@ -20,6 +20,7 @@ else() endif() if(ENABLE_GLSLANG_INSTALL) - install(TARGETS OSDependent + install(TARGETS OSDependent EXPORT OSDependentTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + install(EXPORT OSDependentTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) endif(ENABLE_GLSLANG_INSTALL) diff --git a/glslang/OSDependent/Windows/CMakeLists.txt b/glslang/OSDependent/Windows/CMakeLists.txt index f257418a..321fd4f3 100644 --- a/glslang/OSDependent/Windows/CMakeLists.txt +++ b/glslang/OSDependent/Windows/CMakeLists.txt @@ -15,6 +15,7 @@ if(WIN32) endif(WIN32) if(ENABLE_GLSLANG_INSTALL) - install(TARGETS OSDependent + install(TARGETS OSDependent EXPORT OSDependentTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + install(EXPORT OSDependentTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) endif(ENABLE_GLSLANG_INSTALL) diff --git a/gtests/CMakeLists.txt b/gtests/CMakeLists.txt index f678cb6e..6e574433 100644 --- a/gtests/CMakeLists.txt +++ b/gtests/CMakeLists.txt @@ -31,8 +31,9 @@ if(BUILD_TESTING) set_property(TARGET glslangtests PROPERTY FOLDER tests) glslang_set_link_args(glslangtests) if(ENABLE_GLSLANG_INSTALL) - install(TARGETS glslangtests + install(TARGETS glslangtests EXPORT glslangtestsTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + install(EXPORT glslangtestsTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) endif(ENABLE_GLSLANG_INSTALL) set(GLSLANG_TEST_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../Test") diff --git a/hlsl/CMakeLists.txt b/hlsl/CMakeLists.txt index 7436dde6..70cd28ef 100644 --- a/hlsl/CMakeLists.txt +++ b/hlsl/CMakeLists.txt @@ -33,12 +33,13 @@ endif(WIN32) if(ENABLE_GLSLANG_INSTALL) if(BUILD_SHARED_LIBS) - install(TARGETS HLSL + install(TARGETS HLSL EXPORT HLSLTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) else() - install(TARGETS HLSL + install(TARGETS HLSL EXPORT HLSLTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() + install(EXPORT HLSLTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) endif(ENABLE_GLSLANG_INSTALL) From c6f7294ced80732d81011e4037dcb28040f949c9 Mon Sep 17 00:00:00 2001 From: James Rumble Date: Tue, 6 Aug 2019 15:29:31 +0100 Subject: [PATCH 2/2] Handle install vs build include directories Fix target_include_directories to appropriately handle build-tree and the install-tree. --- OGLCompilersDLL/CMakeLists.txt | 2 +- SPIRV/CMakeLists.txt | 12 ++++++++---- StandAlone/CMakeLists.txt | 10 ++++++---- glslang/CMakeLists.txt | 6 ++++-- glslang/OSDependent/Unix/CMakeLists.txt | 2 +- glslang/OSDependent/Windows/CMakeLists.txt | 2 +- gtests/CMakeLists.txt | 2 +- hlsl/CMakeLists.txt | 2 +- 8 files changed, 23 insertions(+), 15 deletions(-) diff --git a/OGLCompilersDLL/CMakeLists.txt b/OGLCompilersDLL/CMakeLists.txt index d257828d..af4ab587 100644 --- a/OGLCompilersDLL/CMakeLists.txt +++ b/OGLCompilersDLL/CMakeLists.txt @@ -11,5 +11,5 @@ endif(WIN32) if(ENABLE_GLSLANG_INSTALL) install(TARGETS OGLCompiler EXPORT OGLCompilerTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - install(EXPORT OGLCompilerTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) + install(EXPORT OGLCompilerTargets DESTINATION lib/cmake) endif(ENABLE_GLSLANG_INSTALL) diff --git a/SPIRV/CMakeLists.txt b/SPIRV/CMakeLists.txt index 3ddf6f17..94db899d 100644 --- a/SPIRV/CMakeLists.txt +++ b/SPIRV/CMakeLists.txt @@ -46,7 +46,9 @@ endif(ENABLE_NV_EXTENSIONS) add_library(SPIRV ${LIB_TYPE} ${SOURCES} ${HEADERS}) set_property(TARGET SPIRV PROPERTY FOLDER glslang) set_property(TARGET SPIRV PROPERTY POSITION_INDEPENDENT_CODE ON) -target_include_directories(SPIRV PUBLIC ..) +target_include_directories(SPIRV PUBLIC + $ + $) if (ENABLE_SPVREMAPPER) add_library(SPVRemapper ${LIB_TYPE} ${SPVREMAP_SOURCES} ${SPVREMAP_HEADERS}) @@ -67,7 +69,9 @@ if(ENABLE_OPT) PRIVATE ${spirv-tools_SOURCE_DIR}/source ) target_link_libraries(SPIRV glslang SPIRV-Tools-opt) - target_include_directories(SPIRV PUBLIC ../External) + target_include_directories(SPIRV PUBLIC + $ + $) else() target_link_libraries(SPIRV glslang) endif(ENABLE_OPT) @@ -97,8 +101,8 @@ if(ENABLE_GLSLANG_INSTALL) ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() - install(EXPORT SPVRemapperTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) - install(EXPORT SPIRVTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) + install(EXPORT SPVRemapperTargets DESTINATION lib/cmake) + install(EXPORT SPIRVTargets DESTINATION lib/cmake) install(FILES ${HEADERS} ${SPVREMAP_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SPIRV/) endif(ENABLE_GLSLANG_INSTALL) diff --git a/StandAlone/CMakeLists.txt b/StandAlone/CMakeLists.txt index 03d64013..89e91c01 100644 --- a/StandAlone/CMakeLists.txt +++ b/StandAlone/CMakeLists.txt @@ -33,7 +33,9 @@ endif(WIN32) target_link_libraries(glslangValidator ${LIBRARIES}) target_link_libraries(spirv-remap ${LIBRARIES}) -target_include_directories(glslangValidator PUBLIC ../External) +target_include_directories(glslangValidator PUBLIC + $ + $) if(WIN32) source_group("Source" FILES ${SOURCES}) @@ -46,12 +48,12 @@ if(ENABLE_GLSLANG_INSTALL) install(TARGETS spirv-remap EXPORT spirv-remapTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - install(EXPORT glslangValidatorTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) - install(EXPORT spirv-remapTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) + install(EXPORT glslangValidatorTargets DESTINATION lib/cmake) + install(EXPORT spirv-remapTargets DESTINATION lib/cmake) if(BUILD_SHARED_LIBS) install(TARGETS glslang-default-resource-limits EXPORT glslang-default-resource-limitsTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) - install(EXPORT glslang-default-resource-limitsTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) + install(EXPORT glslang-default-resource-limitsTargets DESTINATION lib/cmake) endif() endif(ENABLE_GLSLANG_INSTALL) diff --git a/glslang/CMakeLists.txt b/glslang/CMakeLists.txt index 9019d81d..9507ef04 100644 --- a/glslang/CMakeLists.txt +++ b/glslang/CMakeLists.txt @@ -86,7 +86,9 @@ add_library(glslang ${LIB_TYPE} ${BISON_GLSLParser_OUTPUT_SOURCE} ${SOURCES} ${H set_property(TARGET glslang PROPERTY FOLDER glslang) set_property(TARGET glslang PROPERTY POSITION_INDEPENDENT_CODE ON) target_link_libraries(glslang OGLCompiler OSDependent) -target_include_directories(glslang PUBLIC ..) +target_include_directories(glslang PUBLIC + $ + $) if(WIN32 AND BUILD_SHARED_LIBS) set_target_properties(glslang PROPERTIES PREFIX "") @@ -114,7 +116,7 @@ if(ENABLE_GLSLANG_INSTALL) install(TARGETS glslang EXPORT glslangTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() - install(EXPORT glslangTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) + install(EXPORT glslangTargets DESTINATION lib/cmake) endif(ENABLE_GLSLANG_INSTALL) if(ENABLE_GLSLANG_INSTALL) diff --git a/glslang/OSDependent/Unix/CMakeLists.txt b/glslang/OSDependent/Unix/CMakeLists.txt index 4a434ef5..91fb45a7 100644 --- a/glslang/OSDependent/Unix/CMakeLists.txt +++ b/glslang/OSDependent/Unix/CMakeLists.txt @@ -22,5 +22,5 @@ endif() if(ENABLE_GLSLANG_INSTALL) install(TARGETS OSDependent EXPORT OSDependentTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - install(EXPORT OSDependentTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) + install(EXPORT OSDependentTargets DESTINATION lib/cmake) endif(ENABLE_GLSLANG_INSTALL) diff --git a/glslang/OSDependent/Windows/CMakeLists.txt b/glslang/OSDependent/Windows/CMakeLists.txt index 321fd4f3..f6bd4e9d 100644 --- a/glslang/OSDependent/Windows/CMakeLists.txt +++ b/glslang/OSDependent/Windows/CMakeLists.txt @@ -17,5 +17,5 @@ endif(WIN32) if(ENABLE_GLSLANG_INSTALL) install(TARGETS OSDependent EXPORT OSDependentTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - install(EXPORT OSDependentTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) + install(EXPORT OSDependentTargets DESTINATION lib/cmake) endif(ENABLE_GLSLANG_INSTALL) diff --git a/gtests/CMakeLists.txt b/gtests/CMakeLists.txt index 6e574433..77d217f1 100644 --- a/gtests/CMakeLists.txt +++ b/gtests/CMakeLists.txt @@ -33,7 +33,7 @@ if(BUILD_TESTING) if(ENABLE_GLSLANG_INSTALL) install(TARGETS glslangtests EXPORT glslangtestsTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - install(EXPORT glslangtestsTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) + install(EXPORT glslangtestsTargets DESTINATION lib/cmake) endif(ENABLE_GLSLANG_INSTALL) set(GLSLANG_TEST_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../Test") diff --git a/hlsl/CMakeLists.txt b/hlsl/CMakeLists.txt index 70cd28ef..44f9d6a2 100644 --- a/hlsl/CMakeLists.txt +++ b/hlsl/CMakeLists.txt @@ -41,5 +41,5 @@ if(ENABLE_GLSLANG_INSTALL) install(TARGETS HLSL EXPORT HLSLTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() - install(EXPORT HLSLTargets DESTINATION ${LIB_INSTALL_DIR}/cmake) + install(EXPORT HLSLTargets DESTINATION lib/cmake) endif(ENABLE_GLSLANG_INSTALL)