From 45953b9dcf44de5db66ee0dd6f6fd5ffe133ae7f Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sun, 3 Mar 2019 12:18:58 +1100 Subject: [PATCH] build: create a dynamic libvulkan.so --- CMakeLists.txt | 29 ++++++++++++++++++++--------- load/ostream.hpp | 2 +- load/vendor.hpp | 4 ++-- tools/spec.py | 6 +++--- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb41283..e880a53 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,7 +61,7 @@ endif() ##----------------------------------------------------------------------------- -add_library (cruft-vk-load STATIC +list (APPEND VK_LOAD_SOURCES load/fwd.hpp ${GENERATED_PREFIX}/load/vtable.hpp ${GENERATED_PREFIX}/load/dispatch.cpp @@ -74,14 +74,23 @@ add_library (cruft-vk-load STATIC load/vtable.cpp ) -target_include_directories (cruft-vk-load - PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}" - "${CMAKE_CURRENT_BINARY_DIR}" - "${CMAKE_CURRENT_SOURCE_DIR}/specs/include/vulkan" -) -target_link_libraries (cruft-vk-load cruft-json cruft) +add_library (vulkan SHARED ${VK_LOAD_SOURCES}) +set_target_properties(vulkan PROPERTIES VERSION 1.1.98) +set_target_properties(vulkan PROPERTIES SOVERSION 1) + +add_library (cruft-vk-load STATIC ${VK_LOAD_SOURCES}) + +foreach (lib vulkan cruft-vk-load) + target_include_directories (${lib} + PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}" + "${CMAKE_CURRENT_BINARY_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}/specs/include/vulkan" + ) + + target_link_libraries (${lib} cruft-json cruft) +endforeach () ############################################################################### list (APPEND sources @@ -189,9 +198,11 @@ foreach (t info hello) set_target_properties(vk_${t} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tools") - target_link_libraries (vk_${t} cruft-vk glfw) endforeach () +target_link_libraries (vk_info cruft-vk cruft-vk-load) +target_link_libraries (vk_hello cruft-vk glfw) + ##----------------------------------------------------------------------------- add_dependencies (vk_hello hello.vert.spv hello.frag.spv) diff --git a/load/ostream.hpp b/load/ostream.hpp index 5a8714b..201e76d 100644 --- a/load/ostream.hpp +++ b/load/ostream.hpp @@ -13,5 +13,5 @@ #include namespace cruft::vk::load { - std::ostream& operator<< (std::ostream&, icd_t const&); + std::ostream& operator<< [[gnu::visibility("default")]] (std::ostream&, icd_t const&); } diff --git a/load/vendor.hpp b/load/vendor.hpp index 6133ccc..47d7c0d 100644 --- a/load/vendor.hpp +++ b/load/vendor.hpp @@ -22,7 +22,7 @@ namespace cruft::vk::load { std::vector - enumerate (void); + enumerate [[gnu::visibility("default")]] (void); struct vendor_table { @@ -31,7 +31,7 @@ namespace cruft::vk::load { void* (*vk_icdGetPhysicalDeviceProcAddr) (VkInstance, char const*) = nullptr; }; - class vendor { + class [[gnu::visibility("default")]] vendor { public: vendor (icd_t const&); vendor (::cruft::library &&); diff --git a/tools/spec.py b/tools/spec.py index 98dbcfe..fd5b1f0 100644 --- a/tools/spec.py +++ b/tools/spec.py @@ -429,7 +429,7 @@ class Command(Type): return f"{{ name: '{self.name}', result: '{self.result}', param: {self.params} }}" def declare(self): - return 'extern "C" %(result)s %(name)s (%(params)s) noexcept;' % { + return 'extern "C" %(result)s %(name)s [[gnu::visibility("default")]] (%(params)s) noexcept;' % { 'name': rename(self.name), 'result': self.result, 'params': ", ".join(p.param for p in self.params) @@ -837,8 +837,8 @@ def write_load(dst: TextIO, q: List[Type], reg: Registry): dst.write(""" struct vendor_table; - extern cruft::vk::load::vendor_table const *v_table; - extern cruft::vk::load::instance_table const *i_table; + extern cruft::vk::load::vendor_table const *v_table [[gnu::visibility("default")]]; + extern cruft::vk::load::instance_table const *i_table [[gnu::visibility("default")]]; } """)