Skip to content
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

Fix building as shared library with MSVC. #2527

Merged
merged 1 commit into from Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CMake/CatchConfigOptions.cmake
Expand Up @@ -67,6 +67,7 @@ set(_OtherConfigOptions
foreach(OptionName ${_OtherConfigOptions})
AddConfigOption(${OptionName})
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_CONSOLE_WIDTH "80" CACHE STRING "Read docs/configuration.md for details. Must form a valid integer literal.")
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -409,6 +409,10 @@ if (CATCH_BUILD_EXAMPLES OR CATCH_BUILD_EXTRA_TESTS)
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/generated-includes>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_compile_definitions(Catch2_buildall_interface
INTERFACE
CATCH_CONFIG_STATIC
)
target_compile_features(Catch2_buildall_interface
INTERFACE
cxx_alignas
Expand Down
4 changes: 2 additions & 2 deletions src/catch2/catch_tostring.hpp
Expand Up @@ -296,13 +296,13 @@ namespace Catch {
template<>
struct StringMaker<float> {
static std::string convert(float value);
static int precision;
CATCH_EXPORT static int precision;
};

template<>
struct StringMaker<double> {
static std::string convert(double value);
static int precision;
CATCH_EXPORT static int precision;
};

template <typename T>
Expand Down
2 changes: 2 additions & 0 deletions src/catch2/catch_user_config.hpp.in
Expand Up @@ -181,6 +181,8 @@
#cmakedefine CATCH_CONFIG_PREFIX_ALL
#cmakedefine CATCH_CONFIG_WINDOWS_CRTDBG

#cmakedefine CATCH_CONFIG_SHARED_LIBRARY


// ------
// "Variable" defines, these have actual values
Expand Down
10 changes: 10 additions & 0 deletions src/catch2/internal/catch_compiler_capabilities.hpp
Expand Up @@ -376,5 +376,15 @@
# define CATCH_CONFIG_COLOUR_WIN32
#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
4 changes: 3 additions & 1 deletion src/catch2/internal/catch_context.hpp
Expand Up @@ -8,6 +8,8 @@
#ifndef CATCH_CONTEXT_HPP_INCLUDED
#define CATCH_CONTEXT_HPP_INCLUDED

#include <catch2/internal/catch_compiler_capabilities.hpp>

namespace Catch {

class IResultCapture;
Expand All @@ -28,7 +30,7 @@ namespace Catch {
virtual void setConfig( IConfig const* config ) = 0;

private:
static IMutableContext *currentContext;
CATCH_EXPORT static IMutableContext* currentContext;
friend IMutableContext& getCurrentMutableContext();
friend void cleanUpContext();
static void createContext();
Expand Down