Skip to content

Commit 6bb0835

Browse files
authored
Merge pull request #222 from zeux/namespace
Add VOLK_NAMESPACE configuration to use C++ namespaces
2 parents afb0cd1 + 622ad3c commit 6bb0835

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.5...3.30)
22

3-
project(volk VERSION
3+
project(volk VERSION
44
# VOLK_GENERATE_VERSION
55
326
66
# VOLK_GENERATE_VERSION
@@ -18,6 +18,9 @@ endif()
1818
if(NOT DEFINED VOLK_INSTALL)
1919
option(VOLK_INSTALL "Create installation targets" OFF)
2020
endif()
21+
if(NOT DEFINED VOLK_NAMESPACE)
22+
option(VOLK_NAMESPACE "Use C++ namespace for vk* functions" OFF)
23+
endif()
2124
if(NOT DEFINED VOLK_HEADERS_ONLY)
2225
option(VOLK_HEADERS_ONLY "Add interface library only" OFF)
2326
endif()
@@ -35,6 +38,10 @@ if(NOT VOLK_HEADERS_ONLY OR VOLK_INSTALL)
3538
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
3639
$<INSTALL_INTERFACE:include>
3740
)
41+
if(VOLK_NAMESPACE)
42+
target_compile_definitions(volk PUBLIC VOLK_NAMESPACE)
43+
set_source_files_properties(volk.c PROPERTIES LANGUAGE CXX)
44+
endif()
3845
if(VOLK_STATIC_DEFINES)
3946
target_compile_definitions(volk PUBLIC ${VOLK_STATIC_DEFINES})
4047
endif()

volk.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424
#include <string.h>
2525

2626
#ifdef __cplusplus
27+
#ifdef VOLK_NAMESPACE
28+
namespace volk {
29+
#else
2730
extern "C" {
2831
#endif
32+
#endif
2933

3034
#ifdef _WIN32
3135
__declspec(dllimport) HMODULE __stdcall LoadLibraryA(LPCSTR);
@@ -3572,6 +3576,6 @@ PFN_vkAcquireNextImage2KHR vkAcquireNextImage2KHR;
35723576
#endif
35733577

35743578
#ifdef __cplusplus
3575-
}
3579+
} // extern "C" / namespace volk
35763580
#endif
35773581
/* clang-format on */

volk.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#ifndef VOLK_H_
1111
#define VOLK_H_
1212

13+
#if defined(VOLK_NAMESPACE) && !defined(__cplusplus)
14+
#error VOLK_NAMESPACE is only supported in C++
15+
#endif
16+
1317
#if defined(VULKAN_H_) && !defined(VK_NO_PROTOTYPES)
1418
# error To use volk, you need to define VK_NO_PROTOTYPES before including vulkan.h
1519
#endif
@@ -32,8 +36,12 @@
3236
#endif
3337

3438
#ifdef __cplusplus
39+
#ifdef VOLK_NAMESPACE
40+
namespace volk {
41+
#else
3542
extern "C" {
3643
#endif
44+
#endif
3745

3846
struct VolkDeviceTable;
3947

@@ -105,7 +113,7 @@ VkDevice volkGetLoadedDevice(void);
105113
void volkLoadDeviceTable(struct VolkDeviceTable* table, VkDevice device);
106114

107115
#ifdef __cplusplus
108-
}
116+
} // extern "C" / namespace volk
109117
#endif
110118

111119
/* Instead of directly including vulkan.h, we include platform-specific parts of the SDK manually
@@ -1515,8 +1523,12 @@ struct VolkDeviceTable
15151523
};
15161524

15171525
#ifdef __cplusplus
1526+
#ifdef VOLK_NAMESPACE
1527+
namespace volk {
1528+
#else
15181529
extern "C" {
15191530
#endif
1531+
#endif
15201532

15211533
/* VOLK_GENERATE_PROTOTYPES_H */
15221534
#if defined(VK_VERSION_1_0)
@@ -2726,11 +2738,15 @@ extern PFN_vkAcquireNextImage2KHR vkAcquireNextImage2KHR;
27262738
#endif
27272739

27282740
#ifdef __cplusplus
2729-
}
2741+
} // extern "C" / namespace volk
27302742
#endif
27312743

2744+
#ifdef VOLK_NAMESPACE
2745+
using namespace volk;
27322746
#endif
27332747

2748+
#endif // VOLK_H
2749+
27342750
#ifdef VOLK_IMPLEMENTATION
27352751
#undef VOLK_IMPLEMENTATION
27362752
/* Prevent tools like dependency checkers from detecting a cyclic dependency */

0 commit comments

Comments
 (0)