Fix building as shared library with MSVC.

This commit is contained in:
Dimitrij Mijoski 2022-09-17 14:58:52 +02:00 committed by Martin Hořeňovský
parent 0de60d8e7e
commit c0e582e659
6 changed files with 22 additions and 3 deletions

View File

@ -67,6 +67,7 @@ set(_OtherConfigOptions
foreach(OptionName ${_OtherConfigOptions}) foreach(OptionName ${_OtherConfigOptions})
AddConfigOption(${OptionName}) AddConfigOption(${OptionName})
endforeach() endforeach()
set(CATCH_CONFIG_SHARED_LIBRARY ${BUILD_SHARED_LIBS})
set(CATCH_CONFIG_DEFAULT_REPORTER "console" CACHE STRING "Read docs/configuration.md for details. The name of the reporter should be without quotes.") set(CATCH_CONFIG_DEFAULT_REPORTER "console" CACHE STRING "Read docs/configuration.md for details. The name of the reporter should be without quotes.")
set(CATCH_CONFIG_CONSOLE_WIDTH "80" CACHE STRING "Read docs/configuration.md for details. Must form a valid integer literal.") set(CATCH_CONFIG_CONSOLE_WIDTH "80" CACHE STRING "Read docs/configuration.md for details. Must form a valid integer literal.")

View File

@ -409,6 +409,10 @@ if (CATCH_BUILD_EXAMPLES OR CATCH_BUILD_EXTRA_TESTS)
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/generated-includes> $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/generated-includes>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
) )
target_compile_definitions(Catch2_buildall_interface
INTERFACE
CATCH_CONFIG_STATIC
)
target_compile_features(Catch2_buildall_interface target_compile_features(Catch2_buildall_interface
INTERFACE INTERFACE
cxx_alignas cxx_alignas

View File

@ -296,13 +296,13 @@ namespace Catch {
template<> template<>
struct StringMaker<float> { struct StringMaker<float> {
static std::string convert(float value); static std::string convert(float value);
static int precision; CATCH_EXPORT static int precision;
}; };
template<> template<>
struct StringMaker<double> { struct StringMaker<double> {
static std::string convert(double value); static std::string convert(double value);
static int precision; CATCH_EXPORT static int precision;
}; };
template <typename T> template <typename T>

View File

@ -181,6 +181,8 @@
#cmakedefine CATCH_CONFIG_PREFIX_ALL #cmakedefine CATCH_CONFIG_PREFIX_ALL
#cmakedefine CATCH_CONFIG_WINDOWS_CRTDBG #cmakedefine CATCH_CONFIG_WINDOWS_CRTDBG
#cmakedefine CATCH_CONFIG_SHARED_LIBRARY
// ------ // ------
// "Variable" defines, these have actual values // "Variable" defines, these have actual values

View File

@ -382,5 +382,15 @@
# define CATCH_CONFIG_COLOUR_WIN32 # define CATCH_CONFIG_COLOUR_WIN32
#endif #endif
#if defined( CATCH_CONFIG_SHARED_LIBRARY ) && defined( _MSC_VER ) && \
!defined( CATCH_CONFIG_STATIC )
# ifdef Catch2_EXPORTS
# define CATCH_EXPORT //__declspec( dllexport ) // not needed
# else
# define CATCH_EXPORT __declspec( dllimport )
# endif
#else
# define CATCH_EXPORT
#endif
#endif // CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED #endif // CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED

View File

@ -8,6 +8,8 @@
#ifndef CATCH_CONTEXT_HPP_INCLUDED #ifndef CATCH_CONTEXT_HPP_INCLUDED
#define CATCH_CONTEXT_HPP_INCLUDED #define CATCH_CONTEXT_HPP_INCLUDED
#include <catch2/internal/catch_compiler_capabilities.hpp>
namespace Catch { namespace Catch {
class IResultCapture; class IResultCapture;
@ -28,7 +30,7 @@ namespace Catch {
virtual void setConfig( IConfig const* config ) = 0; virtual void setConfig( IConfig const* config ) = 0;
private: private:
static IMutableContext *currentContext; CATCH_EXPORT static IMutableContext* currentContext;
friend IMutableContext& getCurrentMutableContext(); friend IMutableContext& getCurrentMutableContext();
friend void cleanUpContext(); friend void cleanUpContext();
static void createContext(); static void createContext();