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

Only export restbed symbols when building as a shared library + fix MinGW build #532

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ if ( NOT DEFINED CMAKE_INSTALL_LIBDIR )
set( CMAKE_INSTALL_LIBDIR "library")
endif ( )

if ( NOT DEFINED CMAKE_INSTALL_BINDIR )
set( CMAKE_INSTALL_BINDIR "binary")
endif ( )

if ( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
set( CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/distribution" CACHE PATH "Install path prefix" FORCE )
endif ( )

if( ${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC )
if( CMAKE_CXX_COMPILER_ID STREQUAL MSVC )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_WIN32_WINNT=0x0601 /W4 /wd4068 /wd4702 /wd4996 /wd4265" )
endif ( )

Expand Down Expand Up @@ -64,8 +68,7 @@ if ( BUILD_IPC )
add_definitions( "-DBUILD_IPC" )
endif ( )

if ( WIN32 )
add_definitions( -DWIN_DLL_EXPORT )
if ( CMAKE_CXX_COMPILER STREQUAL "MSVC" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251" )
endif ( )

Expand All @@ -84,10 +87,14 @@ set( SHARED_LIBRARY_NAME "${PROJECT_NAME}-shared" )
add_library( ${SHARED_LIBRARY_NAME} SHARED ${MANIFEST} )
set_property( TARGET ${SHARED_LIBRARY_NAME} PROPERTY CXX_STANDARD 14 )
set_property( TARGET ${SHARED_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON )
set_property( TARGET ${SHARED_LIBRARY_NAME} PROPERTY CXX_VISIBILITY_PRESET "hidden" )
set_property( TARGET ${SHARED_LIBRARY_NAME} PROPERTY DEFINE_SYMBOL "RESTBED_BUILDING_DLL" )

target_include_directories(${SHARED_LIBRARY_NAME} SYSTEM PUBLIC ${asio_INCLUDE} ${ssl_INCLUDE} ${INCLUDE_DIR})
target_include_directories(${STATIC_LIBRARY_NAME} SYSTEM PUBLIC ${asio_INCLUDE} ${ssl_INCLUDE} ${INCLUDE_DIR})

target_compile_definitions(${STATIC_LIBRARY_NAME} PUBLIC RESTBED_STATIC )

if ( WIN32 )
# Workaround to avoid name clash of static lib and dynamic import lib under windows.
set_target_properties( ${SHARED_LIBRARY_NAME} PROPERTIES OUTPUT_NAME "${PROJECT_NAME}-shared" )
Expand All @@ -97,13 +104,18 @@ endif ( )
set_target_properties( ${SHARED_LIBRARY_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} )

if ( BUILD_SSL )
target_link_libraries( ${SHARED_LIBRARY_NAME} LINK_PRIVATE ${ssl_LIBRARY_SHARED} ${crypto_LIBRARY_SHARED} )
target_link_libraries( ${STATIC_LIBRARY_NAME} LINK_PRIVATE ${ssl_LIBRARY_STATIC} ${crypto_LIBRARY_STATIC} ${CMAKE_DL_LIBS} )
else ( )
target_link_libraries( ${SHARED_LIBRARY_NAME} )
target_link_libraries( ${SHARED_LIBRARY_NAME} PRIVATE ${ssl_LIBRARY_SHARED} ${crypto_LIBRARY_SHARED} )
target_link_libraries( ${STATIC_LIBRARY_NAME} PRIVATE ${ssl_LIBRARY_STATIC} ${crypto_LIBRARY_STATIC} )
endif ( )
if ( NOT WIN32 )
target_link_libraries( ${STATIC_LIBRARY_NAME} ${CMAKE_DL_LIBS} )
endif ( )

if ( WIN32 )
target_link_libraries( ${SHARED_LIBRARY_NAME} PRIVATE ws2_32 mswsock )
target_link_libraries( ${STATIC_LIBRARY_NAME} PRIVATE ws2_32 mswsock )
endif ( )

if ( BUILD_TESTS )
find_package( catch REQUIRED )

Expand All @@ -122,4 +134,4 @@ file( GLOB ARTIFACTS "${SOURCE_DIR}/*.hpp" )
install( FILES "${INCLUDE_DIR}/${PROJECT_NAME}" DESTINATION "${CMAKE_INSTALL_PREFIX}/include" )
install( FILES ${ARTIFACTS} DESTINATION "${CMAKE_INSTALL_PREFIX}/include/corvusoft/${PROJECT_NAME}" )
install( TARGETS ${STATIC_LIBRARY_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT library )
install( TARGETS ${SHARED_LIBRARY_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT library )
install( TARGETS ${SHARED_LIBRARY_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT library )
14 changes: 2 additions & 12 deletions source/corvusoft/restbed/context_placeholder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@

//Project Includes
#include <corvusoft/restbed/context_placeholder_base.hpp>
#include <corvusoft/restbed/export.hpp>

//External Includes

//Windows DLL Exports
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(_WIN64)
#ifdef WIN_DLL_EXPORT
#define CONTEXT_PLACEHOLDER_EXPORT __declspec(dllexport)
#else
#define CONTEXT_PLACEHOLDER_EXPORT __declspec(dllimport)
#endif
#else
#define CONTEXT_PLACEHOLDER_EXPORT __attribute__((visibility ("default")))
#endif

//System Namespaces

//Project Namespaces
Expand All @@ -34,7 +24,7 @@ namespace restbed
//Forward Declarations

template< typename Type >
class CONTEXT_PLACEHOLDER_EXPORT ContextPlaceholder : public ContextPlaceholderBase
class RESTBED_EXPORT ContextPlaceholder : public ContextPlaceholderBase
{
public:
//Friends
Expand Down
14 changes: 2 additions & 12 deletions source/corvusoft/restbed/context_placeholder_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,10 @@
#include <typeinfo>

//Project Includes
#include <corvusoft/restbed/context_placeholder_base.hpp>

//External Includes

//Windows DLL Exports
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(_WIN64)
#ifdef WIN_DLL_EXPORT
#define CONTEXT_PLACEHOLDER_BASE_EXPORT __declspec(dllexport)
#else
#define CONTEXT_PLACEHOLDER_BASE_EXPORT __declspec(dllimport)
#endif
#else
#define CONTEXT_PLACEHOLDER_BASE_EXPORT __attribute__((visibility ("default")))
#endif

//System Namespaces

//Project Namespaces
Expand All @@ -32,7 +22,7 @@ namespace restbed
{
//Forward Declarations

class CONTEXT_PLACEHOLDER_BASE_EXPORT ContextPlaceholderBase
class RESTBED_EXPORT ContextPlaceholderBase
{
public:
//Friends
Expand Down
14 changes: 2 additions & 12 deletions source/corvusoft/restbed/context_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,10 @@
//Project Includes
#include <corvusoft/restbed/context_placeholder.hpp>
#include <corvusoft/restbed/context_placeholder_base.hpp>
#include <corvusoft/restbed/export.hpp>

//External Includes

//Windows DLL Exports
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(_WIN64)
#ifdef WIN_DLL_EXPORT
#define CONTEXT_VALUE_EXPORT __declspec(dllexport)
#else
#define CONTEXT_VALUE_EXPORT __declspec(dllimport)
#endif
#else
#define CONTEXT_VALUE_EXPORT __attribute__((visibility ("default")))
#endif

//System Namespaces

//Project Namespaces
Expand All @@ -37,7 +27,7 @@ namespace restbed
{
//Forward Declarations

class CONTEXT_VALUE_EXPORT ContextValue
class RESTBED_EXPORT ContextValue
{
public:
//Friends
Expand Down
23 changes: 23 additions & 0 deletions source/corvusoft/restbed/export.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2022, Corvusoft Ltd, All Rights Reserved.
*/

#pragma once

#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(_WIN64)
#define RESTBED_SHARED_EXPORT __declspec(dllexport)
#define RESTBED_SHARED_IMPORT __declspec(dllimport)
#else
#define RESTBED_SHARED_EXPORT __attribute__((visibility("default")))
#define RESTBED_SHARED_IMPORT
#endif

#if !defined(RESTBED_STATIC)
#if defined(RESTBED_BUILDING_DLL)
#define RESTBED_EXPORT RESTBED_SHARED_EXPORT
#else
#define RESTBED_EXPORT RESTBED_SHARED_IMPORT
#endif
#else
#define RESTBED_EXPORT
#endif
9 changes: 2 additions & 7 deletions source/corvusoft/restbed/http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,15 @@

//Project Includes
#include <corvusoft/restbed/byte.hpp>
#include <corvusoft/restbed/export.hpp>

//External Includes

//Windows DLL Exports
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(_WIN64)
#ifdef WIN_DLL_EXPORT
#define HTTP_EXPORT __declspec(dllexport)
#else
#define HTTP_EXPORT __declspec(dllimport)
#endif
#define DEPRECATED(MSG) __declspec(deprecated(MSG))
#else
// gcc11 and clang12 don't like mixing __attribute__ and [[deprecated(MSG)]]
#define HTTP_EXPORT __attribute__((visibility ("default")))
#define DEPRECATED(MSG) __attribute__((__deprecated__(MSG)))
#endif

Expand All @@ -43,7 +38,7 @@ namespace restbed
class Response;
class Settings;

class DEPRECATED("HTTP client is deprecated; we will release a complimentary client framework at a future date.") HTTP_EXPORT Http
class DEPRECATED("HTTP client is deprecated; we will release a complimentary client framework at a future date.") RESTBED_EXPORT Http
{
public:
//Friends
Expand Down
14 changes: 2 additions & 12 deletions source/corvusoft/restbed/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,10 @@
#include <memory>

//Project Includes
#include <corvusoft/restbed/export.hpp>

//External Includes

//Windows DLL Exports
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(_WIN64)
#ifdef WIN_DLL_EXPORT
#define LOGGER_EXPORT __declspec(dllexport)
#else
#define LOGGER_EXPORT __declspec(dllimport)
#endif
#else
#define LOGGER_EXPORT __attribute__((visibility ("default")))
#endif

//System Namespaces

//Project Namespaces
Expand All @@ -38,7 +28,7 @@ namespace restbed
//Forward Declarations
class Settings;

class LOGGER_EXPORT Logger
class RESTBED_EXPORT Logger
{
public:
//Friends
Expand Down
14 changes: 2 additions & 12 deletions source/corvusoft/restbed/request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,10 @@
//Project Includes
#include <corvusoft/restbed/byte.hpp>
#include <corvusoft/restbed/common.hpp>
#include <corvusoft/restbed/export.hpp>

//External Includes

//Windows DLL Exports
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(_WIN64)
#ifdef WIN_DLL_EXPORT
#define REQUEST_EXPORT __declspec(dllexport)
#else
#define REQUEST_EXPORT __declspec(dllimport)
#endif
#else
#define REQUEST_EXPORT __attribute__((visibility ("default")))
#endif

//System Namespaces

//Project Namespaces
Expand All @@ -54,7 +44,7 @@ namespace restbed
class WebSocketManagerImpl;
}

class REQUEST_EXPORT Request
class RESTBED_EXPORT Request
{
public:
//Friends
Expand Down
14 changes: 2 additions & 12 deletions source/corvusoft/restbed/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,10 @@
#include <functional>

//Project Includes
#include <corvusoft/restbed/export.hpp>

//External Includes

//Windows DLL Exports
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(_WIN64)
#ifdef WIN_DLL_EXPORT
#define RESOURCE_EXPORT __declspec(dllexport)
#else
#define RESOURCE_EXPORT __declspec(dllimport)
#endif
#else
#define RESOURCE_EXPORT __attribute__((visibility ("default")))
#endif

//System Namespaces

//Project Namespaces
Expand All @@ -45,7 +35,7 @@ namespace restbed
struct ResourceImpl;
}

class RESOURCE_EXPORT Resource
class RESTBED_EXPORT Resource
{
public:
//Friends
Expand Down
14 changes: 2 additions & 12 deletions source/corvusoft/restbed/response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,10 @@
//Project Includes
#include <corvusoft/restbed/byte.hpp>
#include <corvusoft/restbed/common.hpp>
#include <corvusoft/restbed/export.hpp>

//External Includes

//Windows DLL Exports
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(_WIN64)
#ifdef WIN_DLL_EXPORT
#define RESPONSE_EXPORT __declspec(dllexport)
#else
#define RESPONSE_EXPORT __declspec(dllimport)
#endif
#else
#define RESPONSE_EXPORT __attribute__((visibility ("default")))
#endif

//System Namespaces

//Project Namespaces
Expand All @@ -45,7 +35,7 @@ namespace restbed
struct ResponseImpl;
}

class RESPONSE_EXPORT Response
class RESTBED_EXPORT Response
{
public:
//Friends
Expand Down
14 changes: 2 additions & 12 deletions source/corvusoft/restbed/rule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@
#include <functional>

//Project Includes
#include <corvusoft/restbed/export.hpp>

//External Includes

//Windows DLL Exports
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(_WIN64)
#ifdef WIN_DLL_EXPORT
#define RULE_EXPORT __declspec(dllexport)
#else
#define RULE_EXPORT __declspec(dllimport)
#endif
#else
#define RULE_EXPORT __attribute__((visibility ("default")))
#endif

//System Namespaces

//Project Namespaces
Expand All @@ -39,7 +29,7 @@ namespace restbed
struct RuleImpl;
}

class RULE_EXPORT Rule
class RESTBED_EXPORT Rule
{
public:
//Friends
Expand Down
Loading