Переглянути джерело

Separate C and CXX DLL import and export flags

Gregor Jasny 6 роки тому
батько
коміт
a47420151d
2 змінених файлів з 27 додано та 11 видалено
  1. 22 6
      include/CivetServer.h
  2. 5 5
      src/CMakeLists.txt

+ 22 - 6
include/CivetServer.h

@@ -14,13 +14,29 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
+#ifndef CIVETWEB_CXX_API
+#if defined(_WIN32)
+#if defined(CIVETWEB_CXX_DLL_EXPORTS)
+#define CIVETWEB_CXX_API __declspec(dllexport)
+#elif defined(CIVETWEB_CXX_DLL_IMPORTS)
+#define CIVETWEB_CXX_API __declspec(dllimport)
+#else
+#define CIVETWEB_CXX_API
+#endif
+#elif __GNUC__ >= 4
+#define CIVETWEB_CXX_API __attribute__((visibility("default")))
+#else
+#define CIVETWEB_CXX_API
+#endif
+#endif
+
 // forward declaration
 // forward declaration
 class CivetServer;
 class CivetServer;
 
 
 /**
 /**
  * Exception class for thrown exceptions within the CivetHandler object.
  * Exception class for thrown exceptions within the CivetHandler object.
  */
  */
-class CIVETWEB_API CivetException : public std::runtime_error
+class CIVETWEB_CXX_API CivetException : public std::runtime_error
 {
 {
   public:
   public:
 	CivetException(const std::string &msg) : std::runtime_error(msg)
 	CivetException(const std::string &msg) : std::runtime_error(msg)
@@ -32,7 +48,7 @@ class CIVETWEB_API CivetException : public std::runtime_error
  * Basic interface for a URI request handler.  Handlers implementations
  * Basic interface for a URI request handler.  Handlers implementations
  * must be reentrant.
  * must be reentrant.
  */
  */
-class CIVETWEB_API CivetHandler
+class CIVETWEB_CXX_API CivetHandler
 {
 {
   public:
   public:
 	/**
 	/**
@@ -110,7 +126,7 @@ class CIVETWEB_API CivetHandler
  * Basic interface for a URI authorization handler.  Handler implementations
  * Basic interface for a URI authorization handler.  Handler implementations
  * must be reentrant.
  * must be reentrant.
  */
  */
-class CIVETWEB_API CivetAuthHandler
+class CIVETWEB_CXX_API CivetAuthHandler
 {
 {
   public:
   public:
 	/**
 	/**
@@ -135,7 +151,7 @@ class CIVETWEB_API CivetAuthHandler
  * Basic interface for a websocket handler.  Handlers implementations
  * Basic interface for a websocket handler.  Handlers implementations
  * must be reentrant.
  * must be reentrant.
  */
  */
-class CIVETWEB_API CivetWebSocketHandler
+class CIVETWEB_CXX_API CivetWebSocketHandler
 {
 {
   public:
   public:
 	/**
 	/**
@@ -197,7 +213,7 @@ class CIVETWEB_API CivetWebSocketHandler
  *
  *
  * wrapper for mg_callbacks
  * wrapper for mg_callbacks
  */
  */
-struct CIVETWEB_API CivetCallbacks : public mg_callbacks {
+struct CIVETWEB_CXX_API CivetCallbacks : public mg_callbacks {
 	CivetCallbacks();
 	CivetCallbacks();
 };
 };
 
 
@@ -206,7 +222,7 @@ struct CIVETWEB_API CivetCallbacks : public mg_callbacks {
  *
  *
  * Basic class for embedded web server.  This has an URL mapping built-in.
  * Basic class for embedded web server.  This has an URL mapping built-in.
  */
  */
-class CIVETWEB_API CivetServer
+class CIVETWEB_CXX_API CivetServer
 {
 {
   public:
   public:
 	/**
 	/**

+ 5 - 5
src/CMakeLists.txt

@@ -10,7 +10,7 @@ set_target_properties(civetweb-c-library PROPERTIES
   SOVERSION ${CIVETWEB_VERSION}
   SOVERSION ${CIVETWEB_VERSION}
 )
 )
 if (BUILD_SHARED_LIBS)
 if (BUILD_SHARED_LIBS)
-  target_compile_definitions(civetweb-c-library PRIVATE CIVETWEB_DLL_EXPORTS)
+  target_compile_definitions(civetweb-c-library PRIVATE CIVETWEB_DLL_EXPORTS INTERFACE CIVETWEB_DLL_IMPORTS)
 endif()
 endif()
 target_include_directories(
 target_include_directories(
   civetweb-c-library PUBLIC
   civetweb-c-library PUBLIC
@@ -257,9 +257,6 @@ if (CIVETWEB_ENABLE_SERVER_EXECUTABLE)
             RUNTIME DESTINATION bin
             RUNTIME DESTINATION bin
             COMPONENT server)
             COMPONENT server)
     endif()
     endif()
-    if (BUILD_SHARED_LIBS)
-        target_compile_definitions(civetweb-c-executable PRIVATE CIVETWEB_DLL_IMPORTS)
-    endif()
     target_include_directories(
     target_include_directories(
         civetweb-c-executable PUBLIC
         civetweb-c-executable PUBLIC
         ${PROJECT_SOURCE_DIR}/include)
         ${PROJECT_SOURCE_DIR}/include)
@@ -296,8 +293,11 @@ if (CIVETWEB_ENABLE_CXX)
     SOVERSION ${CIVETWEB_VERSION}
     SOVERSION ${CIVETWEB_VERSION}
   )
   )
   if (BUILD_SHARED_LIBS)
   if (BUILD_SHARED_LIBS)
-    target_compile_definitions(civetweb-cpp PRIVATE CIVETWEB_DLL_EXPORTS)
+    target_compile_definitions(civetweb-cpp PRIVATE CIVETWEB_CXX_DLL_EXPORTS INTERFACE CIVETWEB_CXX_DLL_IMPORTS)
   endif()
   endif()
+  target_link_libraries(
+    civetweb-cpp PUBLIC
+	civetweb-c-library)
   target_include_directories(
   target_include_directories(
     civetweb-cpp PUBLIC
     civetweb-cpp PUBLIC
     ${PROJECT_SOURCE_DIR}/include)
     ${PROJECT_SOURCE_DIR}/include)