[DO-987] catch recipe (!3)

Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech>
Reviewed-on: https://git.avroid.tech/Conan/conan_build/pulls/3
Reviewed-by: Denis Patrakeev <denis.patrakeev@avroid.team>
Co-authored-by: Aleksandr Vodyanov <aleksandr.vodyanov@avroid.team>
Co-committed-by: Aleksandr Vodyanov <aleksandr.vodyanov@avroid.team>
This commit is contained in:
Aleksandr Vodyanov
2024-11-21 17:23:08 +03:00
committed by Denis Patrakeev
parent bb6197bed7
commit e3106d807c
27 changed files with 928 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -263,9 +263,7 @@ set(REPORTER_SOURCES
)
set(REPORTER_FILES ${REPORTER_HEADERS} ${REPORTER_SOURCES})
-# Fixme: STATIC because for dynamic, we would need to handle visibility
-# and I don't want to do the annotations right now
-add_library(Catch2 STATIC
+add_library(Catch2
${REPORTER_FILES}
${INTERNAL_FILES}
${BENCHMARK_HEADERS}
@@ -318,7 +316,7 @@ target_include_directories(Catch2
)
-add_library(Catch2WithMain STATIC
+add_library(Catch2WithMain
${SOURCES_DIR}/internal/catch_main.cpp
)
add_build_reproducibility_settings(Catch2WithMain)
@@ -338,8 +336,12 @@ if (NOT_SUBPROJECT)
Catch2WithMain
EXPORT
Catch2Targets
- DESTINATION
+ LIBRARY DESTINATION
+ ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION
${CMAKE_INSTALL_LIBDIR}
+ RUNTIME DESTINATION
+ ${CMAKE_INSTALL_BINDIR}
)
@@ -409,3 +411,27 @@ endif()
list(APPEND CATCH_WARNING_TARGETS Catch2 Catch2WithMain)
set(CATCH_WARNING_TARGETS ${CATCH_WARNING_TARGETS} PARENT_SCOPE)
+
+
+# We still do not support building dynamic library with hidden visibility
+# so we want to check & warn users if they do this. However, we won't abort
+# the configuration step so that we don't have to also provide an override.
+if (BUILD_SHARED_LIBS)
+ if (MSVC)
+ set_target_properties(Catch2 Catch2WithMain
+ PROPERTIES
+ WINDOWS_EXPORT_ALL_SYMBOLS ON
+ )
+ endif()
+
+ get_target_property(_VisPreset Catch2 CXX_VISIBILITY_PRESET)
+ if (NOT MSVC AND _VisPreset STREQUAL "hidden")
+ set_target_properties(Catch2 Catch2WithMain
+ PROPERTIES
+ CXX_VISIBILITY_PRESET "default"
+ VISIBILITY_INLINES_HIDDEN OFF
+ )
+ message(WARNING "Setting Catch2's visibility to default."
+ " Hidden visibility is not supported.")
+ endif()
+endif()

View File

@@ -0,0 +1,77 @@
--- a/CMake/CatchConfigOptions.cmake
+++ b/CMake/CatchConfigOptions.cmake
@@ -45,6 +45,7 @@ set(_OverridableOptions
foreach(OptionName ${_OverridableOptions})
AddOverridableConfigOption(${OptionName})
endforeach()
+set(CATCH_CONFIG_SHARED_LIBRARY ${BUILD_SHARED_LIBS})
set(_OtherConfigOptions
"DISABLE_EXCEPTIONS"
--- a/src/catch2/catch_tostring.hpp
+++ b/src/catch2/catch_tostring.hpp
@@ -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>
--- a/src/catch2/catch_user_config.hpp.in
+++ b/src/catch2/catch_user_config.hpp.in
@@ -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
--- a/src/catch2/internal/catch_compiler_capabilities.hpp
+++ b/src/catch2/internal/catch_compiler_capabilities.hpp
@@ -364,5 +364,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
--- a/src/catch2/internal/catch_context.hpp
+++ b/src/catch2/internal/catch_context.hpp
@@ -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;
@@ -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();

View File

@@ -0,0 +1,16 @@
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -359,8 +359,12 @@ if (NOT_SUBPROJECT)
Catch2WithMain
EXPORT
Catch2Targets
- DESTINATION
+ LIBRARY DESTINATION
+ ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION
${CMAKE_INSTALL_LIBDIR}
+ RUNTIME DESTINATION
+ ${CMAKE_INSTALL_BINDIR}
)

View File

@@ -0,0 +1,77 @@
--- a/CMake/CatchConfigOptions.cmake
+++ b/CMake/CatchConfigOptions.cmake
@@ -45,6 +45,7 @@ set(_OverridableOptions
foreach(OptionName ${_OverridableOptions})
AddOverridableConfigOption(${OptionName})
endforeach()
+set(CATCH_CONFIG_SHARED_LIBRARY ${BUILD_SHARED_LIBS})
set(_OtherConfigOptions
"DISABLE_EXCEPTIONS"
--- a/src/catch2/catch_tostring.hpp
+++ b/src/catch2/catch_tostring.hpp
@@ -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>
--- a/src/catch2/catch_user_config.hpp.in
+++ b/src/catch2/catch_user_config.hpp.in
@@ -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
--- a/src/catch2/internal/catch_compiler_capabilities.hpp
+++ b/src/catch2/internal/catch_compiler_capabilities.hpp
@@ -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
--- a/src/catch2/internal/catch_context.hpp
+++ b/src/catch2/internal/catch_context.hpp
@@ -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;
@@ -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();