Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmake] Question about target ${SPIRV_TOOLS}-shared and ${SPIRV_TOOLS} #4417

Open
JackBoosY opened this issue Jul 29, 2021 · 0 comments
Open

Comments

@JackBoosY
Copy link

JackBoosY commented Jul 29, 2021

In the following code:

# 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()

There are two scenarios here:

  1. If I pass -DSPIRV_TOOLS_BUILD_STATIC=ON, there will be 3 targets:
  • ${SPIRV_TOOLS}-shared
  • ${SPIRV_TOOLS}-static
  • ${SPIRV_TOOLS}

${SPIRV_TOOLS} is point to ${SPIRV_TOOLS}-shared or ${SPIRV_TOOLS}-static according to BUILD_SHARED_LIBS. that's okay, but I don’t know why SPIRV_TOOLS_BUILD_STATIC and SPIRV_TOOLS_LIBRARY_TYPE and BUILD_SHARED_LIBS can exist at the same time.
If we use BUILD_SHARED_LIBS, the generated library should have the same expectation as the value of BUILD_SHARED_LIBS: generate dynamic library, otherwise generate static library.

  1. If I pass -DSPIRV_TOOLS_BUILD_STATIC=OFF, there will be 2 targets:
  • ${SPIRV_TOOLS}-shared
  • ${SPIRV_TOOLS}

${SPIRV_TOOLS} uses the same source files with ${SPIRV_TOOLS}-shared.
And if BUILD_SHARED_LIBS is ON, there will be 2 dynamic libraries!
On Windows, ${SPIRV_TOOLS} has exported symbols, and ${SPIRV_TOOLS}-shared doesn't export any symbols. I think that's not make sence: how to use a dynamic library that does not export any symbols?
On non-Windows, you will see SPIRV_TOOLS is same with ${SPIRV_TOOLS}-shared.

So my question is:

  1. Why is there such a design?
  2. What is the point of always generating dynamic libraries?
  3. Why not just use BUILD_SHARED_LIBS or SPIRV_TOOLS_BUILD_STATIC or SPIRV_TOOLS_LIBRARY_TYPE ?

Related downstrem PR: microsoft/vcpkg#19219

@JackBoosY JackBoosY changed the title Question about target ${SPIRV_TOOLS}-shared and ${SPIRV_TOOLS} [cmake] Question about target ${SPIRV_TOOLS}-shared and ${SPIRV_TOOLS} Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants