diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..75029fb --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.14) + +project(base64 + VERSION 1.0.0 + DESCRIPTION "Base64 Encoder/Decoder" + LANGUAGES C CXX +) + +set(SOURCES + base64.cpp +) + +set(HEADERS + base64.h +) + +if(BUILD_SHARED_LIBS) + add_library(${PROJECT_NAME} SHARED) + target_compile_definitions(${PROJECT_NAME} PUBLIC CXXBASE64_EXPORTS) +else() + add_library(${PROJECT_NAME} STATIC) + target_compile_definitions(${PROJECT_NAME} PUBLIC CXXBASE64_STATIC_DEFINE) +endif() + +add_library(BASE64::base64 ALIAS ${PROJECT_NAME}) + +target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_sources(${PROJECT_NAME} PRIVATE ${SOURCES}) +target_sources(${PROJECT_NAME} PRIVATE ${HEADERS}) + +target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17) + +if(BUILD_SHARED_LIBS) + set_target_properties(${PROJECT_NAME} PROPERTIES + CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN ON + ) +endif() \ No newline at end of file diff --git a/base64.h b/base64.h index 4860d63..019bd27 100644 --- a/base64.h +++ b/base64.h @@ -6,18 +6,19 @@ #ifndef BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A #define BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A +#include #include #if __cplusplus >= 201703L #include #endif // __cplusplus >= 201703L -std::string base64_encode (std::string const& s, bool url = false); -std::string base64_encode_pem (std::string const& s); -std::string base64_encode_mime(std::string const& s); +std::string CXXBASE64_API base64_encode (std::string const& s, bool url = false); +std::string CXXBASE64_API base64_encode_pem (std::string const& s); +std::string CXXBASE64_API base64_encode_mime(std::string const& s); -std::string base64_decode(std::string const& s, bool remove_linebreaks = false); -std::string base64_encode(unsigned char const*, size_t len, bool url = false); +std::string CXXBASE64_API base64_decode(std::string const& s, bool remove_linebreaks = false); +std::string CXXBASE64_API base64_encode(unsigned char const*, size_t len, bool url = false); #if __cplusplus >= 201703L // @@ -25,11 +26,11 @@ std::string base64_encode(unsigned char const*, size_t len, bool url = false); // Requires C++17 // Provided by Yannic Bonenberger (https://github.com/Yannic) // -std::string base64_encode (std::string_view s, bool url = false); -std::string base64_encode_pem (std::string_view s); -std::string base64_encode_mime(std::string_view s); +std::string CXXBASE64_API base64_encode (std::string_view s, bool url = false); +std::string CXXBASE64_API base64_encode_pem (std::string_view s); +std::string CXXBASE64_API base64_encode_mime(std::string_view s); -std::string base64_decode(std::string_view s, bool remove_linebreaks = false); +std::string CXXBASE64_API base64_decode(std::string_view s, bool remove_linebreaks = false); #endif // __cplusplus >= 201703L #endif /* BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A */ diff --git a/base64_api.h b/base64_api.h new file mode 100644 index 0000000..a948aa4 --- /dev/null +++ b/base64_api.h @@ -0,0 +1,92 @@ +#ifndef _CXXBASE64_API_H_ +#define _CXXBASE64_API_H_ + + +#ifdef CXXBASE64_STATIC_DEFINE /* Define if compiling as a static library (-DCXXBASE64_STATIC_DEFINE) */ +# define CXXBASE64_API +# define CXXBASE64_NO_EXPORT +#else +# ifndef CXXBASE64_API +# ifdef CXXBASE64_EXPORTS /* We are building this library */ +# if defined _WIN32 || defined _WIN64 || defined __CYGWIN__ || defined __MINGW64__ +# if defined __GNUC__ || defined __clang__ +# define CXXBASE64_API __attribute__ ((dllexport)) +# else +# define CXXBASE64_API __declspec(dllexport) +# endif +# else +# if (defined __GNUC__ && __GNUC__ >= 4) || defined __clang__ +# define CXXBASE64_API __attribute__ ((visibility ("default"))) +# endif +# endif +# else /* We are using this library */ +# if defined _WIN32 || defined _WIN64 || defined __CYGWIN__ || defined __MINGW64__ +# if defined __GNUC__ || defined __clang__ +# define CXXBASE64_API __attribute__ ((dllimport)) +# else +# define CXXBASE64_API __declspec(dllimport) +# endif +# else +# if defined __GNUC__ && __GNUC__ >= 4 +# define CXXBASE64_API +# endif +# endif +# endif +# else /* Should Only reach here for non-*nix, un-supported platforms */ +# warning "Platform Unsupported - Either Not a derivative of Unix // Not Windows" +# define CXXBASE64_API +# endif +# ifndef CXXBASE64_NO_EXPORT +# if defined __GNUC__ && __GNUC__ >= 4 /* Symbols exported by default on *nix systems */ +# define CXXBASE64_NO_EXPORT __attribute__((visibility ("hidden"))) +# else /* (DLL) Symbols on platforms like windows must be exported manually [__declspec(dllexport)] */ +# define CXXBASE64_NO_EXPORT +# endif +# endif +#endif + + +#ifndef CXXBASE64_DEPRECATED +# if defined(__cplusplus) +# if __cplusplus >= 201402L /* [[deprecated]] Supported since C++14 */ +# define CXXBASE64_DEPRECATED [[deprecated]] +# define CXXBASE64_DEPRECATED_MSG(MSG) [[deprecated(MSG)]] +# endif +# else +# if defined _WIN32 || defined _WIN64 +# if defined __GNUC__ || defined __clang__ /* Cygwin, MinGW32/64 */ +# define CXXBASE64_DEPRECATED __attribute__((deprecated)) +# define CXXBASE64_DEPRECATED_MSG(MSG) __attribute__((deprecated(MSG))) +# else +# define CXXBASE64_DEPRECATED __declspec(deprecated) +# define CXXBASE64_DEPRECATED_MSG(MSG) __declspec(deprecated(MSG)) +# endif +# elif defined __GNUC__ || defined __clang__ +# define CXXBASE64_DEPRECATED __attribute__((deprecated)) +# define CXXBASE64_DEPRECATED_MSG(MSG) __attribute__((deprecated(MSG))) +# else /* Should Only reach here for non-*nix, un-supported platforms */ +# define CXXBASE64_DEPRECATED +# define CXXBASE64_DEPRECATED_MSG(MSG) +# endif +# endif +#endif + + +#ifndef CXXBASE64_DEPRECATED_EXPORT +# define CXXBASE64_DEPRECATED_EXPORT CXXBASE64_API CXXBASE64_DEPRECATED +#endif + + +#ifndef CXXBASE64_DEPRECATED_NO_EXPORT +# define CXXBASE64_DEPRECATED_NO_EXPORT CXXBASE64_NO_EXPORT CXXBASE64_DEPRECATED +#endif + + +/* NOLINTNEXTLINE(readability-avoid-unconditional-preprocessor-if) */ +#if 0 /* DEFINE_NO_DEPRECATED */ +# ifndef CXXBASE64_NO_DEPRECATED +# define CXXBASE64_NO_DEPRECATED +# endif +#endif + +#endif /* _CXXBASE64_API_H_ */