From db7e9cb07341043ac9949012d9e1a978fa7c8508 Mon Sep 17 00:00:00 2001 From: Sandy Carter Date: Sat, 30 Jan 2021 19:33:13 -0500 Subject: [PATCH 1/4] cmake: turn on CMAKE_POSITION_INDEPENDENT_CODE for shared This prevents an error while linking libbx.a into libbgfx.so on linux --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 52a7315b..4412be12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,10 @@ set( BGFX_LIBRARY_TYPE "STATIC" CACHE STRING "Linking type for library" ) set_property( CACHE BGFX_LIBRARY_TYPE PROPERTY STRINGS STATIC SHARED ) +if( BGFX_LIBRARY_TYPE MATCHES "SHARED" ) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() + if( NOT BX_DIR ) set( BX_DIR "${CMAKE_CURRENT_SOURCE_DIR}/bx" CACHE STRING "Location of bx." ) elseif( NOT IS_ABSOLUTE "${BX_DIR}") From 3935d459cc299e172e28e70d5ee8eb2d798ecbc0 Mon Sep 17 00:00:00 2001 From: Sandy Carter Date: Sat, 30 Jan 2021 21:18:07 -0500 Subject: [PATCH 2/4] bimg: specify visibility of linked libs --- cmake/bimg.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/bimg.cmake b/cmake/bimg.cmake index 56a047e2..f403771a 100644 --- a/cmake/bimg.cmake +++ b/cmake/bimg.cmake @@ -38,7 +38,7 @@ target_include_directories( bimg $) # bimg dependencies -target_link_libraries( bimg bx astc-codec astc edtaa3 etc1 etc2 iqa squish nvtt pvrtc ) +target_link_libraries( bimg PUBLIC bx PRIVATE astc-codec astc edtaa3 etc1 etc2 iqa squish nvtt pvrtc ) # Put in a "bgfx" folder in Visual Studio set_target_properties( bimg PROPERTIES FOLDER "bgfx" ) \ No newline at end of file From bf668bfed4ae56d4efcd7013f9e93eed21c0c2f5 Mon Sep 17 00:00:00 2001 From: Sandy Carter Date: Sat, 30 Jan 2021 20:52:41 -0500 Subject: [PATCH 3/4] install: if generating shared, only install bgfx --- CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4412be12..ca72939a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,13 +122,22 @@ if( BGFX_INSTALL ) install(FILES ${BGFX_DIR}/LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR}) install(FILES README.md DESTINATION ${CMAKE_INSTALL_DOCDIR}) - install( TARGETS bgfx bimg bx astc-codec astc edtaa3 etc1 etc2 iqa squish nvtt pvrtc + install( TARGETS bgfx EXPORT "${TARGETS_EXPORT_NAME}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) + if( NOT BGFX_LIBRARY_TYPE MATCHES "SHARED" ) + install( TARGETS bimg bx astc-codec astc edtaa3 etc1 etc2 iqa squish nvtt pvrtc + EXPORT "${TARGETS_EXPORT_NAME}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + ) + endif() if (BGFX_CONFIG_RENDERER_WEBGPU) install( TARGETS webgpu EXPORT "${TARGETS_EXPORT_NAME}" From 2e984715d77426b72d467ee3fb8c26658a7e4a26 Mon Sep 17 00:00:00 2001 From: Sandy Carter Date: Sat, 30 Jan 2021 22:08:08 -0500 Subject: [PATCH 4/4] bgfx: make bx and bimg private This makes it so in shared mode, bx and bimg static libs aren't installed --- cmake/bgfx.cmake | 2 +- cmake/examples.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/bgfx.cmake b/cmake/bgfx.cmake index c2757ad4..a0a3d308 100755 --- a/cmake/bgfx.cmake +++ b/cmake/bgfx.cmake @@ -82,7 +82,7 @@ target_include_directories( bgfx $) # bgfx depends on bx and bimg -target_link_libraries( bgfx PUBLIC bx bimg ) +target_link_libraries( bgfx PRIVATE bx bimg ) # ovr support if( BGFX_USE_OVR ) diff --git a/cmake/examples.cmake b/cmake/examples.cmake index 68093b41..90769324 100755 --- a/cmake/examples.cmake +++ b/cmake/examples.cmake @@ -134,7 +134,7 @@ function( add_example ARG_NAME ) if( ARG_COMMON ) add_library( example-${ARG_NAME} STATIC EXCLUDE_FROM_ALL ${SOURCES} ) target_include_directories( example-${ARG_NAME} PUBLIC ${BGFX_DIR}/examples/common ) - target_link_libraries( example-${ARG_NAME} PUBLIC bgfx dear-imgui meshoptimizer ) + target_link_libraries( example-${ARG_NAME} PUBLIC bgfx bx bimg dear-imgui meshoptimizer ) if( BGFX_WITH_GLFW ) find_package( glfw3 REQUIRED ) target_link_libraries( example-${ARG_NAME} PUBLIC glfw )