From 0938f82c32b3c5a99008a54ee29cea3a785c9707 Mon Sep 17 00:00:00 2001 From: Michael Tryby Date: Wed, 22 Aug 2018 15:46:24 -0400 Subject: [PATCH] Adding adding GEN_X macro for cmake export header --- CMakeLists.txt | 15 +++++++----- include/epanet2.h | 61 +++++++++++++++++++++++++---------------------- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index acb522c..d5bf92b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,12 +80,15 @@ target_include_directories(epanet PUBLIC ${PROJECT_SOURCE_DIR}/include) # create export lib so we can link against dll using Visual Studio -include(GenerateExportHeader) -GENERATE_EXPORT_HEADER(epanet - BASE_NAME epanet - EXPORT_MACRO_NAME DLLEXPORT - EXPORT_FILE_NAME epanet_export.h - STATIC_DEFINE SHARED_EXPORTS_BUILT_AS_STATIC) +IF (GEN_X) + include(GenerateExportHeader) + GENERATE_EXPORT_HEADER(epanet + BASE_NAME epanet + EXPORT_MACRO_NAME DLLEXPORT + EXPORT_FILE_NAME epanet_export.h + STATIC_DEFINE SHARED_EXPORTS_BUILT_AS_STATIC) + file(COPY ${CMAKE_CURRENT_BINARY_DIR}/epanet_export.h DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/include) +ENDIF (GEN_X) diff --git a/include/epanet2.h b/include/epanet2.h index 85e1170..02b9033 100644 --- a/include/epanet2.h +++ b/include/epanet2.h @@ -30,37 +30,40 @@ #define EN_API_FLOAT_TYPE float #endif -// // --- define WINDOWS -// #undef WINDOWS -// #ifdef _WIN32 -// #define WINDOWS -// #endif -// #ifdef __WIN32__ -// #define WINDOWS -// #endif +#ifdef GEN_X + #include "epanet_export.h" +#else + // --- define WINDOWS + #undef WINDOWS + #ifdef _WIN32 + #define WINDOWS + #endif + #ifdef __WIN32__ + #define WINDOWS + #endif -// // --- define DLLEXPORT -// #ifndef DLLEXPORT -// #ifdef WINDOWS -// #ifdef __cplusplus -// #define DLLEXPORT __declspec(dllexport) -// #else -// #define DLLEXPORT __declspec(dllexport) __stdcall -// #endif // __cplusplus -// #elif defined(CYGWIN) -// #define DLLEXPORT __stdcall -// #elif defined(__APPLE__) -// #ifdef __cplusplus -// #define DLLEXPORT -// #else -// #define DLLEXPORT -// #endif -// #else -// #define DLLEXPORT -// #endif -// #endif + // --- define DLLEXPORT + #ifndef DLLEXPORT + #ifdef WINDOWS + #ifdef __cplusplus + #define DLLEXPORT __declspec(dllexport) + #else + #define DLLEXPORT __declspec(dllexport) __stdcall + #endif // __cplusplus + #elif defined(CYGWIN) + #define DLLEXPORT __stdcall + #elif defined(__APPLE__) + #ifdef __cplusplus + #define DLLEXPORT + #else + #define DLLEXPORT + #endif + #else + #define DLLEXPORT + #endif + #endif +#endif -#include "epanet_export.h" // --- Define the EPANET toolkit constants