Skip to content

Commit

Permalink
Add support for shared library build
Browse files Browse the repository at this point in the history
  • Loading branch information
makkarpov committed Jul 25, 2024
1 parent 90add1d commit 638331b
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 16 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ bazel-spirv-reflect
bazel-SPIRV-Reflect
bazel-testlogs
/.vs
/.vscode
/.vscode

# CLion-specific:
/.idea
/cmake-build*
19 changes: 18 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.5)

project(spirv-reflect)

OPTION(BUILD_SHARED_LIBS "Build shared library" OFF)
OPTION(SPIRV_REFLECT_EXECUTABLE "Build spirv-reflect executable" ON)

OPTION(SPIRV_REFLECT_STATIC_LIB "Build a SPIRV-Reflect static library" OFF)
Expand All @@ -12,14 +13,15 @@ OPTION(SPIRV_REFLECT_ENABLE_ASAN "Use address sanitization" OFF)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 14)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")

if (SPIRV_REFLECT_ENABLE_ASAN)
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
add_link_options(-fsanitize=address)
endif()

if (SPIRV_REFLECT_EXECUTABLE)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")

# ==========================================================================
# Compile spirv_reflect.c as C
# ==========================================================================
Expand Down Expand Up @@ -118,3 +120,18 @@ if(SPIRV_REFLECT_STATIC_LIB)
ARCHIVE DESTINATION lib)
endif()

if(BUILD_SHARED_LIBS)
add_library(spirv-reflect SHARED ${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.h
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.c)

target_include_directories(spirv-reflect
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_compile_definitions(spirv-reflect PUBLIC SPIRV_REFLECT_SHARED)
target_compile_options(spirv-reflect PRIVATE
$<$<CXX_COMPILER_ID:GNU>:-fvisibility=hidden>)

install(TARGETS spirv-reflect
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif ()
1 change: 1 addition & 0 deletions spirv_reflect.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
limitations under the License.
*/

#define SPIRV_REFLECT_IMPLEMENTATION // turn dllimports into dllexports
#include "spirv_reflect.h"

#include <assert.h>
Expand Down
Loading

0 comments on commit 638331b

Please sign in to comment.