From 2a4b11e0e7fbe76ca5d1050a6b3a9a15a09f6c51 Mon Sep 17 00:00:00 2001 From: sL1pKn07 Date: Tue, 12 Oct 2021 15:03:09 +0200 Subject: [PATCH] Attemp to fix https://github.com/KhronosGroup/SPIRV-Tools/issues/3909 - Try to fix the point (1). - Build static unconditionally. but is only used for link all `spirv-foo` programs. because all of them (or partial) need all symbols which is only provided by static libs. for install it. see below This can increase the size a bit. - Now exist two defines witch control what type of library is installed/builded*: - `SPIRV_TOOLS_BUILD_SHARED_LIBS` -> this control if you want build shared libs. and if is builded, install it when invoke `make install` - `SPIRV_TOOLS_INSTALL_STATIC_LIBS` -> this not control the build static library (because is ON unconditionality), but can control the installation when invoke `make install` -- I do this because some distros needs only static libs, other only shared libs, other both, or other simply what install only the programs --- Table of individual use: `SPIRV_TOOLS_BUILD_SHARED_LIBS` not set -> Disable build and installation of shared libraries `SPIRV_TOOLS_BUILD_SHARED_LIBS=ON' -> Enable build and install shared libs `SPIRV_TOOLS_INSTALL_STATIC_LIBS` not set -> Enable by default. enable the installation the libraries when invoke `make install` `SPIRV_TOOLS_INSTALL_STATIC_LIBS=ON` -> Same as not set --- Table of conjuntion use: `SPIRV_TOOLS_BUILD_SHARED_LIBS=ON' and `SPIRV_TOOLS_INSTALL_STATIC_LIBS=ON` -> Build and install the wrole project. include programs, static and shared libs `SPIRV_TOOLS_BUILD_SHARED_LIBS=OFF' and `SPIRV_TOOLS_INSTALL_STATIC_LIBS=ON` -> Build the programs and static libs, and install the static libs and the programs when invoke `make install` (Default) `SPIRV_TOOLS_BUILD_SHARED_LIBS=ON' and `SPIRV_TOOLS_INSTALL_STATIC_LIBS=OFF` -> build the programs, shared and static libs, and only install the programs and the shared libs when invoke `make install` `SPIRV_TOOLS_BUILD_SHARED_LIBS=OFF' and `SPIRV_TOOLS_INSTALL_STATIC_LIBS=OFF` -> build the programs and the static libs, but not install when invoke `make install` * In all cases, always install the headers - The generation of the `.cmake` files is changed. now generate two flavors: one for static (without any sufix), and other for shared (whit `shared` sufix). both can install with the two defines described above. (and not colided between both) -- This need HARD test. this need a CMakeLists.txt test case wich can get the info when use static libs or use shared libs. and test if can linked with other things. I have desing this for can coinstall shared and static in same time, an let the user what need in your project. cmake can search one or other with only need add `STATIC` or `SHARED` in the `findpackage(FOO >TYPE<)`. - The files `libSPIRV-Tools-shared.so` and `SPIRV-Tools-shared.pc` is completely gone. no need anymore. is a duplicate lib when build shared libs, and useless whe build static libs (who ise a shared lib when the dev use static libs?) - By design, the common `SPIRV-Tools.pc` can be used in both build modes. the `pkg-config` stack can handle the information of static libs with `--static` flag when exist static libs in the library path, and normal use when is used as shared lib. Maybe need ajust for include this information (if exist in the project) into `SPIRV-Tools.pc.in` and setup in the `CMakeFiles.txt`. - The visiblility of the shared/static libs is untouched: Hiden for `libSPIRV-Tools.so` and full visible for static.. the other libs originally have ones hiden and other full visible. i leave it untouch. but need test if is all ok. TODO: - Fix point (2) and point (3) - Point (4) is out of my scope. i'm not coder --- CMakeLists.txt | 80 ++++++--------------- cmake/SPIRV-Tools-shared.pc.in | 12 ---- external/CMakeLists.txt | 13 +++- source/CMakeLists.txt | 123 ++++++++++++++++++++------------- source/fuzz/CMakeLists.txt | 78 +++++++++++++++------ source/link/CMakeLists.txt | 76 ++++++++++++++------ source/lint/CMakeLists.txt | 88 +++++++++++++++-------- source/opt/CMakeLists.txt | 77 +++++++++++++++------ source/reduce/CMakeLists.txt | 84 +++++++++++++++------- test/CMakeLists.txt | 12 ++-- 10 files changed, 401 insertions(+), 242 deletions(-) delete mode 100644 cmake/SPIRV-Tools-shared.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 01e3b16f549..2333641197e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,45 +139,10 @@ if (DEFINED SPIRV_TOOLS_EXTRA_DEFINITIONS) add_definitions(${SPIRV_TOOLS_EXTRA_DEFINITIONS}) endif() -# Library build setting definitions: -# -# * SPIRV_TOOLS_BUILD_STATIC - ON or OFF - Defaults to ON. -# If enabled the following targets will be created: -# ${SPIRV_TOOLS}-static - STATIC library. -# Has full public symbol visibility. -# ${SPIRV_TOOLS}-shared - SHARED library. -# Has default-hidden symbol visibility. -# ${SPIRV_TOOLS} - will alias to one of above, based on BUILD_SHARED_LIBS. -# If disabled the following targets will be created: -# ${SPIRV_TOOLS} - either STATIC or SHARED based on SPIRV_TOOLS_LIBRARY_TYPE. -# Has full public symbol visibility. -# ${SPIRV_TOOLS}-shared - SHARED library. -# Has default-hidden symbol visibility. -# -# * SPIRV_TOOLS_LIBRARY_TYPE - SHARED or STATIC. -# Specifies the library type used for building SPIRV-Tools libraries. -# Defaults to SHARED when BUILD_SHARED_LIBS=1, otherwise STATIC. -# -# * SPIRV_TOOLS_FULL_VISIBILITY - "${SPIRV_TOOLS}-static" or "${SPIRV_TOOLS}" -# Evaluates to the SPIRV_TOOLS target library name that has no hidden symbols. -# This is used by internal targets for accessing symbols that are non-public. -# Note this target provides no API stability guarantees. -# -# Ideally, all of these will go away - see https://github.com/KhronosGroup/SPIRV-Tools/issues/3909. -option(SPIRV_TOOLS_BUILD_STATIC "Build ${SPIRV_TOOLS}-static target. ${SPIRV_TOOLS} will alias to ${SPIRV_TOOLS}-static or ${SPIRV_TOOLS}-shared based on BUILD_SHARED_LIBS" ON) -if(SPIRV_TOOLS_BUILD_STATIC) - set(SPIRV_TOOLS_FULL_VISIBILITY ${SPIRV_TOOLS}-static) - set(SPIRV_TOOLS_LIBRARY_TYPE "STATIC") -else(SPIRV_TOOLS_BUILD_STATIC) - set(SPIRV_TOOLS_FULL_VISIBILITY ${SPIRV_TOOLS}) - if (NOT DEFINED SPIRV_TOOLS_LIBRARY_TYPE) - if(BUILD_SHARED_LIBS) - set(SPIRV_TOOLS_LIBRARY_TYPE "SHARED") - else() - set(SPIRV_TOOLS_LIBRARY_TYPE "STATIC") - endif() - endif() -endif(SPIRV_TOOLS_BUILD_STATIC) +option(SPIRV_TOOLS_INSTALL_STATIC_LIBS "Enable static libs" ON) +option(SPIRV_TOOLS_BUILD_SHARED_LIBS "Enable shared libs" OFF) + +set(SPIRV_TOOLS_FULL_VISIBILITY ${SPIRV_TOOLS}) function(spvtools_default_compile_options TARGET) target_compile_options(${TARGET} PRIVATE ${SPIRV_WARNINGS}) @@ -276,9 +241,17 @@ if(ENABLE_SPIRV_TOOLS_INSTALL) file(WRITE ${CMAKE_BINARY_DIR}/${TARGET}Config.cmake "include(CMakeFindDependencyMacro)\n" "find_dependency(${SPIRV_TOOLS})\n" - "include(\${CMAKE_CURRENT_LIST_DIR}/${TARGET}Targets.cmake)\n" + "get_target_property(target_type ${TARGET} TYPE)\n" + "if (target_type STREQUAL STATIC_LIBRARY)\n" + "include(\${CMAKE_CURRENT_LIST_DIR}/${TARGET}-staticTargets.cmake)\n" "set(${TARGET}_LIBRARIES ${TARGET})\n" - "get_target_property(${TARGET}_INCLUDE_DIRS ${TARGET} INTERFACE_INCLUDE_DIRECTORIES)\n") + "get_target_property(${TARGET}_INCLUDE_DIRS ${TARGET} INTERFACE_INCLUDE_DIRECTORIES)\n" + "endif()\n" + "if (target_type STREQUAL SHARED_LIBRARY)\n" + "include(\${CMAKE_CURRENT_LIST_DIR}/${TARGET}-sharedTargets.cmake)\n" + "set(${TARGET}_LIBRARIES ${TARGET}-shared)\n" + "get_target_property(${TARGET}_INCLUDE_DIRS ${TARGET}-shared INTERFACE_INCLUDE_DIRECTORIES)\n" + "endif()\n") endmacro() endif() @@ -353,7 +326,6 @@ if (NOT "${SPIRV_SKIP_TESTS}") endif() set(SPIRV_LIBRARIES "-lSPIRV-Tools-opt -lSPIRV-Tools -lSPIRV-Tools-link") -set(SPIRV_SHARED_LIBRARIES "-lSPIRV-Tools-shared") # Build pkg-config file # Use a first-class target so it's regenerated when relevant files are updated. @@ -368,24 +340,14 @@ add_custom_target(spirv-tools-pkg-config ALL -DSPIRV_LIBRARIES=${SPIRV_LIBRARIES} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/write_pkg_config.cmake DEPENDS "CHANGES" "cmake/SPIRV-Tools.pc.in" "cmake/write_pkg_config.cmake") -add_custom_target(spirv-tools-shared-pkg-config ALL - COMMAND ${CMAKE_COMMAND} - -DCHANGES_FILE=${CMAKE_CURRENT_SOURCE_DIR}/CHANGES - -DTEMPLATE_FILE=${CMAKE_CURRENT_SOURCE_DIR}/cmake/SPIRV-Tools-shared.pc.in - -DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools-shared.pc - -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} - -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} - -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR} - -DSPIRV_SHARED_LIBRARIES=${SPIRV_SHARED_LIBRARIES} - -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/write_pkg_config.cmake - DEPENDS "CHANGES" "cmake/SPIRV-Tools-shared.pc.in" "cmake/write_pkg_config.cmake") # Install pkg-config file if (ENABLE_SPIRV_TOOLS_INSTALL) - install( - FILES - ${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools.pc - ${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools-shared.pc - DESTINATION - ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + if(SPIRV_TOOLS_BUILD_SHARED_LIBS OR SPIRV_TOOLS_INSTALL_STATIC_LIBS) + install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools.pc + DESTINATION + ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + endif() endif() diff --git a/cmake/SPIRV-Tools-shared.pc.in b/cmake/SPIRV-Tools-shared.pc.in deleted file mode 100644 index 0dcaa27644b..00000000000 --- a/cmake/SPIRV-Tools-shared.pc.in +++ /dev/null @@ -1,12 +0,0 @@ -prefix=@CMAKE_INSTALL_PREFIX@ -exec_prefix=${prefix} -libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ -includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ - -Name: SPIRV-Tools -Description: Tools for SPIR-V -Version: @CURRENT_VERSION@ -URL: https://github.com/KhronosGroup/SPIRV-Tools - -Libs: -L${libdir} @SPIRV_SHARED_LIBRARIES@ -Cflags: -I${includedir} diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 179a4012f94..27952c9d39e 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -74,9 +74,10 @@ if (NOT ${SPIRV_SKIP_TESTS}) "Use shared (DLL) run-time lib even when Google Test is built as static lib." ON) endif() - # gtest requires special defines for building as a shared + # Gtest requires special defines for building as a shared # library, simply always build as static. push_variable(BUILD_SHARED_LIBS 0) + set(BUILD_SHARED_LIBS OFF CACHE BOOL "Disable build shared libs") add_subdirectory(${GMOCK_DIR} EXCLUDE_FROM_ALL) pop_variable(BUILD_SHARED_LIBS) endif() @@ -102,7 +103,10 @@ if (NOT ${SPIRV_SKIP_TESTS}) # If we are configuring RE2, then turn off its testing. It takes a long time and # does not add much value for us. If an enclosing project configured RE2, then it # has already chosen whether to enable RE2 testing. - set(RE2_BUILD_TESTING OFF CACHE STRING "Run RE2 Tests") + set(RE2_BUILD_TESTING OFF CACHE BOOL "Run RE2 Tests") + # Build static RE2. do less problems if run the test when you have already RE2 + # in the system and have different library version. + set(BUILD_SHARED_LIBS OFF CACHE BOOL "Disable build shared libs") if (NOT RE2_SOURCE_DIR) if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/re2) set(RE2_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/re2" CACHE STRING "RE2 source dir" ) @@ -125,7 +129,10 @@ if (NOT ${SPIRV_SKIP_TESTS}) if (NOT TARGET effcee) set(EFFCEE_BUILD_TESTING OFF CACHE BOOL "Do not build Effcee test suite") endif() - push_variable(BUILD_SHARED_LIBS 0) # effcee does not export any symbols for building as a DLL. Always build as static. + # Effcee does not export any symbols for building as a DLL. Always build as static. + push_variable(BUILD_SHARED_LIBS 0) + # Expands this if include RE2 in the effcee third_party folder + set(BUILD_SHARED_LIBS OFF CACHE BOOL "Disable build shared libs") add_subdirectory(effcee EXCLUDE_FROM_ALL) pop_variable(BUILD_SHARED_LIBS) set_property(TARGET effcee PROPERTY FOLDER Effcee) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 898fcfd3c37..3b88db216c9 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -351,6 +351,11 @@ set_source_files_properties( ${CMAKE_CURRENT_SOURCE_DIR}/software_version.cpp PROPERTIES OBJECT_DEPENDS "${SPIRV_TOOLS_BUILD_VERSION_INC}") +if(MSVC AND (NOT ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))) + # Enable parallel builds across four cores for this lib + add_definitions(/MP4) +endif() + spvtools_pch(SPIRV_SOURCES pch_source) # spirv_tools_default_target_options() sets the target options that are common @@ -369,37 +374,26 @@ function(spirv_tools_default_target_options target) add_dependencies(${target} spirv-tools-build-version core_tables enum_string_mapping extinst_tables) endfunction() -# Always build ${SPIRV_TOOLS}-shared. This is expected distro packages, and -# unlike the other SPIRV_TOOLS target, defaults to hidden symbol visibility. -add_library(${SPIRV_TOOLS}-shared SHARED ${SPIRV_SOURCES}) -spirv_tools_default_target_options(${SPIRV_TOOLS}-shared) -set_target_properties(${SPIRV_TOOLS}-shared PROPERTIES CXX_VISIBILITY_PRESET hidden) -target_compile_definitions(${SPIRV_TOOLS}-shared - PRIVATE SPIRV_TOOLS_IMPLEMENTATION - PUBLIC SPIRV_TOOLS_SHAREDLIB -) - -if(SPIRV_TOOLS_BUILD_STATIC) - add_library(${SPIRV_TOOLS}-static STATIC ${SPIRV_SOURCES}) - spirv_tools_default_target_options(${SPIRV_TOOLS}-static) - # The static target does not have the '-static' suffix. - set_target_properties(${SPIRV_TOOLS}-static PROPERTIES OUTPUT_NAME "${SPIRV_TOOLS}") - - # Create the "${SPIRV_TOOLS}" target as an alias to either "${SPIRV_TOOLS}-static" - # or "${SPIRV_TOOLS}-shared" depending on the value of BUILD_SHARED_LIBS. - if(BUILD_SHARED_LIBS) - add_library(${SPIRV_TOOLS} ALIAS ${SPIRV_TOOLS}-shared) - else() - add_library(${SPIRV_TOOLS} ALIAS ${SPIRV_TOOLS}-static) - endif() - - set(SPIRV_TOOLS_TARGETS ${SPIRV_TOOLS}-static ${SPIRV_TOOLS}-shared) -else() - add_library(${SPIRV_TOOLS} ${SPIRV_TOOLS_LIBRARY_TYPE} ${SPIRV_SOURCES}) - spirv_tools_default_target_options(${SPIRV_TOOLS}) - set(SPIRV_TOOLS_TARGETS ${SPIRV_TOOLS} ${SPIRV_TOOLS}-shared) +add_library(${SPIRV_TOOLS} STATIC ${SPIRV_SOURCES}) +if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + add_library(${SPIRV_TOOLS}-shared SHARED ${SPIRV_SOURCES}) + set_target_properties(${SPIRV_TOOLS}-shared PROPERTIES CXX_VISIBILITY_PRESET hidden) + target_compile_definitions(${SPIRV_TOOLS}-shared + PRIVATE SPIRV_TOOLS_IMPLEMENTATION + PUBLIC SPIRV_TOOLS_SHAREDLIB + ) + set(SPIRV_TOOLS_SHARED ${SPIRV_TOOLS}-shared) endif() +set(SPIRV_TOOLS_DEFAUL_TARGET_OPTIONS ${SPIRV_TOOLS} ${SPIRV_TOOLS_SHARED}) + +foreach(target ${SPIRV_TOOLS_DEFAUL_TARGET_OPTIONS}) + spirv_tools_default_target_options(${target}) +endforeach() + +set(SPIRV_TOOLS_TARGETS ${SPIRV_TOOLS} ${SPIRV_TOOLS_SHARED}) +set(SPIRV_TOOLS_FULL_VISIBILITY ${SPIRV_TOOLS}) + if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") find_library(LIBRT rt) if(LIBRT) @@ -416,24 +410,55 @@ if (ANDROID) endif() if(ENABLE_SPIRV_TOOLS_INSTALL) - install(TARGETS ${SPIRV_TOOLS_TARGETS} EXPORT ${SPIRV_TOOLS}Targets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - export(EXPORT ${SPIRV_TOOLS}Targets FILE ${SPIRV_TOOLS}Target.cmake) - - spvtools_config_package_dir(${SPIRV_TOOLS} PACKAGE_DIR) - install(EXPORT ${SPIRV_TOOLS}Targets FILE ${SPIRV_TOOLS}Target.cmake DESTINATION ${PACKAGE_DIR}) - - # Special config file for root library compared to other libs. - file(WRITE ${CMAKE_BINARY_DIR}/${SPIRV_TOOLS}Config.cmake - "include(\${CMAKE_CURRENT_LIST_DIR}/${SPIRV_TOOLS}Target.cmake)\n" - "set(${SPIRV_TOOLS}_LIBRARIES ${SPIRV_TOOLS})\n" - "get_target_property(${SPIRV_TOOLS}_INCLUDE_DIRS ${SPIRV_TOOLS} INTERFACE_INCLUDE_DIRECTORIES)\n") - install(FILES ${CMAKE_BINARY_DIR}/${SPIRV_TOOLS}Config.cmake DESTINATION ${PACKAGE_DIR}) -endif(ENABLE_SPIRV_TOOLS_INSTALL) + if(SPIRV_TOOLS_INSTALL_STATIC_LIBS) + install(TARGETS ${SPIRV_TOOLS} EXPORT ${SPIRV_TOOLS}-Targets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + export(EXPORT ${SPIRV_TOOLS}-Targets FILE ${SPIRV_TOOLS}Targets.cmake) + + spvtools_config_package_dir(${SPIRV_TOOLS} PACKAGE_DIR) + install(EXPORT ${SPIRV_TOOLS}-Targets FILE ${SPIRV_TOOLS}Targets.cmake DESTINATION ${PACKAGE_DIR}) + + # Special config file for root library compared to other libs. + file(WRITE ${CMAKE_BINARY_DIR}/${SPIRV_TOOLS}Config.cmake + "get_target_property(target_type \${TARGET} TYPE)\n" + "if (target_type STREQUAL STATIC_LIBRARY)\n" + "include(\${CMAKE_CURRENT_LIST_DIR}/${SPIRV_TOOLS}Targets.cmake)\n" + "get_target_property(${SPIRV_TOOLS}_INCLUDE_DIRS ${SPIRV_TOOLS} INTERFACE_INCLUDE_DIRECTORIES)\n" + "endif()\n" + "if (target_type STREQUAL SHARED_LIBRARY)\n" + "include(\${CMAKE_CURRENT_LIST_DIR}/${SPIRV_TOOLS}-sharedTargets.cmake)\n" + "set(${SPIRV_TOOLS}_LIBRARIES ${SPIRV_TOOLS}-shared)\n" + "get_target_property(${SPIRV_TOOLS}_INCLUDE_DIRS ${SPIRV_TOOLS}-shared INTERFACE_INCLUDE_DIRECTORIES)\n" + "endif()\n") + install(FILES ${CMAKE_BINARY_DIR}/${SPIRV_TOOLS}Config.cmake DESTINATION ${PACKAGE_DIR}) + endif() -if(MSVC AND (NOT ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))) - # Enable parallel builds across four cores for this lib - add_definitions(/MP4) -endif() + if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + set_target_properties(${SPIRV_TOOLS}-shared PROPERTIES OUTPUT_NAME ${SPIRV_TOOLS}) + set_target_properties(${SPIRV_TOOLS}-shared PROPERTIES EXPORT_NAME ${SPIRV_TOOLS}) + install(TARGETS ${SPIRV_TOOLS}-shared EXPORT ${SPIRV_TOOLS}-Targets-shared + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + export(EXPORT ${SPIRV_TOOLS}-Targets-shared FILE ${SPIRV_TOOLS}-sharedTargets.cmake) + + spvtools_config_package_dir(${SPIRV_TOOLS} PACKAGE_DIR) + install(EXPORT ${SPIRV_TOOLS}-Targets-shared FILE ${SPIRV_TOOLS}-sharedTargets.cmake DESTINATION ${PACKAGE_DIR}) + + # Special config file for root library compared to other libs. + file(WRITE ${CMAKE_BINARY_DIR}/${SPIRV_TOOLS}Config.cmake + "get_target_property(target_type ${SPIRV_TOOLS} TYPE)\n" + "if (target_type STREQUAL STATIC_LIBRARY)\n" + "include(\${CMAKE_CURRENT_LIST_DIR}/${SPIRV_TOOLS}Targets.cmake)\n" + "get_target_property(${SPIRV_TOOLS}_INCLUDE_DIRS ${SPIRV_TOOLS} INTERFACE_INCLUDE_DIRECTORIES)\n" + "endif()\n" + "if (target_type STREQUAL SHARED_LIBRARY)\n" + "include(\${CMAKE_CURRENT_LIST_DIR}/${SPIRV_TOOLS}-sharedTargets.cmake)\n" + "set(${SPIRV_TOOLS}_LIBRARIES ${SPIRV_TOOLS}-shared)\n" + "get_target_property(${SPIRV_TOOLS}_INCLUDE_DIRS ${SPIRV_TOOLS}-shared INTERFACE_INCLUDE_DIRECTORIES)\n" + "endif()\n") + install(FILES ${CMAKE_BINARY_DIR}/${SPIRV_TOOLS}Config.cmake DESTINATION ${PACKAGE_DIR}) + endif() +endif(ENABLE_SPIRV_TOOLS_INSTALL) diff --git a/source/fuzz/CMakeLists.txt b/source/fuzz/CMakeLists.txt index dd674dd04c8..2e1009f2927 100644 --- a/source/fuzz/CMakeLists.txt +++ b/source/fuzz/CMakeLists.txt @@ -438,9 +438,14 @@ if(SPIRV_BUILD_FUZZER) spvtools_pch(SPIRV_TOOLS_FUZZ_SOURCES pch_source_fuzz) - add_library(SPIRV-Tools-fuzz ${SPIRV_TOOLS_FUZZ_SOURCES}) + add_library(SPIRV-Tools-fuzz STATIC ${SPIRV_TOOLS_FUZZ_SOURCES}) - spvtools_default_compile_options(SPIRV-Tools-fuzz) + if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + add_library(SPIRV-Tools-fuzz-shared SHARED ${SPIRV_TOOLS_FUZZ_SOURCES}) + set(SPIRV_TOOLS_FUZZ_SHARED SPIRV-Tools-fuzz-shared) + endif() + + spvtools_default_compile_options(SPIRV-Tools-fuzz ${SPIRV_TOOLS_FUZZ_SHARED}) # Compilation of the auto-generated protobuf source file will yield warnings, # which we have no control over and thus wish to ignore. @@ -451,37 +456,68 @@ if(SPIRV_BUILD_FUZZER) set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/protobufs/spvtoolsfuzz.pb.cc PROPERTIES COMPILE_FLAGS /w) endif() - target_include_directories(SPIRV-Tools-fuzz - PUBLIC - $ - $ - $ - PRIVATE ${spirv-tools_BINARY_DIR} - PRIVATE ${CMAKE_BINARY_DIR}) + set(SPIRV_TOOLS_LINK_TARGET SPIRV-Tools-fuzz ${SPIRV_TOOLS_FUZZ_SHARED}) + + foreach(target ${SPIRV_TOOLS_FUZZ_TARGET}) + target_include_directories(${target} + PUBLIC + $ + $ + $ + PRIVATE ${spirv-tools_BINARY_DIR} + PRIVATE ${CMAKE_BINARY_DIR}) + endforeach() # The fuzzer reuses a lot of functionality from the SPIRV-Tools library. target_link_libraries(SPIRV-Tools-fuzz - PUBLIC ${SPIRV_TOOLS_FULL_VISIBILITY} - PUBLIC SPIRV-Tools-opt - PUBLIC SPIRV-Tools-reduce - PUBLIC protobuf::libprotobuf) + PUBLIC ${SPIRV_TOOLS_FULL_VISIBILITY} + PUBLIC SPIRV-Tools-opt + PUBLIC SPIRV-Tools-reduce + PUBLIC protobuf::libprotobuf) + + if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + target_link_libraries(SPIRV-Tools-fuzz-shared + PUBLIC ${SPIRV_TOOLS_FULL_VISIBILITY}-shared + PUBLIC SPIRV-Tools-opt-shared + PUBLIC SPIRV-Tools-reduce-shared + PUBLIC protobuf::libprotobuf) + endif() - set_property(TARGET SPIRV-Tools-fuzz PROPERTY FOLDER "SPIRV-Tools libraries") - spvtools_check_symbol_exports(SPIRV-Tools-fuzz) + set_property(TARGET SPIRV-Tools-fuzz ${SPIRV_TOOLS_FUZZ_SHARED} PROPERTY FOLDER "SPIRV-Tools libraries") + spvtools_check_symbol_exports(SPIRV-Tools-fuzz ${SPIRV_TOOLS_FUZZ_SHARED}) if(ENABLE_SPIRV_TOOLS_INSTALL) + if(SPIRV_TOOLS_INSTALL_STATIC_LIBS) install(TARGETS SPIRV-Tools-fuzz EXPORT SPIRV-Tools-fuzzTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - export(EXPORT SPIRV-Tools-fuzzTargets FILE SPIRV-Tools-fuzzTarget.cmake) + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + export(EXPORT SPIRV-Tools-fuzzTargets FILE SPIRV-Tools-fuzzTargets.cmake) spvtools_config_package_dir(SPIRV-Tools-fuzz PACKAGE_DIR) - install(EXPORT SPIRV-Tools-fuzzTargets FILE SPIRV-Tools-fuzzTarget.cmake - DESTINATION ${PACKAGE_DIR}) + install(EXPORT SPIRV-Tools-fuzzTargets FILE SPIRV-Tools-fuzzTargets.cmake + DESTINATION ${PACKAGE_DIR}) spvtools_generate_config_file(SPIRV-Tools-fuzz) install(FILES ${CMAKE_BINARY_DIR}/SPIRV-Tools-fuzzConfig.cmake DESTINATION ${PACKAGE_DIR}) + endif() + + if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + set_target_properties(SPIRV-Tools-fuzz-shared PROPERTIES OUTPUT_NAME SPIRV-Tools-fuzz) + set_target_properties(SPIRV-Tools-fuzz-shared PROPERTIES EXPORT_NAME SPIRV-Tools-fuzz) + install(TARGETS SPIRV-Tools-fuzz-shared EXPORT SPIRV-Tools-fuzzTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + export(EXPORT SPIRV-Tools-fuzzTargets FILE SPIRV-Tools-shared-fuzzTargets.cmake) + + spvtools_config_package_dir(SPIRV-Tools-fuzz PACKAGE_DIR) + install(EXPORT SPIRV-Tools-linkTargets FILE SPIRV-Tools-shared-linkTargets.cmake + DESTINATION ${PACKAGE_DIR}) + + spvtools_generate_config_file(SPIRV-Tools-fuzz) + install(FILES ${CMAKE_BINARY_DIR}/SPIRV-Tools-linkConfig.cmake DESTINATION ${PACKAGE_DIR}) + endif() endif(ENABLE_SPIRV_TOOLS_INSTALL) endif(SPIRV_BUILD_FUZZER) diff --git a/source/link/CMakeLists.txt b/source/link/CMakeLists.txt index c8dd2f7153a..9a8741cf4e5 100644 --- a/source/link/CMakeLists.txt +++ b/source/link/CMakeLists.txt @@ -11,36 +11,70 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -add_library(SPIRV-Tools-link ${SPIRV_TOOLS_LIBRARY_TYPE} - linker.cpp -) - -spvtools_default_compile_options(SPIRV-Tools-link) -target_include_directories(SPIRV-Tools-link - PUBLIC - $ - $ - $ - PRIVATE ${spirv-tools_BINARY_DIR} -) + +add_library(SPIRV-Tools-link STATIC linker.cpp) + +if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + add_library(SPIRV-Tools-link-shared SHARED linker.cpp) + set(SPIRV_TOOLS_LINK_SHARED SPIRV-Tools-link-shared) +endif() + +spvtools_default_compile_options(SPIRV-Tools-link ${SPIRV_TOOLS_LINK_SHARED}) + +set(SPIRV_TOOLS_LINK_TARGET SPIRV-Tools-link ${SPIRV_TOOLS_LINK_SHARED}) + +foreach(target ${SPIRV_TOOLS_LINK_TARGET}) + target_include_directories(${target} + PUBLIC + $ + $ + $ + PRIVATE ${spirv-tools_BINARY_DIR} + ) +endforeach() + # We need the IR functionnalities from the optimizer target_link_libraries(SPIRV-Tools-link PUBLIC SPIRV-Tools-opt) -set_property(TARGET SPIRV-Tools-link PROPERTY FOLDER "SPIRV-Tools libraries") -spvtools_check_symbol_exports(SPIRV-Tools-link) +if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + target_link_libraries(SPIRV-Tools-link-shared + PUBLIC SPIRV-Tools-opt-shared) +endif() + +set_property(TARGET SPIRV-Tools-link ${SPIRV_TOOLS_LINK_SHARED} PROPERTY FOLDER "SPIRV-Tools libraries") +spvtools_check_symbol_exports(SPIRV-Tools-link ${SPIRV_TOOLS_LINK_SHARED}) if(ENABLE_SPIRV_TOOLS_INSTALL) - install(TARGETS SPIRV-Tools-link EXPORT SPIRV-Tools-linkTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - export(EXPORT SPIRV-Tools-linkTargets FILE SPIRV-Tools-linkTargets.cmake) + if(SPIRV_TOOLS_INSTALL_STATIC_LIBS) + install(TARGETS SPIRV-Tools-link EXPORT SPIRV-Tools-linkTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + export(EXPORT SPIRV-Tools-linkTargets FILE SPIRV-Tools-linkTargets.cmake) + + spvtools_config_package_dir(SPIRV-Tools-link PACKAGE_DIR) + install(EXPORT SPIRV-Tools-linkTargets FILE SPIRV-Tools-linkTargets.cmake + DESTINATION ${PACKAGE_DIR}) + + spvtools_generate_config_file(SPIRV-Tools-link) + install(FILES ${CMAKE_BINARY_DIR}/SPIRV-Tools-linkConfig.cmake DESTINATION ${PACKAGE_DIR}) + endif() + + if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + set_target_properties(SPIRV-Tools-link-shared PROPERTIES OUTPUT_NAME SPIRV-Tools-link) + set_target_properties(SPIRV-Tools-link-shared PROPERTIES EXPORT_NAME SPIRV-Tools-link) + install(TARGETS SPIRV-Tools-link-shared EXPORT SPIRV-Tools-shared-linkTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + export(EXPORT SPIRV-Tools-shared-linkTargets FILE SPIRV-Tools-shared-linkTargets.cmake) spvtools_config_package_dir(SPIRV-Tools-link PACKAGE_DIR) - install(EXPORT SPIRV-Tools-linkTargets FILE SPIRV-Tools-linkTargets.cmake - DESTINATION ${PACKAGE_DIR}) + install(EXPORT SPIRV-Tools-shared-linkTargets FILE SPIRV-Tools-shared-linkTargets.cmake + DESTINATION ${PACKAGE_DIR}) spvtools_generate_config_file(SPIRV-Tools-link) install(FILES ${CMAKE_BINARY_DIR}/SPIRV-Tools-linkConfig.cmake DESTINATION ${PACKAGE_DIR}) + endif() endif(ENABLE_SPIRV_TOOLS_INSTALL) diff --git a/source/lint/CMakeLists.txt b/source/lint/CMakeLists.txt index 1feae3f94d2..2b107133dc5 100644 --- a/source/lint/CMakeLists.txt +++ b/source/lint/CMakeLists.txt @@ -25,37 +25,71 @@ if(MSVC AND (NOT ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))) add_definitions(/MP4) endif() -add_library(SPIRV-Tools-lint ${SPIRV_TOOLS_LIBRARY_TYPE} ${SPIRV_TOOLS_LINT_SOURCES}) - -spvtools_default_compile_options(SPIRV-Tools-lint) -target_include_directories(SPIRV-Tools-lint - PUBLIC - $ - $ - $ - PRIVATE ${spirv-tools_BINARY_DIR} -) +add_library(SPIRV-Tools-lint STATIC ${SPIRV_TOOLS_LINT_SOURCES}) + +if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + add_library(SPIRV-Tools-lint-shared SHARED ${SPIRV_TOOLS_LINT_SOURCES}) + set(SPIRV_TOOLS_LINT_SHARED SPIRV-Tools-lint-shared) +endif() + +spvtools_default_compile_options(SPIRV-Tools-lint ${SPIRV_TOOLS_LINT_SHARED}) + +set(SPIRV_TOOLS_LINT_TARGET SPIRV-Tools-lint ${SPIRV_TOOLS_LINT_SHARED}) + +foreach(target ${SPIRV_TOOLS_LINT_TARGET}) + target_include_directories(${target} + PUBLIC + $ + $ + $ + PRIVATE ${spirv-tools_BINARY_DIR} + ) +endforeach() + # We need the assembling and disassembling functionalities in the main library. target_link_libraries(SPIRV-Tools-lint - PUBLIC ${SPIRV_TOOLS_FULL_VISIBILITY}) -# We need the internals of spirv-opt. -target_link_libraries(SPIRV-Tools-lint + PUBLIC ${SPIRV_TOOLS_FULL_VISIBILITY} PUBLIC SPIRV-Tools-opt) -set_property(TARGET SPIRV-Tools-lint PROPERTY FOLDER "SPIRV-Tools libraries") -spvtools_check_symbol_exports(SPIRV-Tools-lint) +if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + target_link_libraries(SPIRV-Tools-lint-shared + PUBLIC ${SPIRV_TOOLS_FULL_VISIBILITY}-shared + PUBLIC SPIRV-Tools-opt-shared) +endif() + +set_property(TARGET SPIRV-Tools-lint ${SPIRV_TOOLS_LINT_SHARED} PROPERTY FOLDER "SPIRV-Tools libraries") +spvtools_check_symbol_exports(SPIRV-Tools-lint ${SPIRV_TOOLS_LINT_SHARED}) if(ENABLE_SPIRV_TOOLS_INSTALL) - install(TARGETS SPIRV-Tools-lint EXPORT SPIRV-Tools-lintTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - export(EXPORT SPIRV-Tools-lintTargets FILE SPIRV-Tools-lintTargets.cmake) - - spvtools_config_package_dir(SPIRV-Tools-lint PACKAGE_DIR) - install(EXPORT SPIRV-Tools-lintTargets FILE SPIRV-Tools-lintTargets.cmake - DESTINATION ${PACKAGE_DIR}) - - spvtools_generate_config_file(SPIRV-Tools-lint) - install(FILES ${CMAKE_BINARY_DIR}/SPIRV-Tools-lintConfig.cmake DESTINATION ${PACKAGE_DIR}) + if(SPIRV_TOOLS_INSTALL_STATIC_LIBS) + install(TARGETS SPIRV-Tools-lint EXPORT SPIRV-Tools-lintTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + export(EXPORT SPIRV-Tools-lintTargets FILE SPIRV-Tools-lintTargets.cmake) + + spvtools_config_package_dir(SPIRV-Tools-lint PACKAGE_DIR) + install(EXPORT SPIRV-Tools-lintTargets FILE SPIRV-Tools-lintTargets.cmake + DESTINATION ${PACKAGE_DIR}) + + spvtools_generate_config_file(SPIRV-Tools-lint) + install(FILES ${CMAKE_BINARY_DIR}/SPIRV-Tools-lintConfig.cmake DESTINATION ${PACKAGE_DIR}) + endif() + + if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + set_target_properties(SPIRV-Tools-lint-shared PROPERTIES OUTPUT_NAME SPIRV-Tools-lint) + set_target_properties(SPIRV-Tools-lint-shared PROPERTIES EXPORT_NAME SPIRV-Tools-lint) + install(TARGETS SPIRV-Tools-lint-shared EXPORT SPIRV-Tools-shared-lintTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + export(EXPORT SPIRV-Tools-shared-lintTargets FILE SPIRV-Tools-shared-lintTargets.cmake) + + spvtools_config_package_dir(SPIRV-Tools-lint PACKAGE_DIR) + install(EXPORT SPIRV-Tools-shared-lintTargets FILE SPIRV-Tools-shared-lintTargets.cmake + DESTINATION ${PACKAGE_DIR}) + + spvtools_generate_config_file(SPIRV-Tools-lint) + install(FILES ${CMAKE_BINARY_DIR}/SPIRV-Tools-lintConfig.cmake DESTINATION ${PACKAGE_DIR}) + endif() endif(ENABLE_SPIRV_TOOLS_INSTALL) diff --git a/source/opt/CMakeLists.txt b/source/opt/CMakeLists.txt index 63af5c1dadd..e21c193d5a0 100644 --- a/source/opt/CMakeLists.txt +++ b/source/opt/CMakeLists.txt @@ -233,34 +233,69 @@ endif() spvtools_pch(SPIRV_TOOLS_OPT_SOURCES pch_source_opt) -add_library(SPIRV-Tools-opt ${SPIRV_TOOLS_LIBRARY_TYPE} ${SPIRV_TOOLS_OPT_SOURCES}) +add_library(SPIRV-Tools-opt STATIC ${SPIRV_TOOLS_OPT_SOURCES}) + +if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + add_library(SPIRV-Tools-opt-shared SHARED ${SPIRV_TOOLS_OPT_SOURCES}) + set(SPIRV_TOOLS_OPT_SHARED SPIRV-Tools-opt-shared) +endif() + +spvtools_default_compile_options(SPIRV-Tools-opt ${SPIRV_TOOLS_OPT_SHARED}) + +set(SPIRV_TOOLS_OPT_TARGET SPIRV-Tools-opt ${SPIRV_TOOLS_OPT_SHARED}) + +foreach(target ${SPIRV_TOOLS_OPT_TARGET}) + target_include_directories(${target} + PUBLIC + $ + $ + $ + PRIVATE ${spirv-tools_BINARY_DIR} + ) +endforeach() -spvtools_default_compile_options(SPIRV-Tools-opt) -target_include_directories(SPIRV-Tools-opt - PUBLIC - $ - $ - $ - PRIVATE ${spirv-tools_BINARY_DIR} -) # We need the assembling and disassembling functionalities in the main library. target_link_libraries(SPIRV-Tools-opt PUBLIC ${SPIRV_TOOLS_FULL_VISIBILITY}) -set_property(TARGET SPIRV-Tools-opt PROPERTY FOLDER "SPIRV-Tools libraries") -spvtools_check_symbol_exports(SPIRV-Tools-opt) +if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + target_link_libraries(SPIRV-Tools-opt-shared + PUBLIC ${SPIRV_TOOLS_FULL_VISIBILITY}-shared) +endif() + +set_property(TARGET SPIRV-Tools-opt ${SPIRV_TOOLS_OPT_SHARED} PROPERTY FOLDER "SPIRV-Tools libraries") +spvtools_check_symbol_exports(SPIRV-Tools-opt ${SPIRV_TOOLS_OPT_SHARED}) if(ENABLE_SPIRV_TOOLS_INSTALL) - install(TARGETS SPIRV-Tools-opt EXPORT SPIRV-Tools-optTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - export(EXPORT SPIRV-Tools-optTargets FILE SPIRV-Tools-optTargets.cmake) + if(SPIRV_TOOLS_INSTALL_STATIC_LIBS) + install(TARGETS SPIRV-Tools-opt EXPORT SPIRV-Tools-optTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + export(EXPORT SPIRV-Tools-optTargets FILE SPIRV-Tools-optTargets.cmake) + + spvtools_config_package_dir(SPIRV-Tools-opt PACKAGE_DIR) + install(EXPORT SPIRV-Tools-optTargets FILE SPIRV-Tools-optTargets.cmake + DESTINATION ${PACKAGE_DIR}) + + spvtools_generate_config_file(SPIRV-Tools-opt) + install(FILES ${CMAKE_BINARY_DIR}/SPIRV-Tools-optConfig.cmake DESTINATION ${PACKAGE_DIR}) + endif() + + if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + set_target_properties(SPIRV-Tools-opt-shared PROPERTIES OUTPUT_NAME SPIRV-Tools-opt) + set_target_properties(SPIRV-Tools-opt-shared PROPERTIES EXPORT_NAME SPIRV-Tools-opt) + install(TARGETS SPIRV-Tools-opt-shared EXPORT SPIRV-Tools-shared-optTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + export(EXPORT SPIRV-Tools-shared-optTargets FILE SPIRV-Tools-shared-optTargets.cmake) - spvtools_config_package_dir(SPIRV-Tools-opt PACKAGE_DIR) - install(EXPORT SPIRV-Tools-optTargets FILE SPIRV-Tools-optTargets.cmake - DESTINATION ${PACKAGE_DIR}) + spvtools_config_package_dir(SPIRV-Tools-opt PACKAGE_DIR) + install(EXPORT SPIRV-Tools-shared-optTargets FILE SPIRV-Tools-shared-optTargets.cmake + DESTINATION ${PACKAGE_DIR}) - spvtools_generate_config_file(SPIRV-Tools-opt) - install(FILES ${CMAKE_BINARY_DIR}/SPIRV-Tools-optConfig.cmake DESTINATION ${PACKAGE_DIR}) + spvtools_generate_config_file(SPIRV-Tools-opt) + install(FILES ${CMAKE_BINARY_DIR}/SPIRV-Tools-optConfig.cmake DESTINATION ${PACKAGE_DIR}) + endif() endif(ENABLE_SPIRV_TOOLS_INSTALL) diff --git a/source/reduce/CMakeLists.txt b/source/reduce/CMakeLists.txt index 6fd8409f69a..192d44cf234 100644 --- a/source/reduce/CMakeLists.txt +++ b/source/reduce/CMakeLists.txt @@ -82,35 +82,71 @@ endif() spvtools_pch(SPIRV_TOOLS_REDUCE_SOURCES pch_source_reduce) -add_library(SPIRV-Tools-reduce ${SPIRV_TOOLS_LIBRARY_TYPE} ${SPIRV_TOOLS_REDUCE_SOURCES}) - -spvtools_default_compile_options(SPIRV-Tools-reduce) -target_include_directories(SPIRV-Tools-reduce - PUBLIC - $ - $ - $ - PRIVATE ${spirv-tools_BINARY_DIR} -) +add_library(SPIRV-Tools-reduce STATIC ${SPIRV_TOOLS_REDUCE_SOURCES}) + +if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + add_library(SPIRV-Tools-reduce-shared SHARED ${SPIRV_TOOLS_REDUCE_SOURCES}) + set(SPIRV_TOOLS_REDUCE_SHARED SPIRV-Tools-reduce-shared) +endif() + +spvtools_default_compile_options(SPIRV-Tools-reduce ${SPIRV_TOOLS_REDUCE_SHARED}) + +set(SPIRV_TOOLS_REDUCE_TARGET SPIRV-Tools-reduce ${SPIRV_TOOLS_REDUCE_SHARED}) + +foreach(target ${SPIRV_TOOLS_REDUCE_TARGET}) + target_include_directories(${target} + PUBLIC + $ + $ + $ + PRIVATE ${spirv-tools_BINARY_DIR} + ) +endforeach() + # The reducer reuses a lot of functionality from the SPIRV-Tools library. target_link_libraries(SPIRV-Tools-reduce PUBLIC ${SPIRV_TOOLS_FULL_VISIBILITY} PUBLIC SPIRV-Tools-opt) -set_property(TARGET SPIRV-Tools-reduce PROPERTY FOLDER "SPIRV-Tools libraries") -spvtools_check_symbol_exports(SPIRV-Tools-reduce) +if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + target_link_libraries(SPIRV-Tools-reduce-shared + PUBLIC ${SPIRV_TOOLS_FULL_VISIBILITY}-shared + PUBLIC SPIRV-Tools-opt-shared) +endif() + +set_property(TARGET SPIRV-Tools-reduce ${SPIRV_TOOLS_REDUCE_SHARED} PROPERTY FOLDER "SPIRV-Tools libraries") +spvtools_check_symbol_exports(SPIRV-Tools-reduce ${SPIRV_TOOLS_REDUCE_SHARED}) if(ENABLE_SPIRV_TOOLS_INSTALL) - install(TARGETS SPIRV-Tools-reduce EXPORT SPIRV-Tools-reduceTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - export(EXPORT SPIRV-Tools-reduceTargets FILE SPIRV-Tools-reduceTarget.cmake) - - spvtools_config_package_dir(SPIRV-Tools-reduce PACKAGE_DIR) - install(EXPORT SPIRV-Tools-reduceTargets FILE SPIRV-Tools-reduceTarget.cmake - DESTINATION ${PACKAGE_DIR}) - - spvtools_generate_config_file(SPIRV-Tools-reduce) - install(FILES ${CMAKE_BINARY_DIR}/SPIRV-Tools-reduceConfig.cmake DESTINATION ${PACKAGE_DIR}) + if(SPIRV_TOOLS_INSTALL_STATIC_LIBS) + install(TARGETS SPIRV-Tools-reduce EXPORT SPIRV-Tools-reduceTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + export(EXPORT SPIRV-Tools-reduceTargets FILE SPIRV-Tools-static-reduceTargets.cmake) + + spvtools_config_package_dir(SPIRV-Tools-reduce PACKAGE_DIR) + install(EXPORT SPIRV-Tools-reduceTargets FILE SPIRV-Tools-static-reduceTargets.cmake + DESTINATION ${PACKAGE_DIR}) + + spvtools_generate_config_file(SPIRV-Tools-reduce) + install(FILES ${CMAKE_BINARY_DIR}/SPIRV-Tools-reduceConfig.cmake DESTINATION ${PACKAGE_DIR}) + endif() + + if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + set_target_properties(SPIRV-Tools-reduce-shared PROPERTIES OUTPUT_NAME SPIRV-Tools-reduce) + set_target_properties(SPIRV-Tools-reduce-shared PROPERTIES EXPORT_NAME SPIRV-Tools-reduce) + install(TARGETS SPIRV-Tools-reduce-shared EXPORT SPIRV-Tools-shared-reduceTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + export(EXPORT SPIRV-Tools-shared-reduceTargets FILE SPIRV-Tools-shared-reduceTargets.cmake) + + spvtools_config_package_dir(SPIRV-Tools-reduce PACKAGE_DIR) + install(EXPORT SPIRV-Tools-shared-reduceTargets FILE SPIRV-Tools-shared-reduceTargets.cmake + DESTINATION ${PACKAGE_DIR}) + + spvtools_generate_config_file(SPIRV-Tools-reduce) + install(FILES ${CMAKE_BINARY_DIR}/SPIRV-Tools-reduceConfig.cmake DESTINATION ${PACKAGE_DIR}) + endif() endif(ENABLE_SPIRV_TOOLS_INSTALL) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e88df04d79c..477eebc42c8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -166,11 +166,13 @@ add_spvtools_unittest( SRCS c_interface_test.cpp LIBS ${SPIRV_TOOLS_FULL_VISIBILITY}) -add_spvtools_unittest( - TARGET c_interface_shared - SRCS c_interface_test.cpp - LIBS ${SPIRV_TOOLS}-shared - ENVIRONMENT PATH=$) +if(SPIRV_TOOLS_BUILD_SHARED_LIBS) + add_spvtools_unittest( + TARGET c_interface_shared + SRCS c_interface_test.cpp + LIBS ${SPIRV_TOOLS} + ENVIRONMENT PATH=$) +endif() add_spvtools_unittest( TARGET cpp_interface