From 16232bde424687f7e88af112bd6a96b360abf71d 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 mode by default (like always). for enable shared mode set `-DBUILD_SHARED_LIBS=ON` - Remove reneration SPIRV-Tools-shared.pc.in. not need anymore. SPIRV-Tools.pc.in can handle both. - Let's visible always. because hide make problems when link to sprv-foo/test programs in shared mode (can' find any symbols). - Build external RE2 in static mode always TODO: - Fix point (2) and point (3) - Point (4) is out of my scope. i'm not coder --- CMakeLists.txt | 58 ++++------------------------------ cmake/SPIRV-Tools-shared.pc.in | 12 ------- external/CMakeLists.txt | 13 ++++++-- source/CMakeLists.txt | 33 ++----------------- test/CMakeLists.txt | 4 +-- 5 files changed, 22 insertions(+), 98 deletions(-) delete mode 100644 cmake/SPIRV-Tools-shared.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 01e3b16f549..a2ad88e7a57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,45 +139,14 @@ 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) +option(BUILD_SHARED_LIBS "Enable shared libs" OFF) + +set(SPIRV_TOOLS_FULL_VISIBILITY ${SPIRV_TOOLS}) +if(BUILD_SHARED_LIBS) + set(SPIRV_TOOLS_LIBRARY_TYPE "SHARED") +else() 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) +endif() function(spvtools_default_compile_options TARGET) target_compile_options(${TARGET} PRIVATE ${SPIRV_WARNINGS}) @@ -353,7 +322,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 +336,12 @@ 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) 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..cf5fe48dc5e 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -369,36 +369,9 @@ 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) -endif() +add_library(${SPIRV_TOOLS} ${SPIRV_TOOLS_LIBRARY_TYPE} ${SPIRV_SOURCES}) +spirv_tools_default_target_options(${SPIRV_TOOLS}) +set(SPIRV_TOOLS_TARGETS ${SPIRV_TOOLS}) if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") find_library(LIBRT rt) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e88df04d79c..a277c2082f7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -169,8 +169,8 @@ add_spvtools_unittest( add_spvtools_unittest( TARGET c_interface_shared SRCS c_interface_test.cpp - LIBS ${SPIRV_TOOLS}-shared - ENVIRONMENT PATH=$) + LIBS ${SPIRV_TOOLS} + ENVIRONMENT PATH=$) add_spvtools_unittest( TARGET cpp_interface