Skip to content

Commit 780a149

Browse files
authored
Merge pull request SQFvm#190 from DarkWanderer/feature/dll-exports
Proper "export" header for library consumers
2 parents 91fd893 + b83700d commit 780a149

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ add_executable(sqfvm ${sqfvm_SOURCES})
6161

6262
target_link_libraries(sqfvm ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${ST_CXXFS_LIBS})
6363
target_include_directories(sqfvm PUBLIC ${PROJECT_SOURCE_DIR}/src)
64+
target_compile_definitions(sqfvm PRIVATE SQFVM_BUILD)
6465

6566
add_library(libsqfvm SHARED ${sqfvm_SOURCES})
6667
target_include_directories(libsqfvm PUBLIC ${PROJECT_SOURCE_DIR}/src)
67-
target_compile_definitions(libsqfvm PUBLIC DISABLE_CLIPBOARD)
68+
target_compile_definitions(libsqfvm
69+
PUBLIC DISABLE_CLIPBOARD
70+
PRIVATE SQFVM_BUILD # this is a define visible only to the library itself
71+
)
6872
set_target_properties(libsqfvm PROPERTIES PREFIX "")
6973

7074
if (SQFVM_ENABLE_SQC_SUPPORT)
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#include "../parser/preprocessor/default.h"
77
#include "../operators/ops.h"
88
#include "../fileio/default.h"
9-
#include "dllexports.h"
9+
10+
#include "sqfvm.h"
1011

1112
#ifdef SQF_SQC_SUPPORT
1213
#include "../sqc/sqc_parser.h"
@@ -147,23 +148,23 @@ namespace dllexports
147148
}
148149
}
149150
extern "C" {
150-
DLLEXPORT_PREFIX void* sqfvm_create_instance(void* user_data, sqfvm_log_callback callback, float max_runtime_seconds)
151+
SQFVM_EXPORT void* sqfvm_create_instance(void* user_data, sqfvm_log_callback callback, float max_runtime_seconds)
151152
{
152153
return dllexports::create_instance(user_data, callback, max_runtime_seconds, dllexports::ops_set::full);
153154
}
154-
DLLEXPORT_PREFIX void* sqfvm_create_instance_basic(void* user_data, sqfvm_log_callback callback, float max_runtime_seconds)
155+
SQFVM_EXPORT void* sqfvm_create_instance_basic(void* user_data, sqfvm_log_callback callback, float max_runtime_seconds)
155156
{
156157
return dllexports::create_instance(user_data, callback, max_runtime_seconds, dllexports::ops_set::basic);
157158
}
158-
DLLEXPORT_PREFIX void* sqfvm_create_instance_empty(void* user_data, sqfvm_log_callback callback, float max_runtime_seconds)
159+
SQFVM_EXPORT void* sqfvm_create_instance_empty(void* user_data, sqfvm_log_callback callback, float max_runtime_seconds)
159160
{
160161
return dllexports::create_instance(user_data, callback, max_runtime_seconds, dllexports::ops_set::none);
161162
}
162-
DLLEXPORT_PREFIX void sqfvm_destroy_instance(void* instance)
163+
SQFVM_EXPORT void sqfvm_destroy_instance(void* instance)
163164
{
164165
return dllexports::destroy_instance(instance);
165166
}
166-
DLLEXPORT_PREFIX int32_t sqfvm_load_config(void* instance, const char* contents, uint32_t length)
167+
SQFVM_EXPORT int32_t sqfvm_load_config(void* instance, const char* contents, uint32_t length)
167168
{
168169
const int32_t instance_invalid = -1;
169170
const int32_t preprocessing_failed = -2;
@@ -190,7 +191,7 @@ extern "C" {
190191
return instance_invalid;
191192
}
192193
}
193-
DLLEXPORT_PREFIX int32_t sqfvm_call(void* instance, void* call_data, char type, const char* code, uint32_t length)
194+
SQFVM_EXPORT int32_t sqfvm_call(void* instance, void* call_data, char type, const char* code, uint32_t length)
194195
{
195196
const int32_t instance_invalid = -1;
196197
const int32_t preprocessing_failed = -2;
@@ -341,7 +342,7 @@ extern "C" {
341342
return instance_invalid;
342343
}
343344
}
344-
DLLEXPORT_PREFIX int32_t sqfvm_status(void* instance)
345+
SQFVM_EXPORT int32_t sqfvm_status(void* instance)
345346
{
346347
auto result = dllexports::with_instance_do(instance, [](dllexports::instance& ref) -> int32_t {
347348
return static_cast<int32_t>(ref.runtime->runtime_state());
@@ -355,4 +356,4 @@ extern "C" {
355356
return -1;
356357
}
357358
}
358-
}
359+
}
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#pragma once
2-
#include <vector>
3-
42

53
#ifdef _WIN32
6-
#define DLLEXPORT_PREFIX __declspec(dllexport)
4+
#ifdef SQFVM_BUILD
5+
#define SQFVM_EXPORT __declspec(dllexport)
6+
#else
7+
#define SQFVM_EXPORT __declspec(dllimport)
8+
#endif
79
#else
8-
#define DLLEXPORT_PREFIX __attribute__((visibility("default")))
10+
#define SQFVM_EXPORT __attribute__((visibility("default")))
911
#endif
1012

1113
extern "C" {
@@ -27,24 +29,24 @@ extern "C" {
2729
// @param user_data Custom data from the callee that will be passed into callback
2830
// @param max_runtime_seconds the maximum runtime in seconds as float. Pass 0
2931
// Returns NULL on error
30-
DLLEXPORT_PREFIX void* sqfvm_create_instance(void* user_data, sqfvm_log_callback callback, float max_runtime_seconds);
32+
SQFVM_EXPORT void* sqfvm_create_instance(void* user_data, sqfvm_log_callback callback, float max_runtime_seconds);
3133

3234
// Creates a new SQF-VM instance with the basic, non-arma specific operators loaded
3335
// @param callback The callback to report log messages on
3436
// @param user_data Custom data from the callee that will be passed into callback
3537
// @param max_runtime_seconds the maximum runtime in seconds as float. Pass 0
3638
// Returns NULL on error
37-
DLLEXPORT_PREFIX void* sqfvm_create_instance_basic(void* user_data, sqfvm_log_callback callback, float max_runtime_seconds);
39+
SQFVM_EXPORT void* sqfvm_create_instance_basic(void* user_data, sqfvm_log_callback callback, float max_runtime_seconds);
3840

3941
// Creates a new SQF-VM instance without any operators loaded
4042
// @param callback The callback to report log messages on
4143
// @param user_data Custom data from the callee that will be passed into callback
4244
// @param max_runtime_seconds the maximum runtime in seconds as float. Pass 0
4345
// Returns NULL on error
44-
DLLEXPORT_PREFIX void* sqfvm_create_instance_empty(void* user_data, sqfvm_log_callback callback, float max_runtime_seconds);
46+
SQFVM_EXPORT void* sqfvm_create_instance_empty(void* user_data, sqfvm_log_callback callback, float max_runtime_seconds);
4547

4648
// Destroys a previously created SQF-VM instance
47-
DLLEXPORT_PREFIX void sqfvm_destroy_instance(void* instance);
49+
SQFVM_EXPORT void sqfvm_destroy_instance(void* instance);
4850

4951
// Loads the provided config into the config tree of the provided instance
5052
// @param instance A valid instance as returned from sqfvm_create_instance
@@ -54,7 +56,7 @@ extern "C" {
5456
// -1 if the instance was null
5557
// -2 if preprocessing failed
5658
// -3 if parsing failed
57-
DLLEXPORT_PREFIX int32_t sqfvm_load_config(void* instance, const char* contents, uint32_t length);
59+
SQFVM_EXPORT int32_t sqfvm_load_config(void* instance, const char* contents, uint32_t length);
5860

5961
// Checks the status of the instance
6062
// @param instance A valid instance as returned from sqfvm_create_instance
@@ -65,7 +67,7 @@ extern "C" {
6567
// +3 Instance is in halted_error
6668
// +4 evaluating
6769
//
68-
DLLEXPORT_PREFIX int32_t sqfvm_status(void* instance);
70+
SQFVM_EXPORT int32_t sqfvm_status(void* instance);
6971

7072
// Calls the provided code, using the SQF-VM instance.
7173
// @param instance A valid instance as returned from sqfvm_create_instance
@@ -86,5 +88,5 @@ extern "C" {
8688
// -4 if the instance is already running
8789
// -5 if the provided type was invalid
8890
// -6 if the execution did not succeed
89-
DLLEXPORT_PREFIX int32_t sqfvm_call(void* instance, void* call_data, char type, const char* code, uint32_t length);
90-
}
91+
SQFVM_EXPORT int32_t sqfvm_call(void* instance, void* call_data, char type, const char* code, uint32_t length);
92+
}

0 commit comments

Comments
 (0)