Skip to content

Commit 21c0a6b

Browse files
committed
Improve API and build system for windows
- Renaming export and import macros to ADOLC_API to be more explicit what is used for - separate the macro to file in include path to have in installed - add macro to various functions and classes that should be part of the api in windows - adapt / improve cmakefiles
1 parent 5ee6533 commit 21c0a6b

31 files changed

+996
-931
lines changed

ADOL-C/include/adolc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ install(FILES
22
adtb_types.h
33
adalloc.h
44
adolcerror.h
5+
adolcexport.h
56
adolc.h
67
adolc_openmp.h
78
adolc_sparse.h

ADOL-C/include/adolc/adalloc.h

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#if !defined(ADOLC_ADALLOC_H)
1616
#define ADOLC_ADALLOC_H 1
1717

18+
#include <adolc/adolcexport.h>
1819
#include <adolc/internal/common.h>
1920

2021
/****************************************************************************/
@@ -23,37 +24,37 @@ BEGIN_C_DECLS
2324

2425
/*--------------------------------------------------------------------------*/
2526
/* MEMORY MANAGEMENT UTILITIES */
26-
ADOLC_DLL_EXPORT char *populate_dpp(double ***const pointer, char *const memory,
27-
int n, int m);
28-
ADOLC_DLL_EXPORT char *populate_dppp(double ****const pointer,
29-
char *const memory, int n, int m, int p);
30-
ADOLC_DLL_EXPORT char *populate_dppp_nodata(double ****const pointer,
31-
char *const memory, int n, int m);
32-
ADOLC_DLL_EXPORT double *myalloc1(size_t);
33-
ADOLC_DLL_EXPORT double **myalloc2(size_t, size_t);
34-
ADOLC_DLL_EXPORT double ***myalloc3(size_t, size_t, size_t);
35-
36-
ADOLC_DLL_EXPORT void myfree1(double *);
37-
ADOLC_DLL_EXPORT void myfree2(double **);
38-
ADOLC_DLL_EXPORT void myfree3(double ***);
27+
ADOLC_API char *populate_dpp(double ***const pointer, char *const memory, int n,
28+
int m);
29+
ADOLC_API char *populate_dppp(double ****const pointer, char *const memory,
30+
int n, int m, int p);
31+
ADOLC_API char *populate_dppp_nodata(double ****const pointer,
32+
char *const memory, int n, int m);
33+
ADOLC_API double *myalloc1(size_t);
34+
ADOLC_API double **myalloc2(size_t, size_t);
35+
ADOLC_API double ***myalloc3(size_t, size_t, size_t);
36+
37+
ADOLC_API void myfree1(double *);
38+
ADOLC_API void myfree2(double **);
39+
ADOLC_API void myfree3(double ***);
3940

4041
/*--------------------------------------------------------------------------*/
4142
/* SPECIAL IDENTITY REPRESENTATION */
42-
ADOLC_DLL_EXPORT double **myallocI2(int);
43-
ADOLC_DLL_EXPORT void myfreeI2(int, double **);
43+
ADOLC_API double **myallocI2(int);
44+
ADOLC_API void myfreeI2(int, double **);
4445

45-
ADOLC_DLL_EXPORT unsigned int *myalloc1_uint(int);
46+
ADOLC_API unsigned int *myalloc1_uint(int);
4647

47-
ADOLC_DLL_EXPORT size_t *myalloc1_ulong(int);
48-
ADOLC_DLL_EXPORT size_t **myalloc2_ulong(int, int);
48+
ADOLC_API size_t *myalloc1_ulong(int);
49+
ADOLC_API size_t **myalloc2_ulong(int, int);
4950

5051
/****************************************************************************/
5152
/* INTEGER VARIANT FOR BIT PATTERN PROPAGATION */
5253

53-
ADOLC_DLL_EXPORT void myfree1_uint(unsigned int *);
54+
ADOLC_API void myfree1_uint(unsigned int *);
5455

55-
ADOLC_DLL_EXPORT void myfree1_ulong(size_t *);
56-
ADOLC_DLL_EXPORT void myfree2_ulong(size_t **);
56+
ADOLC_API void myfree1_ulong(size_t *);
57+
ADOLC_API void myfree2_ulong(size_t **);
5758

5859
END_C_DECLS
5960

@@ -63,13 +64,15 @@ END_C_DECLS
6364

6465
/*--------------------------------------------------------------------------*/
6566
/* MEMORY MANAGEMENT UTILITIES */
66-
inline double *myalloc(int n) { return myalloc1(n); }
67-
inline double **myalloc(int m, int n) { return myalloc2(m, n); }
68-
inline double ***myalloc(int m, int n, int p) { return myalloc3(m, n, p); }
69-
70-
inline void myfree(double *A) { myfree1(A); }
71-
inline void myfree(double **A) { myfree2(A); }
72-
inline void myfree(double ***A) { myfree3(A); }
67+
ADOLC_API inline double *myalloc(int n) { return myalloc1(n); }
68+
ADOLC_API inline double **myalloc(int m, int n) { return myalloc2(m, n); }
69+
ADOLC_API inline double ***myalloc(int m, int n, int p) {
70+
return myalloc3(m, n, p);
71+
}
72+
73+
ADOLC_API inline void myfree(double *A) { myfree1(A); }
74+
ADOLC_API inline void myfree(double **A) { myfree2(A); }
75+
ADOLC_API inline void myfree(double ***A) { myfree3(A); }
7376

7477
#endif
7578

ADOL-C/include/adolc/adolcerror.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef ADOLC_ERROR_H
1616
#define ADOLC_ERROR_H
1717

18+
#include <adolc/adolcexport.h>
1819
#include <sstream>
1920
#include <stdexcept>
2021
#include <string>
@@ -72,7 +73,7 @@ struct source_location {
7273
* }
7374
* @endcode
7475
*/
75-
class ADOLCError : public std::runtime_error {
76+
class ADOLC_API ADOLCError : public std::runtime_error {
7677

7778
source_location info_;
7879

@@ -105,7 +106,7 @@ class ADOLCError : public std::runtime_error {
105106
const source_location &where() const noexcept { return info_; }
106107
};
107108

108-
enum class ErrorType : size_t {
109+
enum class ADOLC_API ErrorType : size_t {
109110
MALLOC_FAILED,
110111
INTEGER_TAPE_FOPEN_FAILED,
111112
INTEGER_TAPE_FREAD_FAILED,
@@ -237,7 +238,7 @@ enum class ErrorType : size_t {
237238
};
238239

239240
// wrapper for information of errors
240-
struct FailInfo {
241+
struct ADOLC_API FailInfo {
241242
short info1{0}; // for tapeId
242243
size_t info2{0};
243244
int info3{0}; // deps
@@ -257,14 +258,14 @@ template <typename T> constexpr auto to_underlying(T t) noexcept {
257258
/*--------------------------------------------------------------------------*/
258259
// prints an error message describing the error type coming from a file function
259260
// (e.g. fopen)
260-
void printError();
261+
void ADOLC_API printError();
261262

262263
// would like to use always CURRENT_LOCATION as default but this
263264
// does not work for all compilers sometimes the funciton names are empty.
264265
// Currently you have to call CURRENT_LOCATION when calling fail
265266
// by hand
266-
void fail(ErrorType error, const source_location LocInfo,
267-
const FailInfo &failinfo = FailInfo());
267+
void ADOLC_API fail(ErrorType error, const source_location LocInfo,
268+
const FailInfo &failinfo = FailInfo());
268269

269270
} // namespace ADOLCError
270271
#endif // ADOLC_ERROR_H

ADOL-C/include/adolc/adolcexport.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef ADOLC_EXPORT_H
2+
#define ADOLC_EXPORT_H
3+
4+
/* Under windows we have to explicit state which symbols (functions, classes,
5+
* etc) are exportet when compiling a SHARED library. The dllimport specifies if
6+
* a user builds its code with adolc that the symbols are defined somewhere
7+
* else.
8+
*/
9+
#ifdef _WIN32
10+
#ifdef BUILD_ADOLC
11+
#define ADOLC_API __declspec(dllexport)
12+
#else
13+
#define ADOLC_API __declspec(dllimport)
14+
#endif
15+
#else
16+
#define ADOLC_API
17+
#endif
18+
19+
#endif // ADOLC_EXPORT_H

0 commit comments

Comments
 (0)