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 7b62fde
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 15 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*
18 changes: 18 additions & 0 deletions 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 @@ -13,6 +14,8 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 14)

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

if (SPIRV_REFLECT_ENABLE_ASAN)
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
Expand Down Expand Up @@ -118,3 +121,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 7b62fde

Please sign in to comment.