-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CMake build support #19
base: master
Are you sure you want to change the base?
Changes from 2 commits
5e0e250
0b6e3e9
327d339
f17fbc3
680dfad
01bd891
278edca
53b10f7
d3a7e11
4ea626a
ac92f8e
93d5f8f
98e01d2
1f54590
93b78c0
78791e7
a1f208b
d1ae9ec
fc605a8
472e68a
c75fe83
0c8ffed
79d9841
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef FPTRS_H | ||
#define FPTRS_H | ||
|
||
#include <stddef.h> /* size_t */ | ||
|
||
#ifdef __cplusplus | ||
namespace gambatte { | ||
extern "C" { | ||
#endif | ||
struct FPtrs { | ||
void (*Save_)(void const *ptr, size_t size, char const *name); | ||
void (*Load_)(void *ptr, size_t size, char const *name); | ||
void (*EnterSection_)(char const *name); | ||
void (*ExitSection_)(char const *name); | ||
}; | ||
#ifdef __cplusplus | ||
} | ||
} | ||
#endif | ||
|
||
#endif /* FPTRS_H */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,12 +27,14 @@ | |
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
#include "fptrs.h" | ||
|
||
typedef struct GB GB; | ||
typedef struct FPtrs FPtrs; | ||
typedef unsigned(InputGetter)(void *); | ||
typedef void (*MemoryCallback)(int32_t address, int64_t cycleOffset); | ||
typedef void (*CDCallback)(int32_t addr, int32_t addrtype, int32_t flags); | ||
#else | ||
#include "fptrs.h" | ||
#include "gambatte.h" | ||
#include "newstate.h" | ||
|
||
|
@@ -43,6 +45,7 @@ using MemoryCallback = gambatte::MemoryCallback; | |
using CDCallback = gambatte::CDCallback; | ||
#endif | ||
|
||
#if defined(LIBGAMBATTE_SHARED) | ||
#if defined(_WIN32) || defined(__CYGWIN__) | ||
#if defined(LIBGAMBATTE_DLL_EXPORT) | ||
#define GBEXPORT __declspec(dllexport) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is used by the user of a dll rather than the dll itself, then dllexport would be incorrect, dllimport is the correct declspec (and I don't think visibility attribrute is correct either for non-Windows cases, rather it should just be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checking GCC's documentation on visibility, you're correct about the dllexport/dllimport. According to that same documentation, for the non-Windows case, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Breaking CI likely indicates it got used internally in the library, or it got used when linking it in statically. You can only use dllimport when you are a user of the library (so not the library itself) and the library is a dll (if it's static, you don't use dllimport/dllexport). |
||
|
@@ -54,6 +57,9 @@ using CDCallback = gambatte::CDCallback; | |
#else | ||
#define GBEXPORT | ||
#endif | ||
#else /* !defined(LIBGAMBATTE_SHARED) */ | ||
#define GBEXPORT | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this might be expected to be #included from a C context (not C++), it may be better to #ifdef this around Similarly, instead of #including gambatte.h or newstate.h, it may be better to just forward declare |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extern "C" here is a bit interesting, technically this is correct, although in practice it typically doesn't actually matter, as most (if not all practical) C++ implementations wouldn't have any issues with a C++ linkage function being assigned to a C linkage function pointer and vice versa (as they function the same at runtime), although this isn't actually guaranteed by the standard (C++ linkage could entail a different calling convention compared to the same function being assigned C linkage, in practice this never occurs).
On that, technically this is not correctly handled in gambatte.h as they all would use C++ (default) linkage, so if we want that to be ""correctly"" done, all those callback definitions need extern "C".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the off chance that there is a compiler out there that defaults to using a different calling convention between C and C++, I went ahead and declared the other function prototypes as
extern "C"
for consistency.Moreover, to make sure the C API is actually usable from C, I added a simple test in c75fe83 that creates and deletes a GB object using the C API.