diff --git a/Base/CMakeLists.txt b/Base/CMakeLists.txt index 994c10a8b3e34dc1341a6aa1c804e02c9a773723..9c145e15c688f6a7920d2ec0b3b17f2eab2a21c2 100644 --- a/Base/CMakeLists.txt +++ b/Base/CMakeLists.txt @@ -49,3 +49,7 @@ if(CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) target_link_libraries(${lib} PRIVATE c++fs) endif() endif() + +if(WIN32) + target_compile_definitions(${lib} PRIVATE -DBA_BASE_BUILD_DLL) +endif() diff --git a/Base/Util/Assert.h b/Base/Util/Assert.h index 1b9f394cc94274eb304ded8b30ba5d8c8b68c37d..7e8a61a4e75aca38a5ca82b69bf063d7837f99fc 100644 --- a/Base/Util/Assert.h +++ b/Base/Util/Assert.h @@ -18,12 +18,14 @@ #ifndef BORNAGAIN_BASE_UTIL_ASSERT_H #define BORNAGAIN_BASE_UTIL_ASSERT_H +#include "Wrap/WinDllMacros.h" #include <functional> #include <sstream> #include <stdexcept> #include <string> -extern std::function<void(std::string)> failedAssertion; // set in Assert.cpp, overriden by GUI +// Function called upon failed assert; set in Assert.cpp, overriden by GUI. +extern BA_BASE_API_ std::function<void(std::string)> failedAssertion; // ASSERT must be declared as a macro, not a function, in order for the error // message to correctly report the source line where the assertion failed. diff --git a/Wrap/WinDllMacros.h b/Wrap/WinDllMacros.h new file mode 100644 index 0000000000000000000000000000000000000000..6f3ac0e353967cb41706874a2f4628971f80c020 --- /dev/null +++ b/Wrap/WinDllMacros.h @@ -0,0 +1,41 @@ +// ************************************************************************************************ +// +// BornAgain: simulate and fit reflection and scattering +// +//! @file Wrap/WinDllMacros.h +//! @brief Defines export/import macros for global data symbols +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +// +// ************************************************************************************************ + +#ifndef BORNAGAIN_WRAP_WINDLLMACROS_H +#define BORNAGAIN_WRAP_WINDLLMACROS_H + +//! Macros for export/import global functions and variables (Windows only). +//! +//! Needed for Windows, empty for Linux and Mac. +//! +//! Note that classes and other non-data symbols are exported automatically thanks to +//! the CMake variable CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS. +//! +//! One such macro is needed for each component library that exports data sybols. + +#ifdef _WIN32 + +#ifdef BA_BASE_BUILD_DLL +#define BA_BASE_API_ __declspec(dllexport) +#else +#define BA_BASE_API_ __declspec(dllimport) +#endif // BA_BASE_BUILD_DLL + +#else // not _WIN32 + +#define BA_BASE_API_ + +#endif // _WIN32 + +#endif // BORNAGAIN_WRAP_WINDLLMACROS_H