Skip to content

Commit 1921ddf

Browse files
authored
Merge pull request #375 from wolfv/allow_win32_shared
allow win32 to build shared lib
2 parents 5013bf7 + 1ddc67a commit 1921ddf

5 files changed

Lines changed: 33 additions & 6 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ ENDIF (NOT PKGCONFIG_INSTALL_DIR)
5858
SET (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
5959
INSTALL( FILES ${CMAKE_MODULE_PATH}/FindLibSolv.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/Modules )
6060

61+
# for shared libraries on windows (DLLs), we just export all symbols for now
62+
SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
63+
6164
INCLUDE (${CMAKE_SOURCE_DIR}/VERSION.cmake)
6265

6366
SET (have_system x)

src/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,15 @@ SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINK_FLAGS} -Wl,-
4848
ENDIF (HAVE_LINKER_VERSION_SCRIPT)
4949

5050
IF (DISABLE_SHARED)
51-
ADD_LIBRARY (libsolv STATIC ${libsolv_SRCS})
51+
ADD_LIBRARY (libsolv STATIC ${libsolv_SRCS})
52+
IF (WIN32)
53+
TARGET_COMPILE_DEFINITIONS(libsolv PUBLIC SOLV_STATIC_LIB)
54+
ENDIF (WIN32)
5255
ELSE (DISABLE_SHARED)
53-
ADD_LIBRARY (libsolv SHARED ${libsolv_SRCS})
56+
ADD_LIBRARY (libsolv SHARED ${libsolv_SRCS})
57+
IF (WIN32)
58+
TARGET_COMPILE_DEFINITIONS(libsolv PRIVATE SOLV_EXPORTS)
59+
ENDIF (WIN32)
5460
ENDIF (DISABLE_SHARED)
5561

5662
SET_TARGET_PROPERTIES(libsolv PROPERTIES OUTPUT_NAME "solv")

win32/config.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifdef _WIN32
2+
#ifdef SOLV_STATIC_LIB
3+
#define SOLV_API
4+
#else
5+
#ifdef SOLV_EXPORTS
6+
#define SOLV_API __declspec(dllexport)
7+
#else
8+
#define SOLV_API __declspec(dllimport)
9+
#endif
10+
#endif
11+
#else
12+
#define SOLV_API
13+
#endif

win32/getopt.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
#include <stdlib.h>
66
#include <stdio.h>
77

8-
char *optarg;
9-
int optind=1, opterr=1, optopt, __optpos, __optreset=0;
8+
#include "config.h"
9+
10+
SOLV_API char *optarg;
11+
SOLV_API int optind=1, opterr=1, optopt, __optpos, __optreset=0;
1012

1113
#define optpos __optpos
1214

win32/getopt.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
extern "C" {
66
#endif
77

8+
#include "config.h"
9+
810
int getopt(int, char * const [], const char *);
9-
extern char *optarg;
10-
extern int optind, opterr, optopt, optreset;
11+
12+
SOLV_API extern char *optarg;
13+
SOLV_API extern int optind, opterr, optopt, optreset;
1114

1215
struct option {
1316
const char *name;

0 commit comments

Comments
 (0)